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