2496
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
2541
|
6 #include "Engine/Engine.h"
|
2496
|
7 #include "LightmapBuilder.h"
|
2541
|
8 #include "Engine/stru314.h"
|
2496
|
9 #include "Outdoor.h"
|
|
10
|
|
11 #include "Lights.h"
|
2541
|
12 #include "Engine/MMT.h"
|
2496
|
13 #include "stru9.h"
|
|
14
|
|
15 LightsStack_StationaryLight_ *pStationaryLightsStack = new LightsStack_StationaryLight_;
|
|
16 //StationaryLight pStationaryLights[400];
|
|
17 //int uNumStationaryLightsApplied; // weak
|
|
18 LightsStack_MobileLight_ *pMobileLightsStack = new LightsStack_MobileLight_;
|
|
19 //MobileLight pMobileLights[400];
|
|
20 //int uNumMobileLightsApplied;
|
|
21
|
|
22
|
|
23 //----- (0045DF13) --------------------------------------------------------
|
|
24 Lightmap::Lightmap()
|
|
25 {
|
2532
|
26 // For initialization step(I)
|
|
27
|
|
28 NumVertices = -1;
|
2508
|
29 for (uint i = 0; i < 64; ++i)
|
|
30 pVertices[i].flt_2C = 0.0f;
|
|
31 this->field_C18 = 0;
|
|
32 //this->vdestructor_ptr = &Lightmap_pvdtor;
|
2496
|
33 }
|
|
34
|
|
35 //----- (0045BB06) --------------------------------------------------------
|
|
36 LightmapBuilder::LightmapBuilder()
|
|
37 {
|
2532
|
38 // For initialization step(II)
|
2508
|
39
|
2532
|
40 for ( int i = 0; i < 512; ++i )//for light type 1
|
2508
|
41 this->std__vector_000004[i] = Lightmap();
|
|
42 this->std__vector_000004_size = 0;
|
|
43
|
2532
|
44 for ( int i = 0; i < 768; ++i )//for light type 2
|
2508
|
45 this->std__vector_183808[i] = Lightmap();
|
|
46 this->std__vector_183808_size = 0;
|
|
47
|
|
48 for ( int i = 0; i < 256; i++ )
|
|
49 this->field_3C8C34[i].flt_2C = 0.0f;
|
2496
|
50 }
|
|
51
|
2532
|
52 //////////////////////////OUTDOOR LIGHT////////////////////////////////////////////
|
2496
|
53 //----- (0045CDB7) --------------------------------------------------------
|
|
54 bool LightmapBuilder::ApplyLights_OutdoorFace(ODMFace *pFace)
|
|
55 {
|
2532
|
56 //For outdoor light (I)
|
2496
|
57 int v3; // eax@1
|
|
58 bool result; // eax@9
|
|
59 int pSlot; // [sp+10h] [bp-4h]@1
|
|
60
|
|
61 v3 = stru_F8AD28.uDefaultAmbientLightLevel + pFace->uShadeType;
|
|
62 pSlot = 0;
|
|
63 stru_F8AD28.uCurrentAmbientLightLevel = v3 << 16;
|
|
64 for ( uint i = 0; i < pMobileLightsStack->uNumLightsActive; ++i )
|
|
65 {
|
|
66 if ( pSlot >= 20 )
|
|
67 break;
|
|
68 ApplyLight_ODM((StationaryLight *)pMobileLightsStack[i].pLights, pFace, (unsigned int *)&pSlot, 1);
|
|
69 }
|
|
70 for ( uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i )
|
|
71 {
|
|
72 if ( pSlot >= 20 )
|
|
73 break;
|
|
74 ApplyLight_ODM(&pStationaryLightsStack->pLights[i], pFace, (unsigned int *)&pSlot, 0);
|
|
75 }
|
|
76 result = pSlot;
|
|
77 stru_F8AD28.uNumLightsApplied = pSlot;
|
|
78 return true;
|
|
79 }
|
|
80
|
|
81 //----- (0045D0D5) --------------------------------------------------------
|
2559
|
82 bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *TerrainVertices, unsigned int uStripType, int X, unsigned int *pSlot)
|
2496
|
83 {
|
2532
|
84 //For outdoor terrain light (II)
|
2496
|
85 bool result; // eax@1
|
|
86 double maxz; // st7@11
|
|
87 char v20; // c2@11
|
|
88 signed int v52; // ecx@17
|
|
89 char v57; // dl@18
|
|
90 std::string v58; // [sp-18h] [bp-38h]@10
|
|
91 double v61; // [sp+Ch] [bp-14h]@11
|
|
92 float minz; // [sp+14h] [bp-Ch]@11
|
2531
|
93 float tX_0;
|
|
94 float tX_1;
|
|
95 float tY_0;
|
|
96 float tY_1; // [sp+1Ch] [bp-4h]@5
|
2496
|
97
|
2559
|
98 // x0,y0 x1,y1
|
|
99 // .____________.
|
|
100 // | |
|
|
101 // | |
|
|
102 // | |
|
|
103 // .____________.
|
|
104 // x3,y3 x2,y2
|
|
105
|
|
106
|
2531
|
107 if ( pLight->uRadius <= 0 )
|
2559
|
108 return false;
|
2496
|
109 if ( uStripType == 4 )
|
|
110 {
|
2559
|
111 tX_0 = TerrainVertices[0].vWorldPosition.x;
|
|
112 tX_1 = TerrainVertices[3].vWorldPosition.x;
|
|
113
|
|
114 tY_0 = TerrainVertices[1].vWorldPosition.y;
|
|
115 tY_1 = TerrainVertices[0].vWorldPosition.y;
|
2496
|
116 }
|
2559
|
117 else if(uStripType == 3)
|
2496
|
118 {
|
2559
|
119 if ((unsigned char)X)
|
2496
|
120 {
|
2559
|
121 tX_0 = TerrainVertices[0].vWorldPosition.x;
|
|
122 tX_1 = TerrainVertices[2].vWorldPosition.x;
|
|
123
|
|
124 tY_0 = TerrainVertices[1].vWorldPosition.y;
|
|
125 tY_1 = TerrainVertices[2].vWorldPosition.y;
|
2496
|
126 }
|
2531
|
127 else
|
|
128 {
|
2559
|
129 tX_0 = TerrainVertices[1].vWorldPosition.x;
|
|
130 tX_1 = TerrainVertices[2].vWorldPosition.x;
|
|
131
|
|
132 tY_0 = TerrainVertices[1].vWorldPosition.y;
|
|
133 tY_1 = TerrainVertices[0].vWorldPosition.y;
|
2531
|
134 }
|
2496
|
135 }
|
2559
|
136 else
|
|
137 MessageBoxW(nullptr, L"Uknown strip type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:981", 0);
|
2496
|
138
|
2559
|
139 minz = pIndoorCameraD3D->GetPolygonMinZ(TerrainVertices, uStripType);
|
|
140 maxz = pIndoorCameraD3D->GetPolygonMaxZ(TerrainVertices, uStripType);
|
2531
|
141
|
|
142 float bounding_x1 = tX_0 - (float)pLight->uRadius; //13 976 - 128 = 13848.0
|
|
143 float bounding_y1 = tY_0 - (float)pLight->uRadius; // 3 800 - 128 = 3672.0
|
|
144 float bounding_z1 = minz - (float)pLight->uRadius; // -26.0
|
|
145
|
|
146 float bounding_x2 = (float)pLight->uRadius + tX_1; //13 877 + 128 = 14005.0
|
|
147 float bounding_y2 = (float)pLight->uRadius + tY_1; //3 792 + 128 = 3920.0
|
|
148 float bounding_z2 = (float)pLight->uRadius + maxz;// 260.0
|
|
149
|
2559
|
150 //ïðîâåðÿåì âåðøèíû
|
2531
|
151 if ( (float)pLight->vPosition.x <= bounding_x1 || (float)pLight->vPosition.x >= bounding_x2
|
|
152 || (float)pLight->vPosition.y <= bounding_y1 || (float)pLight->vPosition.y >= bounding_y2
|
|
153 || (float)pLight->vPosition.z <= bounding_z1 || (float)pLight->vPosition.z >= bounding_z2 )
|
2559
|
154 return false;
|
2531
|
155
|
2559
|
156 Vec3_float_::NegDot(&TerrainVertices->vWorldPosition, pNormal, a3);
|
|
157 float p_dot = (float)pLight->vPosition.x * pNormal->x
|
|
158 + (float)pLight->vPosition.y * pNormal->y
|
|
159 + (float)pLight->vPosition.z * pNormal->z + *a3;
|
|
160 p_dot = p_dot + 0.5f;
|
2531
|
161 if ( (//v49 = pNormal,
|
|
162 //Vec3_float_::NegDot(&a1->vWorldPosition, pNormal, a3),
|
|
163 //X = v8->vPosition.y,
|
|
164 //v50 = (double)v8->vPosition.y * v49->y,
|
|
165 //X = v8->vPosition.z,
|
|
166 //v51 = (double)v8->vPosition.z * v49->z,
|
|
167 //X = v8->vPosition.x,
|
|
168 //*(float *)&a3 = (double)pLight->vPosition.y * pNormal->y
|
|
169 //+ (double)pLight->vPosition.z * pNormal->z
|
|
170 //+ (double)pLight->vPosition.x * pNormal->x + *a3,
|
|
171 //v61 = *(float *)&a3 + 0.5f,
|
|
172 //result = LODWORD(v61),
|
|
173 //X = LODWORD(v61),
|
|
174 //v52 = v63,
|
|
175 p_dot > pLight->uRadius) )
|
2559
|
176 return false;
|
2531
|
177 /*
|
2496
|
178 v49 = pNormal;
|
|
179 Vec3_float_::NegDot(&v11->vWorldPosition, pNormal, a3);
|
|
180 *(float *)a3 = (double)v8->vPosition.x * v49->x
|
|
181 + (double)v8->vPosition.y * v49->y
|
|
182 + (double)v8->vPosition.z * v49->z + *a3;
|
|
183 v61 = *(float *)a3 + 6.7553994e15;
|
|
184 result = LODWORD(v61);
|
|
185 X = LODWORD(v61);
|
2531
|
186 v52 = radius_1;
|
|
187 if ( SLODWORD(v61) > radius_1)*/
|
|
188 //v53 = pSlot;
|
|
189 //v60 = X;
|
|
190 stru_F8AD28._blv_lights_radii[*pSlot] = pLight->uRadius;
|
|
191 stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / pLight->uRadius;
|
|
192 stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x;
|
|
193 stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y;
|
|
194 stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z;
|
|
195
|
|
196 stru_F8AD28._blv_lights_rs[*pSlot] = pLight->uLightColorR / 255.0f;
|
|
197 stru_F8AD28._blv_lights_gs[*pSlot] = pLight->uLightColorG / 255.0f;
|
|
198 stru_F8AD28._blv_lights_bs[*pSlot] = pLight->uLightColorB / 255.0f;
|
|
199
|
|
200 stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = abs(p_dot);
|
|
201 stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType;
|
|
202
|
|
203 v57 = stru_F8AD28._blv_lights_types[*pSlot];
|
|
204 if ( /*pRenderer->pRenderD3D &&*/ pRenderer->bUsingSpecular && stru_F8AD28._blv_lights_types[*pSlot] & 4 )
|
2496
|
205 v57 = _4E94D2_light_type;
|
2531
|
206 stru_F8AD28._blv_lights_types[*pSlot] = v57;
|
|
207
|
2559
|
208 int id = 4 * *pSlot;
|
2531
|
209 if ( /*pRenderer->pRenderD3D &&*/ pRenderer->bUsingSpecular )
|
2496
|
210 {
|
2531
|
211 if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 )
|
2496
|
212 {
|
2559
|
213 stru_F8AD28._blv_lights_rs[id] = stru_F8AD28._blv_lights_rs[id] * 0.3300000131130219;
|
|
214 stru_F8AD28._blv_lights_gs[id] = stru_F8AD28._blv_lights_gs[id] * 0.3300000131130219;
|
|
215 stru_F8AD28._blv_lights_bs[id] = stru_F8AD28._blv_lights_bs[id] * 0.3300000131130219;
|
2496
|
216 }
|
|
217 }
|
2531
|
218 ++*pSlot;
|
2559
|
219 return true;
|
2496
|
220 }
|
|
221
|
2532
|
222 //----- (0045CE50) --------------------------------------------------------
|
|
223 bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4)
|
|
224 {
|
|
225 //For outdoor light (IV)
|
|
226 int result; // eax@0
|
|
227 int v10; // ecx@8
|
|
228 char v14; // dl@11
|
|
229
|
|
230 v10 = (pFace->pFacePlane.dist
|
|
231 + pLight->vPosition.x * pFace->pFacePlane.vNormal.x
|
|
232 + pLight->vPosition.y * pFace->pFacePlane.vNormal.y
|
|
233 + pLight->vPosition.z * pFace->pFacePlane.vNormal.z) >> 16;
|
|
234 if ( pLight->uRadius > 0
|
|
235 && (pLight->vPosition.x > pFace->pBoundingBox.x1 - pLight->uRadius) && pLight->vPosition.x < pLight->uRadius + pFace->pBoundingBox.x2
|
|
236 && (pLight->vPosition.y > pFace->pBoundingBox.y1 - pLight->uRadius) && pLight->vPosition.y < pLight->uRadius + pFace->pBoundingBox.y2
|
|
237 && (pLight->vPosition.z > pFace->pBoundingBox.z1 - pLight->uRadius) && pLight->vPosition.z < pLight->uRadius + pFace->pBoundingBox.z2
|
|
238 && ((a4) || v10 >= 0) && v10 <= pLight->uRadius )
|
|
239 {
|
|
240 stru_F8AD28._blv_lights_radii[*pSlot] = pLight->uRadius;
|
|
241 stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / pLight->uRadius;
|
|
242 stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x;
|
|
243 stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y;
|
|
244 stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z;
|
|
245 stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689;
|
|
246 stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689;
|
|
247 stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689;
|
|
248 //v11 = abs(v10);
|
|
249 //v12 = pRenderer->bUsingSpecular;
|
|
250 stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = abs(v10);
|
|
251 stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType;
|
|
252 //v13 = pRenderer->pRenderD3D;
|
|
253 v14 = stru_F8AD28._blv_lights_types[*pSlot];
|
|
254 if ( /*pRenderer->pRenderD3D &&*/ pRenderer->bUsingSpecular && v14 & 4 )
|
|
255 v14 = _4E94D2_light_type;
|
|
256 stru_F8AD28._blv_lights_types[*pSlot] = v14;
|
|
257 result = 4 * *pSlot;
|
|
258 if ( /*v13*/true && pRenderer->bUsingSpecular )
|
|
259 {
|
|
260 if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 )
|
|
261 {
|
|
262 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result)
|
|
263 * 0.33000001;
|
|
264 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result)
|
|
265 * 0.33000001;
|
|
266 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result)
|
|
267 * 0.33000001;
|
|
268 }
|
|
269 }
|
|
270 ++*pSlot;
|
|
271 return true;
|
|
272 }
|
|
273 else
|
|
274 return false;
|
|
275 }
|
|
276
|
|
277
|
|
278 //////////////////////////INDOOR LIGHT////////////////////////////////////////////
|
|
279 //----- (0045C7F6) --------------------------------------------------------
|
|
280 bool LightmapBuilder::ApplyLights_IndoorFace(unsigned int uFaceID)
|
|
281 {
|
|
282 //For Indoor light (I)
|
|
283 BLVFace* pFace = &pIndoor->pFaces[uFaceID];
|
|
284 BLVSector* pSector = &pIndoor->pSectors[pFace->uSectorID];
|
|
285
|
|
286 stru_F8AD28.uCurrentAmbientLightLevel = (stru_F8AD28.uDefaultAmbientLightLevel + pSector->uMinAmbientLightLevel) << 16;//0x00180000
|
|
287
|
|
288 uint uNumLightsApplied = 0;
|
|
289 for (uint i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
|
|
290 {
|
|
291 if (uNumLightsApplied >= 20)
|
|
292 break;
|
|
293
|
|
294 ApplyLight_BLV((StationaryLight *)(pMobileLightsStack->pLights + i), pFace, &uNumLightsApplied, true, 0);
|
|
295 }
|
|
296
|
|
297 for (uint i = 0; i < pSector->uNumLights; ++i)
|
|
298 {
|
|
299 if (uNumLightsApplied >= 20 )
|
|
300 break;
|
|
301
|
|
302 BLVLightMM7* pLight = &pIndoor->pLights[pSector->pLights[i]];
|
|
303 if (~pLight->uAtributes & 0x08)
|
|
304 ApplyLight_BLV((StationaryLight *)pLight, pFace, &uFaceID, false, &_4E94D0_light_type);
|
|
305 }
|
|
306
|
|
307 for (uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
|
|
308 {
|
|
309 if (uNumLightsApplied >= 20)
|
|
310 break;
|
|
311
|
|
312 ApplyLight_BLV(pStationaryLightsStack->pLights + i, pFace, &uNumLightsApplied, false, &_4E94D0_light_type);
|
|
313 }
|
|
314
|
|
315 stru_F8AD28.uNumLightsApplied = uNumLightsApplied;
|
|
316 return true;
|
|
317 }
|
|
318
|
|
319 //----- (0045C911) --------------------------------------------------------
|
|
320 bool LightmapBuilder::ApplyLight_BLV(StationaryLight *pLight, BLVFace *a2, unsigned int *pSlot, bool bLightBackfaces, char *a5)
|
|
321 {
|
|
322 //For indoor light (II)
|
|
323 double v13; // st7@8
|
|
324
|
|
325 if (!pLight->uRadius)//800
|
|
326 return false;
|
|
327
|
|
328 if (pLight->vPosition.x > a2->pBounding.x1 - pLight->uRadius && pLight->vPosition.x < a2->pBounding.x2 + pLight->uRadius &&
|
|
329 pLight->vPosition.y > a2->pBounding.y1 - pLight->uRadius && pLight->vPosition.y < a2->pBounding.y2 + pLight->uRadius &&
|
|
330 pLight->vPosition.z > a2->pBounding.z1 - pLight->uRadius && pLight->vPosition.z < a2->pBounding.z2 + pLight->uRadius)
|
|
331 {
|
|
332 v13 = (double)pLight->vPosition.z * a2->pFacePlane.vNormal.z +
|
|
333 (double)pLight->vPosition.y * a2->pFacePlane.vNormal.y +
|
|
334 (double)pLight->vPosition.x * a2->pFacePlane.vNormal.x +
|
|
335 a2->pFacePlane.dist;
|
|
336 if ((bLightBackfaces || v13 >= 0.0f) && fabsf(v13) <= pLight->uRadius)
|
|
337 {
|
|
338 unsigned int slot = *pSlot;
|
|
339
|
|
340 stru_F8AD28._blv_lights_radii[slot] = pLight->uRadius;
|
|
341 stru_F8AD28._blv_lights_inv_radii[slot] = 65536 / pLight->uRadius;
|
|
342 stru_F8AD28._blv_lights_xs[slot] = pLight->vPosition.x;
|
|
343 stru_F8AD28._blv_lights_ys[slot] = pLight->vPosition.y;
|
|
344 stru_F8AD28._blv_lights_zs[slot] = pLight->vPosition.z;
|
|
345 stru_F8AD28._blv_lights_rs[slot] = (double)pLight->uLightColorR / 255.0f;
|
|
346 stru_F8AD28._blv_lights_gs[slot] = (double)pLight->uLightColorG / 255.0f;
|
|
347 stru_F8AD28._blv_lights_bs[slot] = (double)pLight->uLightColorB / 255.0f;
|
|
348 stru_F8AD28._blv_lights_light_dot_faces[slot] = abs((int)floorf(v13 + 0.5f));
|
|
349 stru_F8AD28._blv_lights_types[slot] = pLight->uLightType;
|
|
350
|
|
351 *pSlot += 1;
|
|
352 return true;
|
|
353 }
|
|
354 }
|
|
355
|
|
356 return false;
|
|
357 }
|
|
358
|
|
359 //----- (0045DA56) --------------------------------------------------------
|
|
360 bool LightmapBuilder::DoDraw_183808_Lightmaps(float z_bias)
|
|
361 {
|
|
362 //For indoor light (X)
|
|
363 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2
|
|
364 v.z = 1.0;
|
|
365 v.y = 1.0;
|
|
366 v.x = 1.0;
|
|
367
|
|
368 for (uint i = 0; i < std__vector_183808_size; ++i)
|
|
369 if (!pRenderer->DrawLightmap(std__vector_183808 + i, &v, z_bias))
|
|
370 Error("Invalid lightmap detected! (%u)", i);
|
|
371
|
|
372 return true;
|
|
373 }
|
|
374
|
|
375 //----- (0045C4B9) --------------------------------------------------------
|
|
376 int LightmapBuilder::_45C4B9(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
|
|
377 {
|
|
378 //For indoor light (?)
|
|
379 RenderVertexSoft *v9; // esi@3
|
|
380 RenderVertexSoft *v12; // ecx@8
|
|
381 char v13; // bl@17
|
|
382 signed int v14; // edx@17
|
|
383 double v15; // st6@18
|
|
384 double v16; // st6@21
|
|
385 double v17; // st6@24
|
|
386 signed int v18; // edx@33
|
|
387 float v22; // [sp+Ch] [bp-14h]@23
|
|
388 float v23; // [sp+10h] [bp-10h]@20
|
|
389 int v24; // [sp+14h] [bp-Ch]@1
|
|
390 char v26; // [sp+1Eh] [bp-2h]@17
|
|
391 char v27; // [sp+1Fh] [bp-1h]@17
|
|
392
|
|
393 v24 = 0;
|
|
394 for ( uint i = 0; i < pLightmap->NumVertices; i++)
|
|
395 {
|
|
396 v9 = &pLightmap->pVertices[(i + 1) % pLightmap->NumVertices];
|
|
397 if ( pLightmap->pVertices[i].vWorldPosition.x != v9->vWorldPosition.x
|
|
398 || pLightmap->pVertices[i].vWorldPosition.y != v9->vWorldPosition.y
|
|
399 || pLightmap->pVertices[i].vWorldPosition.z != v9->vWorldPosition.z )
|
|
400 {
|
|
401 for ( uint j = 0; j < a2; ++j )
|
|
402 {
|
|
403 v12 = &a3[(j + 1) % a2];
|
|
404 if ((a3[j].vWorldPosition.x != v12->vWorldPosition.x
|
|
405 || a3[j].vWorldPosition.y != v12->vWorldPosition.y
|
|
406 || a3[j].vWorldPosition.z != v12->vWorldPosition.z)
|
|
407 && pLightmap->pVertices[i].vWorldPosition.x == a3[j].vWorldPosition.x
|
|
408 && pLightmap->pVertices[i].vWorldPosition.y == a3[j].vWorldPosition.y
|
|
409 && pLightmap->pVertices[i].vWorldPosition.z == a3[j].vWorldPosition.z
|
|
410 && (v9->vWorldPosition.x != v12->vWorldPosition.x
|
|
411 || v9->vWorldPosition.y != v12->vWorldPosition.y
|
|
412 || v9->vWorldPosition.z != v12->vWorldPosition.z) )
|
|
413 {
|
|
414 v13 = 0;
|
|
415 v14 = 0;
|
|
416 v27 = 0;
|
|
417 v26 = 0;
|
|
418
|
|
419 if ( v9->vWorldPosition.x <= (double)v12->vWorldPosition.x )
|
|
420 v15 = v12->vWorldPosition.x - v9->vWorldPosition.x;
|
|
421 else
|
|
422 v15 = v9->vWorldPosition.x - v12->vWorldPosition.x;
|
|
423 v23 = v15;
|
|
424
|
|
425 if ( v9->vWorldPosition.y <= (double)v12->vWorldPosition.y )
|
|
426 v16 = v12->vWorldPosition.y - v9->vWorldPosition.y;
|
|
427 else
|
|
428 v16 = v9->vWorldPosition.y - v12->vWorldPosition.y;
|
|
429 v22 = v16;
|
|
430
|
|
431 if ( v9->vWorldPosition.z <= (double)v12->vWorldPosition.z )
|
|
432 v17 = v12->vWorldPosition.z - v9->vWorldPosition.z;
|
|
433 else
|
|
434 v17 = v9->vWorldPosition.z - v12->vWorldPosition.z;
|
|
435
|
|
436 if ( v23 < 1.0 )
|
|
437 {
|
|
438 v13 = 1;
|
|
439 v14 = 1;
|
|
440 }
|
|
441
|
|
442 if ( v22 < 1.0 )
|
|
443 {
|
|
444 v27 = 1;
|
|
445 ++v14;
|
|
446 }
|
|
447
|
|
448 if ( v17 < 1.0 )
|
|
449 {
|
|
450 v26 = 1;
|
|
451 ++v14;
|
|
452 }
|
|
453
|
|
454 if ( v14 > 1 )
|
|
455 {
|
|
456 v18 = 0;
|
|
457 if ( v13 && v9->vWorldPosition.x != v12->vWorldPosition.x )
|
|
458 {
|
|
459 v18 = 1;
|
|
460 v9->vWorldPosition.x = v12->vWorldPosition.x;
|
|
461 }
|
|
462
|
|
463 if ( v27 && v9->vWorldPosition.y != v12->vWorldPosition.y )
|
|
464 {
|
|
465 ++v18;
|
|
466 v9->vWorldPosition.y = v12->vWorldPosition.y;
|
|
467 }
|
|
468
|
|
469 if ( v26 && v9->vWorldPosition.z != v12->vWorldPosition.z )
|
|
470 {
|
|
471 ++v18;
|
|
472 v9->vWorldPosition.z = v12->vWorldPosition.z;
|
|
473 }
|
|
474
|
|
475 if ( v18 > 0 )
|
|
476 ++v24;
|
|
477 }
|
|
478 }
|
|
479 }
|
|
480 }
|
|
481 }
|
|
482 return v24;
|
|
483 }
|
|
484
|
|
485 ////////////////////////FOR OUTDOOR TERRAIN//////////////////////////////////////////
|
|
486 //----- (0045D036) --------------------------------------------------------
|
|
487 bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *Light_tile_dist, RenderVertexSoft *a3, unsigned int uStripType, bool bLightBackfaces)
|
|
488 {
|
|
489 /*int v6; // esi@1
|
|
490 //LightmapBuilder *v7; // edi@1
|
|
491 MobileLight *v8; // ebx@2
|
|
492 int v9; // esi@5
|
|
493 StationaryLight *v10; // ebx@6
|
|
494 //bool result; // eax@9
|
|
495 unsigned int a7; // [sp+Ch] [bp-4h]@1
|
|
496
|
|
497 v6 = 0;
|
|
498 //v7 = this;
|
|
499 a7 = 0;
|
|
500 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type;
|
|
501 if ( pMobileLightsStack->uNumLightsActive > 0 )
|
|
502 {
|
|
503 v8 = pMobileLightsStack->pLights;
|
|
504 do
|
|
505 {
|
|
506 if ( (signed int)a7 >= 20 )
|
|
507 break;
|
|
508 StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
|
|
509 ++v6;
|
|
510 ++v8;
|
|
511 }
|
|
512 while ( v6 < pMobileLightsStack->uNumLightsActive );
|
|
513 }
|
|
514 v9 = 0;
|
|
515 if ( pStationaryLightsStack->uNumLightsActive > 0 )
|
|
516 {
|
|
517 v10 = pStationaryLightsStack->pLights;
|
|
518 do
|
|
519 {
|
|
520 if ( (signed int)a7 >= 20 )
|
|
521 break;
|
|
522 StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
|
|
523 ++v9;
|
|
524 ++v10;
|
|
525 }
|
|
526 while ( v9 < pStationaryLightsStack->uNumLightsActive );
|
|
527 }
|
|
528
|
|
529 stru_F8AD28.uNumLightsApplied = a7;
|
|
530 return true;*/
|
|
531 // bool __stdcall sub_45D036(struct Vec3<float> *pNormal, int a2, struct RenderVertex *a3, int a4, signed int X)
|
|
532 //{
|
|
533 // float v6; // ebx@2
|
|
534
|
|
535 //For outdoor terrain light(I)
|
|
536 unsigned int num_lights; // [sp+Ch] [bp-4h]@1
|
|
537 int i;
|
|
538
|
|
539 num_lights = 0;
|
|
540 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->max_terrain_dimming_level;
|
|
541 for (i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
|
|
542 {
|
|
543 if ( num_lights >= 20 )
|
|
544 break;
|
|
545 StackLight_TerrainFace((StationaryLight *)&pMobileLightsStack->pLights[i], pNormal, Light_tile_dist, a3, uStripType, bLightBackfaces, &num_lights);
|
|
546 }
|
|
547
|
|
548 for (i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
|
|
549 {
|
|
550 if ( num_lights >= 20 )
|
|
551 break;
|
|
552 StackLight_TerrainFace(&pStationaryLightsStack->pLights[i], pNormal, Light_tile_dist, a3, uStripType, bLightBackfaces, &num_lights);
|
|
553 }
|
|
554
|
|
555 stru_F8AD28.uNumLightsApplied = num_lights;
|
|
556 return true;
|
|
557
|
|
558 }
|
|
559
|
|
560
|
|
561 /////////////////////////TOGETHER///////////////////////////////////////////////////////
|
|
562 //----- (0045BC07) --------------------------------------------------------
|
|
563 bool LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, IndoorCameraD3D_Vec4 *a6, char uClipFlag)
|
|
564 {
|
|
565 //For outdoor terrain and indoor light (III)(III)
|
|
566 Vec3_int_ pos; // [sp+2Ch] [bp-40h]@21
|
|
567 RenderVertexSoft *a9; // [sp+68h] [bp-4h]@8
|
|
568
|
|
569 if (!uNumVertices)
|
|
570 return false;
|
|
571
|
|
572 static RenderVertexSoft static_69B140[64];
|
|
573
|
|
574 a9 = a5;
|
|
575 if (a6)
|
|
576 {
|
|
577 for (uint i = 0; i < uNumVertices; ++i)
|
|
578 memcpy(&static_69B140[i], a5 + i, sizeof(RenderVertexSoft));
|
|
579
|
2543
|
580 if (pIndoorCameraD3D->_437376(a3, static_69B140, &uNumVertices) == 1)
|
2532
|
581 {
|
|
582 if ( !uNumVertices )
|
|
583 return false;
|
|
584 a9 = static_69B140;
|
|
585 }
|
|
586 }
|
|
587
|
|
588 static stru314 static_69B110;
|
|
589 static_69B110.field_4.x = a3->face_plane.vNormal.x;
|
|
590 static_69B110.field_4.y = a3->face_plane.vNormal.y;
|
|
591 static_69B110.field_4.z = a3->face_plane.vNormal.z;
|
|
592 static_69B110.dist = a3->face_plane.dist;
|
2543
|
593 if (!pIndoorCameraD3D->GetFacetOrientation(a3->polygonType, &static_69B110.field_4,
|
2532
|
594 &static_69B110.field_10, &static_69B110.field_1C))
|
|
595 {
|
|
596 MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0);
|
|
597 ExitProcess(0);
|
|
598 }
|
|
599
|
|
600 for (uint i = 0; i < a2->uNumLightsApplied; ++i)
|
|
601 {
|
|
602 pos.x = a2->_blv_lights_xs[i];
|
|
603 pos.y = a2->_blv_lights_ys[i];
|
|
604 pos.z = a2->_blv_lights_zs[i];
|
|
605
|
|
606 uint uColorR = (uint)floorf(a2->_blv_lights_rs[i] * 255.0 + 0.5f) & 0xFF,
|
|
607 uColorG = (uint)floorf(a2->_blv_lights_gs[i] * 255.0 + 0.5f) & 0xFF,
|
|
608 uColorB = (uint)floorf(a2->_blv_lights_bs[i] * 255.0 + 0.5f) & 0xFF;
|
|
609 uint uColor = (uColorR << 16) | (uColorG << 8) | uColorB;
|
|
610 if (!uColor)
|
|
611 uColor = 0x0FFFFF;//0x00FFFFF;
|
|
612
|
|
613 if (!_45BE86_build_light_polygon(&pos, a2->_blv_lights_radii[i], uColor, a2->_blv_lights_light_dot_faces[i],
|
|
614 a2->_blv_lights_types[i], &static_69B110, uNumVertices, a9, uClipFlag) )
|
|
615 {
|
|
616 MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0);
|
|
617 }
|
|
618 }
|
|
619 return true;
|
|
620 }
|
|
621
|
|
622 //----- (0045BE86) --------------------------------------------------------
|
|
623 bool LightmapBuilder::_45BE86_build_light_polygon(Vec3_int_ *pos, float radius, unsigned int uColorMask, float dot_dist, int uLightType, stru314 *a7, unsigned int uNumVertices, RenderVertexSoft *a9, char uClipFlag)
|
|
624 {
|
|
625 //For outdoor terrain and indoor light (IV)(IV)
|
|
626 Lightmap *lightmap; // edi@3
|
|
627 double v17; // st7@5
|
|
628 double v24; // st7@6
|
|
629 double v38; // st7@14
|
|
630 double v39; // st7@16
|
|
631 double v40; // st7@16
|
|
632 int v45; // eax@24
|
|
633
|
|
634 if (radius < 0.0f)
|
|
635 return true;
|
|
636
|
|
637 lightmap = uLightType & 1 ? &std__vector_000004[std__vector_000004_size] ://stationary
|
|
638 &std__vector_183808[std__vector_183808_size];//mobile
|
|
639 tex_light_radius = radius - dot_dist;
|
|
640 flt_3C8C28 = sqrt((radius + radius - tex_light_radius) * tex_light_radius);
|
|
641 //flt_3C8C28 = sqrt(tex_light_radius * tex_light_radius);
|
|
642 flt_3C8C2C_lightmaps_brightness = 1.0 - (radius - flt_3C8C28) / radius;
|
|
643 lightmap->position_x = (double)pos->x - dot_dist * a7->field_4.x;
|
|
644 lightmap->position_y = (double)pos->y - dot_dist * a7->field_4.y;
|
|
645 lightmap->position_z = (double)pos->z - dot_dist * a7->field_4.z;
|
|
646
|
|
647 flt_3C8C30 = radius * flt_3C8C2C_lightmaps_brightness;
|
|
648 flt_3C8C0C = flt_3C8C30 * a7->field_10.x;
|
|
649 flt_3C8C10 = flt_3C8C30 * a7->field_10.y;
|
|
650 flt_3C8C14 = flt_3C8C30 * a7->field_10.z;
|
|
651
|
|
652 flt_3C8C18 = flt_3C8C30 * a7->field_1C.x;
|
|
653 flt_3C8C1C = flt_3C8C30 * a7->field_1C.y;
|
|
654 flt_3C8C20 = flt_3C8C30 * a7->field_1C.z;
|
|
655
|
|
656 lightmap->pVertices[0].vWorldPosition.x = lightmap->position_x - flt_3C8C18 + flt_3C8C0C;
|
|
657 lightmap->pVertices[0].vWorldPosition.y = lightmap->position_y - flt_3C8C1C + flt_3C8C10;
|
|
658 lightmap->pVertices[0].vWorldPosition.z = lightmap->position_z - flt_3C8C20 + flt_3C8C14;
|
|
659 lightmap->pVertices[0].u = 0.0;
|
|
660 lightmap->pVertices[0].v = 0.0;
|
|
661
|
|
662 lightmap->pVertices[1].vWorldPosition.x = lightmap->position_x - flt_3C8C18 - flt_3C8C0C;
|
|
663 lightmap->pVertices[1].vWorldPosition.y = lightmap->position_y - flt_3C8C1C - flt_3C8C10;
|
|
664 lightmap->pVertices[1].vWorldPosition.z = lightmap->position_z - flt_3C8C20 - flt_3C8C14;
|
|
665 lightmap->pVertices[1].u = 0.0;
|
|
666 lightmap->pVertices[1].v = 1.0;
|
|
667
|
|
668 lightmap->pVertices[2].vWorldPosition.x = lightmap->position_x + flt_3C8C18 - flt_3C8C0C;
|
|
669 lightmap->pVertices[2].vWorldPosition.y = lightmap->position_y + flt_3C8C1C - flt_3C8C10;
|
|
670 lightmap->pVertices[2].vWorldPosition.z = lightmap->position_z + flt_3C8C20 - flt_3C8C14;
|
|
671 lightmap->pVertices[2].u = 1.0;
|
|
672 lightmap->pVertices[2].v = 1.0;
|
|
673
|
|
674 lightmap->pVertices[3].vWorldPosition.x = lightmap->position_x + flt_3C8C18 + flt_3C8C0C;
|
|
675 lightmap->pVertices[3].vWorldPosition.y = lightmap->position_y + flt_3C8C1C + flt_3C8C10;
|
|
676 lightmap->pVertices[3].vWorldPosition.z = lightmap->position_z + flt_3C8C20 + flt_3C8C14;
|
|
677 lightmap->pVertices[3].u = 1.0;
|
|
678 lightmap->pVertices[3].v = 0.0;
|
|
679
|
|
680 for (uint i = 0; i < 4; ++i)
|
|
681 {
|
|
682 v24 = a7->field_4.y * lightmap->pVertices[i].vWorldPosition.y
|
|
683 + a7->field_4.z * lightmap->pVertices[i].vWorldPosition.z
|
|
684 + a7->field_4.x * lightmap->pVertices[i].vWorldPosition.x
|
|
685 + a7->dist;
|
|
686
|
|
687 lightmap->pVertices[i].vWorldPosition.x -= v24 * a7->field_4.x;
|
|
688 lightmap->pVertices[i].vWorldPosition.y -= v24 * a7->field_4.y;
|
|
689 lightmap->pVertices[i].vWorldPosition.z -= v24 * a7->field_4.z;
|
|
690 }
|
|
691
|
|
692 lightmap->uColorMask = uColorMask;
|
|
693 lightmap->NumVertices = 4;
|
|
694
|
|
695 //Brightness(ÿðêîñòü)/////////////////////////////////
|
2541
|
696 if (~pEngine->uFlags2 & 4)
|
2532
|
697 lightmap->fBrightness = flt_3C8C2C_lightmaps_brightness;
|
|
698 else
|
|
699 {
|
|
700 Vec3_float_ a1; // [sp+2Ch] [bp-20h]@8
|
|
701 a1.x = (double)pos->x - lightmap->position_x;
|
|
702 a1.y = (double)pos->y - lightmap->position_y;
|
|
703 a1.z = (double)pos->z - lightmap->position_z;
|
|
704 a1.Normalize();
|
|
705
|
|
706 auto temp1 = lightmap->position_x + 0.5f,
|
|
707 temp2 = lightmap->position_y + 0.5f,
|
|
708 temp3 = lightmap->position_z + 0.5f;
|
|
709
|
|
710 auto dist_x = abs(pos->x - temp1), //v31
|
|
711 dist_y = abs(pos->y - temp2), //v32 arg0a
|
|
712 dist_z = abs(pos->z - temp3); //v33 _v64
|
|
713 v38 = int_get_vector_length(dist_x, dist_y, dist_z);
|
|
714 if (v38 > radius)
|
|
715 return true;
|
|
716 //radius = (1 / radius) * v38;
|
|
717 if ( uLightType & 4 )
|
|
718 {
|
|
719 v39 = fabs(a1.x * a7->field_4.x + a1.z * a7->field_4.z + a1.y * a7->field_4.y);
|
|
720 v40 = v39 * 1.0 * flt_4D86CC;
|
|
721
|
|
722 lightmap->fBrightness = v40 - ((1 / radius) * v38) * v40;
|
|
723 }
|
|
724 else if ( uLightType & 8 )
|
|
725 {
|
|
726 v40 = 1.0 * 1.0;
|
|
727 lightmap->fBrightness = v40 - ((1 / radius) * v38);
|
|
728 }
|
|
729 else
|
|
730 MessageBoxW(nullptr, L"Invalid light type!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:277", 0);
|
|
731 }
|
|
732 //Brightness(ÿðêîñòü)/////////////////////////////////////////////////////
|
|
733
|
2541
|
734 if (!pEngine->pStru9Instance->_4980B9(a9, uNumVertices,
|
2532
|
735 a7->field_4.x, a7->field_4.y, a7->field_4.z,
|
|
736 lightmap->pVertices, &lightmap->NumVertices))
|
|
737 return false;
|
|
738
|
|
739 if (!lightmap->NumVertices)
|
|
740 return true;
|
|
741
|
|
742 v45 = _45C6D6(uNumVertices, a9, lightmap);
|
|
743 if ( v45 != uNumVertices && v45 > 0 )
|
|
744 _45C4B9(uNumVertices, a9, lightmap);
|
|
745
|
2543
|
746 pIndoorCameraD3D->ViewTransform(lightmap->pVertices, lightmap->NumVertices);
|
|
747 pIndoorCameraD3D->Project(lightmap->pVertices, lightmap->NumVertices, 0);
|
2532
|
748
|
|
749 unsigned int _a4 = 0;
|
|
750 if ( !(uClipFlag & 1) )
|
|
751 _a4 = 1;
|
|
752 else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
|
|
753 {
|
|
754 if ( uClipFlag & 2 )
|
|
755 {
|
2543
|
756 pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
|
|
757 pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
|
2532
|
758 }
|
|
759 else if ( uClipFlag & 4 )
|
|
760 {
|
2543
|
761 pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
|
|
762 pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
|
2532
|
763 }
|
|
764 else
|
|
765 MessageBoxW(nullptr, L"Undefined clip flag specified", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330", 0);
|
|
766 }
|
|
767 else
|
|
768 MessageBoxW(nullptr, L"Lightpoly builder native indoor clipping not implemented", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:335", 0);
|
|
769
|
|
770 if (_a4)
|
|
771 {
|
|
772 if (uLightType & 1)
|
|
773 {
|
|
774 if (std__vector_000004_size < 512 - 1)
|
|
775 ++std__vector_000004_size;
|
|
776 }
|
|
777 else
|
|
778 {
|
|
779 if (std__vector_183808_size < 768 - 1)
|
|
780 ++std__vector_183808_size;
|
|
781 }
|
|
782 //if ( v50 ^ v51 )
|
|
783 // *(unsigned int *)v48 = v49 + 1;
|
|
784 }
|
|
785 return true;
|
|
786 }
|
|
787
|
|
788 //----- (0045C6D6) --------------------------------------------------------
|
|
789 int LightmapBuilder::_45C6D6(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
|
|
790 {
|
|
791 //For outdoor terrain and indoor light (V)(V)
|
|
792 signed int v6; // esi@1
|
|
793 float temp_x; // st7@6
|
|
794 float temp_y; // st6@10
|
|
795 float temp_z; // st5@14
|
|
796 float v12; // st7@17
|
|
797 int v15; // [sp+Ch] [bp-8h]@1
|
|
798
|
|
799 v6 = -1;
|
|
800 v15 = 0;
|
|
801 if ( (signed int)pLightmap->NumVertices > 0 )
|
|
802 {
|
|
803 for ( uint i = 0; i < (signed int)pLightmap->NumVertices; ++i )
|
|
804 {
|
|
805 if ( a2 > 0 )
|
|
806 {
|
|
807 for ( uint j = 0; j < a2; ++j )
|
|
808 {
|
|
809 if ( pLightmap->pVertices[i].vWorldPosition.x <= (double)a3[j].vWorldPosition.x )
|
|
810 temp_x = a3[j].vWorldPosition.x - pLightmap->pVertices[i].vWorldPosition.x;
|
|
811 else
|
|
812 temp_x = pLightmap->pVertices[i].vWorldPosition.x - a3[j].vWorldPosition.x;
|
|
813 if ( temp_x < 2.0 )
|
|
814 {
|
|
815 if ( pLightmap->pVertices[i].vWorldPosition.y <= (double)a3[j].vWorldPosition.y )
|
|
816 temp_y = a3[j].vWorldPosition.y - pLightmap->pVertices[i].vWorldPosition.y;
|
|
817 else
|
|
818 temp_y = pLightmap->pVertices[i].vWorldPosition.y - a3[j].vWorldPosition.y;
|
|
819 if ( temp_y < 2.0 )
|
|
820 {
|
|
821 if ( pLightmap->pVertices[i].vWorldPosition.z <= (double)a3[j].vWorldPosition.z )
|
|
822 temp_z = a3[j].vWorldPosition.z - pLightmap->pVertices[i].vWorldPosition.z;
|
|
823 else
|
|
824 temp_z = pLightmap->pVertices[i].vWorldPosition.z - a3[j].vWorldPosition.z;
|
|
825 if ( temp_z < 2.0 )
|
|
826 {
|
|
827 v12 = temp_x + temp_y + temp_z;
|
|
828 if ( v12 < FLT_MAX )
|
|
829 v6 = j;
|
|
830 }
|
|
831 }
|
|
832 }
|
|
833 }//For
|
|
834 if ( v6 != -1 )
|
|
835 {
|
|
836 ++v15;
|
|
837 pLightmap->pVertices[i].vWorldPosition.x = a3[v6].vWorldPosition.x;
|
|
838 pLightmap->pVertices[i].vWorldPosition.y = a3[v6].vWorldPosition.y;
|
|
839 pLightmap->pVertices[i].vWorldPosition.z = a3[v6].vWorldPosition.z;
|
|
840 }
|
|
841 }
|
|
842 v6 = -1;
|
|
843 }//For
|
|
844 }
|
|
845 return v15;
|
|
846 }
|
|
847
|
|
848 //----- (0045D73F) --------------------------------------------------------
|
|
849 void LightmapBuilder::DrawLightmapsType(int type)
|
|
850 {
|
|
851 //For outdoor and indoor light (II)(VIII)
|
|
852 if (type == 2)
|
|
853 Draw_183808_Lightmaps();
|
|
854 }
|
|
855
|
|
856 //----- (0045D74F) --------------------------------------------------------
|
|
857 bool LightmapBuilder::DrawLightmaps(int *indices)
|
|
858 {
|
|
859 //For outdoor terrain and indoor light (VI)(VI)
|
|
860 Lightmap *v28; // [sp+50h] [bp-38h]@2
|
|
861 Vec3_float_ arg4;
|
|
862
|
|
863 if (std__vector_000004_size == 0)
|
|
864 return true;
|
|
865
|
2541
|
866 if (byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_01_lightmap_related)
|
2532
|
867 return true;
|
|
868
|
|
869 pRenderer->BeginLightmaps();
|
|
870
|
|
871 arg4.x = 1.0f;
|
|
872 arg4.y = 1.0f;
|
|
873 arg4.z = 1.0f;
|
|
874 if (indices)
|
|
875 {
|
|
876 for (int* i = indices; *i != -1; ++i)
|
|
877 {
|
|
878 __debugbreak();//Not used?
|
|
879 v28 = &std__vector_000004[*i];
|
|
880 if ( !pRenderer->DrawLightmap(v28, &arg4, 0.0) )
|
|
881 Error("Invalid lightmap detected! (%u)", *i);
|
|
882 }
|
|
883 }
|
|
884 else
|
2561
|
885 if (for_refactoring)
|
2532
|
886 {
|
|
887 for (unsigned int i = 0; i < std__vector_000004_size; ++i)
|
|
888 if ( !pRenderer->DrawLightmap(std__vector_000004 + i, &arg4, 0.0) )
|
|
889 Error("Invalid lightmap detected! (%u)", i);
|
|
890 }
|
|
891
|
|
892 pRenderer->EndLightmaps();
|
|
893
|
|
894 return true;
|
|
895 }
|
|
896
|
|
897 //----- (0045DAE8) --------------------------------------------------------
|
|
898 bool Render::DrawLightmap(Lightmap *pLightmap, Vec3_float_ *pColorMult, float z_bias)
|
|
899 {
|
|
900 //For outdoor terrain and indoor light (VII)(VII)
|
|
901 signed int dwFlags; // [sp-1Ch] [bp-670h]@13
|
|
902 RenderVertexD3D3 pVerticesD3D[64]; // [sp+0h] [bp-654h]@7
|
|
903
|
|
904 if (pLightmap->NumVertices < 3)
|
|
905 {
|
|
906 Log::Warning(L"Lightmap uNumVertices < 3");
|
|
907 return false;
|
|
908 }
|
|
909
|
|
910 uint uLightmapColorMaskR = (pLightmap->uColorMask >> 16) & 0xFF,
|
|
911 uLightmapColorMaskG = (pLightmap->uColorMask >> 8) & 0xFF,
|
|
912 uLightmapColorMaskB = pLightmap->uColorMask & 0xFF;
|
|
913
|
|
914 uint uLightmapColorR = floorf(uLightmapColorMaskR * pLightmap->fBrightness * pColorMult->x + 0.5f),
|
|
915 uLightmapColorG = floorf(uLightmapColorMaskG * pLightmap->fBrightness * pColorMult->y + 0.5f),
|
|
916 uLightmapColorB = floorf(uLightmapColorMaskB * pLightmap->fBrightness * pColorMult->z + 0.5f);
|
|
917
|
|
918 for (uint i = 0; i < pLightmap->NumVertices; ++i)
|
|
919 {
|
|
920 float v18;
|
|
921 if (fabs(z_bias) < 1e-5)
|
2543
|
922 v18 = 1.0 - 1.0 / ((1.0f / pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0);
|
2532
|
923 else
|
|
924 {
|
2543
|
925 v18 = 1.0 - 1.0 / ((1.0f / pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias;
|
2532
|
926 if (v18 < 0.000099999997)
|
|
927 v18 = 0.000099999997;
|
|
928 }
|
|
929
|
|
930 pVerticesD3D[i].pos.x = pLightmap->pVertices[i].vWorldViewProjX;
|
|
931 pVerticesD3D[i].pos.y = pLightmap->pVertices[i].vWorldViewProjY;
|
|
932 pVerticesD3D[i].pos.z = v18;
|
|
933
|
|
934 pVerticesD3D[i].rhw = 1.0 / pLightmap->pVertices[i].vWorldViewPosition.x;
|
|
935 pVerticesD3D[i].diffuse = (uLightmapColorMaskR << 16) | (uLightmapColorMaskG << 8) | uLightmapColorB;
|
|
936 pVerticesD3D[i].specular = 0;
|
|
937
|
|
938 pVerticesD3D[i].texcoord.x = pLightmap->pVertices[i].u;
|
|
939 pVerticesD3D[i].texcoord.y = pLightmap->pVertices[i].v;
|
|
940 }
|
|
941
|
|
942 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
|
|
943 dwFlags = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS;
|
|
944 else
|
|
945 dwFlags = D3DDP_DONOTLIGHT;
|
|
946
|
|
947 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
|
|
948 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
|
|
949 pVerticesD3D, pLightmap->NumVertices, dwFlags));
|
|
950
|
|
951 return true;
|
|
952 }
|
|
953
|
|
954 //----- (0045DCA9) --------------------------------------------------------
|
|
955 void LightmapBuilder::Draw_183808_Lightmaps()
|
|
956 {
|
|
957 //For outdoor and indoor light (III)(IX)
|
|
958 if (!std__vector_183808_size)
|
|
959 return;
|
|
960
|
|
961 pRenderer->BeginLightmaps2();
|
|
962
|
|
963 DoDraw_183808_Lightmaps(0.00050000002);
|
|
964
|
|
965 pRenderer->EndLightmaps2();
|
|
966 }
|
|
967
|
|
968
|
|
969 ////////////////////////OTHER////////////////////////////////////////////////////////
|
|
970 //----- (0045CA88) --------------------------------------------------------
|
|
971 int LightmapBuilder::_45CA88(stru320 *a2, RenderVertexSoft *a3, int a4, Vec3_float_ *pNormal)
|
|
972 {
|
|
973 int result; // eax@1
|
|
974 stru320 *v6; // ecx@2
|
|
975 RenderVertexSoft *v7; // ebx@2
|
|
976 double v8; // st7@2
|
|
977 double v9; // st6@2
|
|
978 char *v10; // eax@3
|
|
979 double v11; // st7@5
|
|
980 __int64 v12; // ST2C_8@5
|
|
981 float v13; // edx@5
|
|
982 int v14; // eax@5
|
|
983 float v15; // ST10_4@5
|
|
984 Vec3_float_ v16; // ST00_12@5
|
|
985 double v17; // st7@5
|
|
986 int a5; // [sp+2Ch] [bp-1Ch]@1
|
|
987 float v19; // [sp+30h] [bp-18h]@1
|
|
988 float v20; // [sp+34h] [bp-14h]@1
|
|
989 //LightmapBuilder *thisa; // [sp+38h] [bp-10h]@1
|
|
990 int v22; // [sp+3Ch] [bp-Ch]@1
|
|
991 int *j; // [sp+40h] [bp-8h]@3
|
|
992 int i; // [sp+44h] [bp-4h]@1
|
|
993 int a3a; // [sp+58h] [bp+10h]@2
|
|
994
|
|
995 __debugbreak();//Not used?
|
|
996
|
|
997 *(float *)&a5 = 0.0;
|
|
998 v19 = 0.0;
|
|
999 //thisa = this;
|
|
1000 v20 = 0.0;
|
|
1001 result = _45CBD4(a3, a4, dword_69B010.data(), &v22);
|
|
1002 for ( i = 0; i < v22; result = i )
|
|
1003 {
|
|
1004 v6 = a2;
|
|
1005 a3a = 0;
|
|
1006 v7 = &a3[dword_69B010[i]];
|
|
1007 v8 = v7->vWorldPosition.z;
|
|
1008 v9 = v7->vWorldPosition.y;
|
|
1009 *(float *)&a5 = v7->vWorldPosition.x;
|
|
1010 v19 = v9;
|
|
1011 v20 = v8;
|
|
1012 v7->flt_2C = 0.0;
|
|
1013 if ( a2->uNumLightsApplied > 0 )
|
|
1014 {
|
|
1015 v10 = (char *)a2->_blv_lights_ys;
|
|
1016 for ( j = a2->_blv_lights_ys; ; v10 = (char *)j )
|
|
1017 {
|
|
1018 v11 = (double)*((signed int *)v10 - 60);
|
|
1019 LODWORD(v12) = *((unsigned int *)v10 - 20);
|
|
1020 HIDWORD(v12) = *(unsigned int *)v10;
|
|
1021 LODWORD(v13) = *((unsigned int *)v10 + 60);
|
|
1022 v14 = a3a;
|
|
1023 LOBYTE(v14) = v6->_blv_lights_types[a3a];
|
|
1024 v15 = v11;
|
|
1025 *(_QWORD *)&v16.x = v12;
|
|
1026 v16.z = v13;
|
|
1027 v17 = _45CC0C_light(v16/*COERCE_VEC3_FLOAT_(v16.x)*/, 1.0, v15, pNormal, *(float *)&a5/*COERCE_FLOAT(&a5)*/, v14)
|
|
1028 + v7->flt_2C;
|
|
1029 ++a3a;
|
|
1030 ++j;
|
|
1031 v7->flt_2C = v17;
|
|
1032 if ( a3a >= a2->uNumLightsApplied )
|
|
1033 break;
|
|
1034 v6 = a2;
|
|
1035 }
|
|
1036 }
|
|
1037 ++i;
|
|
1038 }
|
|
1039 return result;
|
|
1040 }
|
|
1041
|
|
1042 //----- (0045CB89) --------------------------------------------------------
|
|
1043 int LightmapBuilder::_45CB89(RenderVertexSoft *a1, int a2)
|
|
1044 {
|
|
1045 int v3; // edx@1
|
|
1046 int result; // eax@2
|
|
1047 char *v5; // ecx@2
|
|
1048 double v6; // st7@4
|
|
1049 __int16 v7; // fps@4
|
|
1050 char v8; // c0@4
|
|
1051 char v9; // c2@4
|
|
1052 char v10; // c3@4
|
|
1053 double v11; // st7@5
|
|
1054 double v12; // st7@6
|
|
1055 __int16 v13; // fps@6
|
|
1056 char v14; // c0@6
|
|
1057 char v15; // c2@6
|
|
1058 char v16; // c3@6
|
|
1059
|
|
1060 __debugbreak();//Not used?
|
|
1061 v3 = a2;
|
|
1062 if ( a2 > 0 )
|
|
1063 {
|
|
1064 HIWORD(result) = HIWORD(a1);
|
|
1065 v5 = (char *)&a1->flt_2C;
|
|
1066 do
|
|
1067 {
|
|
1068 __debugbreak(); // warning C4700: uninitialized local variable 'v7' used
|
|
1069 if ( *(float *)v5 < 0.0
|
|
1070 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) )
|
|
1071 {
|
|
1072 v12 = *(float *)v5;
|
|
1073 //UNDEF(v13);
|
|
1074 v14 = 0.0 < v12;
|
|
1075 v15 = 0;
|
|
1076 v16 = 0.0 == v12;
|
|
1077 __debugbreak(); // warning C4700: uninitialized local variable 'v13' used
|
|
1078 LOWORD(result) = v13;
|
|
1079 if ( v12 >= 0.0 )
|
|
1080 v11 = *(float *)v5;
|
|
1081 else
|
|
1082 v11 = 0.0;
|
|
1083 }
|
|
1084 else
|
|
1085 {
|
|
1086 v11 = 1.0;
|
|
1087 }
|
|
1088 *(float *)v5 = v11;
|
|
1089 v5 += 48;
|
|
1090 --v3;
|
|
1091 }
|
|
1092 while ( v3 );
|
|
1093 }
|
|
1094 return result;
|
|
1095 }
|
|
1096
|
|
1097 //----- (0045CBD4) --------------------------------------------------------
|
|
1098 int LightmapBuilder::_45CBD4(RenderVertexSoft *a2, int a3, int *a4, int *a5)
|
|
1099 {
|
|
1100 int result; // eax@1
|
|
1101 int v6; // edx@1
|
|
1102 int v7; // ecx@2
|
|
1103 int v8; // esi@2
|
|
1104
|
|
1105 __debugbreak();//Not used?
|
|
1106 result = (int)a5;
|
|
1107 v6 = 0;
|
|
1108 for ( *a5 = 0; v6 < a3; ++v6 )
|
|
1109 {
|
|
1110 v7 = *a5;
|
|
1111 v8 = 0;
|
|
1112 if ( *a5 <= 0 )
|
|
1113 {
|
|
1114 //LABEL_5:
|
|
1115 a4[v7] = v6;
|
|
1116 ++*a5;
|
|
1117 }
|
|
1118 else
|
|
1119 {
|
|
1120 while ( a4[v8] != v6 )
|
|
1121 {
|
|
1122 ++v8;
|
|
1123 if (v8 >= v7)
|
|
1124 {
|
|
1125 a4[v7] = v6;
|
|
1126 ++*a5;
|
|
1127 break;
|
|
1128 //goto LABEL_5;
|
|
1129 }
|
|
1130 }
|
|
1131 }
|
|
1132 }
|
|
1133 return result;
|
|
1134 }
|
|
1135
|
|
1136 //----- (0045CC0C) --------------------------------------------------------
|
|
1137 double LightmapBuilder::_45CC0C_light(Vec3_float_ a1, float a2, float a3, Vec3_float_ *pNormal, float a5, int uLightType)
|
|
1138 {
|
|
1139 float v7; // esi@1
|
|
1140 int v8; // eax@1
|
|
1141 double v14; // st7@7
|
|
1142 double result; // st7@8
|
|
1143 double v16; // st7@9
|
|
1144 int v17; // esi@9
|
|
1145 const char *v18; // ecx@9
|
|
1146 double v19; // st7@10
|
|
1147 double v20; // st7@10
|
|
1148 std::string v21; // [sp-10h] [bp-40h]@13
|
|
1149 const char *v22[6]; // [sp+0h] [bp-30h]@10
|
|
1150 double v23; // [sp+18h] [bp-18h]@1
|
|
1151 // double v24; // [sp+20h] [bp-10h]@1
|
|
1152 int v25; // [sp+28h] [bp-8h]@1
|
|
1153 int v26; // [sp+2Ch] [bp-4h]@1
|
|
1154
|
|
1155 __debugbreak();//Not used?
|
|
1156 v7 = a5;
|
|
1157 LODWORD(a5) = *(unsigned int *)(LODWORD(a5) + 8);
|
|
1158 //v24 = a5 + 6.7553994e15;
|
|
1159 v26 = floorf(a5 + 0.5f);//LODWORD(v24);
|
|
1160 LODWORD(a5) = *(unsigned int *)(LODWORD(v7) + 4);
|
|
1161 //v24 = a5 + 6.7553994e15;
|
|
1162 auto _v24 = floorf(a5 + 0.5f);
|
|
1163 LODWORD(a5) = *(unsigned int *)LODWORD(v7);
|
|
1164 //v23 = a5 + 6.7553994e15;
|
|
1165 auto _v23 = floorf(a5 + 0.5f);
|
|
1166 //*(_QWORD *)((char *)&v24 + 4) = __PAIR__(LODWORD(v24), LODWORD(v23));
|
|
1167 v26 = abs((signed)LODWORD(a1.z) - v26);
|
|
1168 //v25 = abs((signed)LODWORD(a1.y) - (signed)LODWORD(v24));
|
|
1169 //v8 = abs((int)a1.x - (signed)LODWORD(v23));
|
|
1170 v25 = abs((signed)LODWORD(a1.y) - (signed)_v24);
|
|
1171 v8 = abs((int)a1.x - (signed)_v23);
|
|
1172 v14 = int_get_vector_length(v26, v25, v8);
|
|
1173 if ( v14 <= a3 )
|
|
1174 {
|
|
1175 a5 = v14 / a3;
|
|
1176 v16 = (double)(signed int)a1.x;
|
|
1177 *(float *)&v23 = (double)SLODWORD(a1.y);
|
|
1178 LODWORD(a1.x) = *(unsigned int *)LODWORD(v7);
|
|
1179 v17 = LODWORD(v7) + 4;
|
|
1180 *((float *)&v23 + 1) = (double)SLODWORD(a1.z);
|
|
1181 LODWORD(a1.y) = *(unsigned int *)v17;
|
|
1182 LODWORD(a1.z) = *(unsigned int *)(v17 + 4);
|
|
1183 a3 = *((float *)&v23 + 1) - a1.z;
|
|
1184 a1.z = a3;
|
|
1185 a1.x = v16 - a1.x;
|
|
1186 a1.y = (float)v23 - a1.y;
|
|
1187 a1.Normalize();
|
|
1188 if ( uLightType & 4 )
|
|
1189 {
|
|
1190 __debugbreak(); // warning C4700: uninitialized local variable 'v18' used
|
|
1191 v22[1] = v18;
|
|
1192 uLightType = dword_4D86D8;
|
|
1193 v22[0] = v18;
|
|
1194 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x);
|
|
1195 v20 = v19 * *(float *)&uLightType * a2;
|
|
1196 }
|
|
1197 else
|
|
1198 {
|
|
1199 if ( uLightType & 8 )
|
|
1200 {
|
|
1201 v20 = 1.3 * a2;
|
|
1202 }
|
|
1203 else
|
|
1204 {
|
|
1205 MessageBoxW(nullptr, L"Invalid light type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:783", 0);
|
|
1206 v20 = *(float *)&uLightType;
|
|
1207 }
|
|
1208 }
|
|
1209 result = v20 - a5 * v20;
|
|
1210 }
|
|
1211 else
|
|
1212 {
|
|
1213 result = 0.0;
|
|
1214 }
|
|
1215 return result;
|
|
1216 }
|
|
1217
|
|
1218 // 4D86D8: using guessed type int dword_4D86D8;
|
|
1219 // 4E94D2: using guessed type char _4E94D2_light_type;
|
|
1220 // 519AB4: using guessed type int uNumStationaryLightsApplied;
|
|
1221
|
2496
|
1222 //----- (0045D698) --------------------------------------------------------
|
|
1223 bool LightmapBuilder::DrawDebugOutlines(char bit_one_for_list1__bit_two_for_list2)
|
|
1224 {
|
|
1225 bool result; // eax@1
|
|
1226 LightmapBuilder *v3; // esi@1
|
|
1227 RenderVertexSoft *v4; // edi@3
|
|
1228 RenderVertexSoft *v5; // edi@7
|
|
1229 IndoorCameraD3D *thisa; // [sp+10h] [bp-8h]@1
|
|
1230 bool v7; // [sp+14h] [bp-4h]@2
|
|
1231 bool a2a; // [sp+20h] [bp+8h]@6
|
|
1232
|
2532
|
1233 __debugbreak();//Not used?
|
2543
|
1234 result = (bool)pIndoorCameraD3D;
|
2496
|
1235 v3 = this;
|
2543
|
1236 thisa = pIndoorCameraD3D;
|
2496
|
1237 if ( bit_one_for_list1__bit_two_for_list2 & 1 )
|
|
1238 {
|
|
1239 v7 = 0;
|
|
1240 if ( (signed int)this->std__vector_000004_size > 0 )
|
|
1241 {
|
|
1242 v4 = this->std__vector_000004[0].pVertices;
|
|
1243 do
|
|
1244 {
|
2543
|
1245 pIndoorCameraD3D->debug_outline_sw(v4, *((unsigned int *)v4 - 1), 0xFF00u, 0.0);
|
2496
|
1246 ++v7;
|
|
1247 v4 = (RenderVertexSoft *)((char *)v4 + 3100);
|
|
1248 result = v7;
|
|
1249 }
|
|
1250 while ( v7 < (signed int)v3->std__vector_000004_size );
|
|
1251 }
|
|
1252 }
|
|
1253 if ( bit_one_for_list1__bit_two_for_list2 & 2 )
|
|
1254 {
|
|
1255 a2a = 0;
|
|
1256 if ( (signed int)v3->std__vector_183808_size > 0 )
|
|
1257 {
|
|
1258 v5 = v3->std__vector_183808[0].pVertices;
|
|
1259 do
|
|
1260 {
|
2543
|
1261 pIndoorCameraD3D->debug_outline_sw(v5, *((unsigned int *)v5 - 1), 0xC04000u, 0.00019999999);
|
2496
|
1262 ++a2a;
|
|
1263 v5 = (RenderVertexSoft *)((char *)v5 + 3100);
|
|
1264 result = a2a;
|
|
1265 }
|
|
1266 while ( a2a < (signed int)v3->std__vector_183808_size );
|
|
1267 }
|
|
1268 }
|
|
1269 LOBYTE(result) = 1;
|
|
1270 return result;
|
|
1271 }
|