comparison LightmapBuilder.cpp @ 0:9c0607679772

init
author Ritor1
date Sat, 12 Jan 2013 09:45:18 +0600
parents
children ca142e247b73 5a08b193507f
comparison
equal deleted inserted replaced
-1:000000000000 0:9c0607679772
1 #include "LightmapBuilder.h"
2 #include "Game.h"
3 #include "stru314.h"
4 #include "Outdoor.h"
5 #include "Log.h"
6
7 #include "mm7_data.h"
8
9
10
11
12
13
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
24
25
26 //----- (0045DF13) --------------------------------------------------------
27 Lightmap::Lightmap()
28 {
29 field_C18 = 0;
30 }
31
32
33
34
35
36 //----- (0045BB06) --------------------------------------------------------
37 LightmapBuilder::LightmapBuilder()
38 {
39 }
40
41
42
43
44
45 //----- (0045BC07) --------------------------------------------------------
46 bool LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, IndoorCameraD3D_Vec4 *a6, char uClipFlag)
47 {
48 Vec3_int_ pos; // [sp+2Ch] [bp-40h]@21
49 RenderVertexSoft *a9; // [sp+68h] [bp-4h]@8
50
51 if (!uNumVertices)
52 return false;
53
54 static RenderVertexSoft static_69B140[64];
55
56 a9 = a5;
57 if (a6)
58 {
59 for (uint i = 0; i < uNumVertices; ++i)
60 memcpy(static_69B140 + i, a5 + i, sizeof(RenderVertexSoft));
61
62 __debugbreak();
63 if (pGame->pIndoorCameraD3D->_437376(
64 a3,
65 static_69B140,
66 &uNumVertices) == 1)
67 {
68 if ( !uNumVertices )
69 return false;
70 a9 = static_69B140;
71 }
72 }
73
74 static stru314 static_69B110;
75 static_69B110.field_4.x = a3->face_plane.vNormal.x;
76 static_69B110.field_4.y = a3->face_plane.vNormal.y;
77 static_69B110.field_4.z = a3->face_plane.vNormal.z;
78 static_69B110.dist = a3->face_plane.dist;
79 if (!pGame->pIndoorCameraD3D->GetFacetOrientation(
80 a3->polygonType,
81 &static_69B110.field_4,
82 &static_69B110.field_10,
83 &static_69B110.field_1C))
84 {
85 MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0);
86 ExitProcess(0);
87 }
88
89 for (uint i = 0; i < a2->uNumLightsApplied; ++i)
90 {
91 pos.x = a2->_blv_lights_xs[i];
92 pos.y = a2->_blv_lights_ys[i];
93 pos.z = a2->_blv_lights_zs[i];
94
95 uint uColorR = (uint)floorf(a2->_blv_lights_rs[i] * 255.0 + 0.5f) & 0xFF,
96 uColorG = (uint)floorf(a2->_blv_lights_gs[i] * 255.0 + 0.5f) & 0xFF,
97 uColorB = (uint)floorf(a2->_blv_lights_bs[i] * 255.0 + 0.5f) & 0xFF;
98 uint uColor = (uColorR << 16) | (uColorG << 8) | uColorB;
99 if (!uColor)
100 uColor = 0x00FFFFF;
101
102 if (!_45BE86_build_light_polygon(
103 &pos,
104 a2->_blv_lights_radii[i],
105 uColor,
106 a2->_blv_lights_light_dot_faces[i],
107 a2->_blv_lights_types[i],
108 &static_69B110,
109 uNumVertices,
110 a9,
111 uClipFlag) )
112 {
113 MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0);
114 }
115 }
116 return true;
117 }
118
119 //----- (0045BE86) --------------------------------------------------------
120 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)
121 {
122 Lightmap *v11; // edi@3
123 double v17; // st7@5
124 double v24; // st7@6
125 int v31; // eax@8
126 int v32; // ebx@8
127 unsigned int v33; // ecx@8
128 int v34; // edx@9
129 int v35; // edx@11
130 unsigned int v36; // edx@13
131 int v37; // ecx@14
132 double v38; // st7@14
133 double v39; // st7@16
134 double v40; // st7@16
135 int v45; // eax@24
136 int v53; // [sp-8h] [bp-54h]@34
137
138 if (fabsf(radius) < 1e-6f)
139 return true;
140
141 v11 = uLightType & 1 ? &std__vector_000004[std__vector_000004_size] :
142 &std__vector_183808[std__vector_183808_size];
143 flt_3C8C24 = radius - dot_dist;
144 flt_3C8C28 = sqrt((radius + dot_dist) * (radius - dot_dist));
145 flt_3C8C2C_lightmaps_brightness = 1.0 - (radius - flt_3C8C28) / radius;
146 v11->field_C08 = (double)pos->x - dot_dist * a7->field_4.x;
147 v11->field_C0A = (double)pos->y - dot_dist * a7->field_4.y;
148 v11->field_C0C = (double)pos->z - dot_dist * a7->field_4.z;
149
150 v17 = radius * flt_3C8C2C_lightmaps_brightness;
151 flt_3C8C30 = v17;
152 flt_3C8C0C = v17 * a7->field_10.x;
153 flt_3C8C10 = v17 * a7->field_10.y;
154 flt_3C8C14 = v17 * a7->field_10.z;
155 flt_3C8C18 = v17 * a7->field_1C.x;
156 flt_3C8C1C = v17 * a7->field_1C.y;
157 flt_3C8C20 = v17 * a7->field_1C.z;
158
159 /*
160 v11->pVertices[0].vWorldPosition.x = v11->field_C08 - flt_3C8C18 + flt_3C8C0C;
161 v11->pVertices[0].vWorldPosition.y = v11->field_C0A - flt_3C8C1C + flt_3C8C10;
162 v11->pVertices[0].vWorldPosition.z = v11->field_C0C - flt_3C8C20 + flt_3C8C14;
163 v11->pVertices[0].u = 0.0;
164 v11->pVertices[0].v = 0.0;
165
166 v11->pVertices[1].vWorldPosition.x = v11->field_C08 - flt_3C8C18 - flt_3C8C0C;
167 v11->pVertices[1].vWorldPosition.y = v11->field_C0A - flt_3C8C1C - flt_3C8C10;
168 v11->pVertices[1].vWorldPosition.z = v11->field_C0C - flt_3C8C20 - flt_3C8C14;
169 v11->pVertices[1].u = 0.0;
170 v11->pVertices[1].v = 1.0;
171
172 v11->pVertices[2].vWorldPosition.x = v11->field_C08 + flt_3C8C18 - flt_3C8C0C;
173 v11->pVertices[2].vWorldPosition.y = v11->field_C0A + flt_3C8C1C - flt_3C8C10;
174 v11->pVertices[2].vWorldPosition.z = v11->field_C0C + flt_3C8C20 - flt_3C8C14;
175 v11->pVertices[2].u = 1.0;
176 v11->pVertices[2].v = 1.0;
177
178 v11->pVertices[3].vWorldPosition.x = v11->field_C08 + flt_3C8C18 + flt_3C8C0C;
179 v11->pVertices[3].vWorldPosition.y = v11->field_C0A + flt_3C8C1C + flt_3C8C10;
180 v11->pVertices[3].vWorldPosition.z = v11->field_C0C + flt_3C8C20 + flt_3C8C14;
181 v11->pVertices[3].u = 1.0;
182 v11->pVertices[3].v = 0.0;
183 */
184
185 for (uint i = 0; i < 4; ++i)
186 {
187 v11->pVertices[i].vWorldPosition.x = v11->field_C08 - flt_3C8C18 + flt_3C8C0C;
188 v11->pVertices[i].vWorldPosition.y = v11->field_C0A - flt_3C8C1C + flt_3C8C10;
189 v11->pVertices[i].vWorldPosition.z = v11->field_C0C - flt_3C8C20 + flt_3C8C14;
190 v11->pVertices[i].u = 0.0;
191 v11->pVertices[i].v = 0.0;
192
193 v24 = a7->field_4.y * v11->pVertices[i].vWorldPosition.y
194 + a7->field_4.z * v11->pVertices[i].vWorldPosition.z
195 + a7->field_4.x * v11->pVertices[i].vWorldPosition.x
196 + a7->dist;
197
198 v11->pVertices[i].vWorldPosition.x -= v24 * a7->field_4.x;
199 v11->pVertices[i].vWorldPosition.y -= v24 * a7->field_4.y;
200 v11->pVertices[i].vWorldPosition.z -= v24 * a7->field_4.z;
201 }
202
203 v11->uColorMask = uColorMask;
204 v11->uNumVertices = 4;
205
206 if (~pGame->uFlags2 & 4)
207 v11->fBrightness = flt_3C8C2C_lightmaps_brightness;
208 else
209 {
210 Vec3_float_ a1; // [sp+2Ch] [bp-20h]@8
211 a1.x = (double)pos->x - v11->field_C08;
212 a1.y = (double)pos->y - v11->field_C0A;
213 a1.z = (double)pos->z - v11->field_C0C;
214 a1.Normalize();
215
216 auto dist_x = abs(pos->x - v11->field_C08), //v31
217 dist_y = abs(pos->y - v11->field_C0A), //v32 arg0a
218 dist_z = abs(pos->z - v11->field_C0C); //v33 _v64
219 v31 = dist_x;
220 v32 = dist_y;
221 v33 = dist_z;
222 if (v31 < dist_y)
223 {
224 v34 = v31;
225 v31 = dist_y;
226 v32 = v34;
227 }
228 if (v31 < dist_z)//SHIDWORD(v64) )
229 {
230 v35 = v31;
231 v31 = dist_z;//HIDWORD(v64);
232 v33 = v35;
233 }
234 if ( v32 < (signed int)v33 )
235 {
236 v36 = v33;
237 v33 = v32;
238 v32 = v36;
239 }
240 v37 = v33 >> 2;
241 //LODWORD(a5) = ((unsigned int)(11 * v32) >> 5) + v37 + v31;
242 v38 = (double)(signed)(((unsigned int)(11 * v32) >> 5) + v37 + v31);
243 if (v38 > radius)
244 return true;
245 //radius = (1 / radius) * v38;
246 if ( uLightType & 4 )
247 {
248 //v59 = (void *)v37;
249 //uLightType = flt_4D86CC;
250 //v58 = v37;
251 v39 = fabs(a1.x * a7->field_4.x + a1.z * a7->field_4.z + a1.y * a7->field_4.y);
252 v40 = v39 * 1.0 * flt_4D86CC;
253
254 v11->fBrightness = v40 - (1 / radius) * v38 * v40;
255 }
256 else if ( uLightType & 8 )
257 {
258 v40 = 1.0 * 1.0;
259 v11->fBrightness = v40 - (1 / radius) * v38;
260 }
261 else
262 {
263 MessageBoxW(nullptr, L"Invalid light type!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:277", 0);
264 }
265 }
266
267 if (!pGame->pStru9Instance->_4980B9(a9, uNumVertices,
268 a7->field_4.x, a7->field_4.y, a7->field_4.z,
269 v11->pVertices, &v11->uNumVertices))
270 return false;
271
272 //v44 = &v11->uNumVertices;
273 if (!v11->uNumVertices)
274 return true;
275
276 v45 = _45C6D6(uNumVertices, a9, v11);
277 if ( v45 != uNumVertices && v45 > 0 )
278 _45C4B9(uNumVertices, a9, v11);
279 //v59 = v11->uNumVertices;
280 //v46 = (RenderVertexSoft *)pLightmapVertices_;
281 pGame->pIndoorCameraD3D->ViewTransform(v11->pVertices, v11->uNumVertices);
282 //v59 = 0;
283 //v58 = v11->uNumVertices;
284 pGame->pIndoorCameraD3D->Project(v11->pVertices, v11->uNumVertices, 0);
285
286 unsigned int _a4 = 0;
287 if ( !(uClipFlag & 1) )
288 _a4 = 1;
289 else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
290 {
291 if ( uClipFlag & 2 )
292 {
293 //v59 = &a4;
294 //v58 = (unsigned int)field_3C8C34;
295 //v57 = *v44;
296 pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(v11->pVertices, v11->uNumVertices, field_3C8C34, &_a4);
297
298 //v59 = v44;
299 //v58 = (unsigned int)field_3C8C34;
300 //v57 = (int)v46;
301 //v56 = a4;
302 pGame->pIndoorCameraD3D->_437143(_a4, v11->pVertices, field_3C8C34, &v11->uNumVertices);
303 }
304 else if ( uClipFlag & 4 )
305 {
306 //v59 = &a4;
307 //v58 = (unsigned int)field_3C8C34;
308 //v57 = *v44;
309 pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(v11->pVertices, v11->uNumVertices, field_3C8C34, &_a4);
310
311 //v59 = v44;
312 //v58 = (unsigned int)field_3C8C34;
313 //v57 = (int)v46;
314 //v56 = a4;
315 pGame->pIndoorCameraD3D->_437143(_a4, v11->pVertices, field_3C8C34, &v11->uNumVertices);
316 }
317 else
318 MessageBoxW(nullptr, L"Undefined clip flag specified", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330", 0);
319 }
320 else
321 MessageBoxW(nullptr, L"Lightpoly builder native indoor clipping not implemented", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:335", 0);
322
323 if (_a4)
324 {
325 if (uLightType & 1)
326 {
327 //v48 = (char *)&std__vector_000004_size;
328 //v49 = std__vector_000004_size;
329 //v51 = __OFSUB__(std__vector_000004_size, 511);
330 //v50 = std__vector_000004_size - 511 < 0;
331 if (std__vector_000004_size < 512 - 1)
332 ++std__vector_000004_size;
333 }
334 else
335 {
336 //v48 = (char *)&std__vector_183808_size;
337 //v49 = std__vector_183808_size;
338 //v51 = __OFSUB__(std__vector_183808_size, 767);
339 //v50 = std__vector_183808_size - 767 < 0;
340 if (std__vector_183808_size < 768 - 1)
341 ++std__vector_183808_size;
342 }
343 //if ( v50 ^ v51 )
344 // *(unsigned int *)v48 = v49 + 1;
345 }
346 return true;
347 }
348
349 //----- (0045C4B9) --------------------------------------------------------
350 int LightmapBuilder::_45C4B9(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
351 {
352 Lightmap *v4; // edi@1
353 int v5; // eax@1
354 signed int v6; // ecx@1
355 RenderVertexSoft *v7; // ebx@2
356 int v8; // edx@3
357 RenderVertexSoft *v9; // esi@3
358 int v10; // eax@6
359 char *v11; // edi@7
360 RenderVertexSoft *v12; // ecx@8
361 char v13; // bl@17
362 signed int v14; // edx@17
363 double v15; // st6@18
364 double v16; // st6@21
365 double v17; // st6@24
366 signed int v18; // edx@33
367 int v20; // [sp+4h] [bp-1Ch]@3
368 int v21; // [sp+8h] [bp-18h]@8
369 float v22; // [sp+Ch] [bp-14h]@23
370 float v23; // [sp+10h] [bp-10h]@20
371 int v24; // [sp+14h] [bp-Ch]@1
372 RenderVertexSoft *v25; // [sp+18h] [bp-8h]@2
373 char v26; // [sp+1Eh] [bp-2h]@17
374 char v27; // [sp+1Fh] [bp-1h]@17
375
376 v4 = pLightmap;
377 v5 = 0;
378 v6 = pLightmap->uNumVertices;
379 v24 = 0;
380 if ( v6 > 0 )
381 {
382 v7 = pLightmap->pVertices;
383 v25 = pLightmap->pVertices;
384 do
385 {
386 v20 = v5 + 1;
387 v8 = (v5 + 1) % v6;
388 v9 = &v4->pVertices[v8];
389 if ( v7->vWorldPosition.x != v9->vWorldPosition.x
390 || v7->vWorldPosition.y != v4->pVertices[v8].vWorldPosition.y
391 || v7->vWorldPosition.z != v4->pVertices[v8].vWorldPosition.z )
392 {
393 v10 = 0;
394 if ( a2 > 0 )
395 {
396 v11 = (char *)&a3->vWorldPosition.z;
397 do
398 {
399 v21 = v10 + 1;
400 v12 = &a3[(v10 + 1) % a2];
401 if ( (*((float *)v11 - 2) != v12->vWorldPosition.x
402 || *((float *)v11 - 1) != v12->vWorldPosition.y
403 || *(float *)v11 != v12->vWorldPosition.z)
404 && v7->vWorldPosition.x == *((float *)v11 - 2)
405 && v7->vWorldPosition.y == *((float *)v11 - 1)
406 && v7->vWorldPosition.z == *(float *)v11
407 && (v9->vWorldPosition.x != v12->vWorldPosition.x
408 || v9->vWorldPosition.y != v12->vWorldPosition.y
409 || v9->vWorldPosition.z != v12->vWorldPosition.z) )
410 {
411 v13 = 0;
412 v14 = 0;
413 v27 = 0;
414 v26 = 0;
415 if ( v9->vWorldPosition.x <= (double)v12->vWorldPosition.x )
416 v15 = v12->vWorldPosition.x - v9->vWorldPosition.x;
417 else
418 v15 = v9->vWorldPosition.x - v12->vWorldPosition.x;
419 v23 = v15;
420 if ( v9->vWorldPosition.y <= (double)v12->vWorldPosition.y )
421 v16 = v12->vWorldPosition.y - v9->vWorldPosition.y;
422 else
423 v16 = v9->vWorldPosition.y - v12->vWorldPosition.y;
424 v22 = v16;
425 if ( v9->vWorldPosition.z <= (double)v12->vWorldPosition.z )
426 v17 = v12->vWorldPosition.z - v9->vWorldPosition.z;
427 else
428 v17 = v9->vWorldPosition.z - v12->vWorldPosition.z;
429 if ( v23 < 1.0 )
430 {
431 v13 = 1;
432 v14 = 1;
433 }
434 if ( v22 < 1.0 )
435 {
436 v27 = 1;
437 ++v14;
438 }
439 if ( v17 < 1.0 )
440 {
441 v26 = 1;
442 ++v14;
443 }
444 if ( v14 > 1 )
445 {
446 v18 = 0;
447 if ( v13 && v9->vWorldPosition.x != v12->vWorldPosition.x )
448 {
449 v18 = 1;
450 v9->vWorldPosition.x = v12->vWorldPosition.x;
451 }
452 if ( v27 && v9->vWorldPosition.y != v12->vWorldPosition.y )
453 {
454 ++v18;
455 v9->vWorldPosition.y = v12->vWorldPosition.y;
456 }
457 if ( v26 && v9->vWorldPosition.z != v12->vWorldPosition.z )
458 {
459 ++v18;
460 v9->vWorldPosition.z = v12->vWorldPosition.z;
461 }
462 if ( v18 > 0 )
463 ++v24;
464 }
465 v7 = v25;
466 }
467 ++v10;
468 v11 += 48;
469 }
470 while ( v21 < a2 );
471 v4 = pLightmap;
472 }
473 }
474 v5 = v20;
475 v6 = v4->uNumVertices;
476 ++v7;
477 v25 = v7;
478 }
479 while ( v20 < v6 );
480 }
481 return v24;
482 }
483
484 //----- (0045C6D6) --------------------------------------------------------
485 int LightmapBuilder::_45C6D6(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
486 {
487 Lightmap *v4; // edi@1
488 signed int v5; // ebx@1
489 signed int v6; // esi@1
490 RenderVertexSoft *v7; // ecx@2
491 char *v8; // edx@4
492 double v9; // st7@6
493 double v10; // st6@10
494 double v11; // st5@14
495 double v12; // st7@17
496 RenderVertexSoft *v13; // eax@21
497 int v15; // [sp+Ch] [bp-8h]@1
498 float v16; // [sp+10h] [bp-4h]@1
499 int pLightmapa; // [sp+24h] [bp+10h]@3
500
501 v4 = pLightmap;
502 v5 = 0;
503 v6 = -1;
504 v16 = 3.4028235e38;
505 v15 = 0;
506 if ( (signed int)pLightmap->uNumVertices > 0 )
507 {
508 v7 = pLightmap->pVertices;
509 do
510 {
511 pLightmapa = 0;
512 if ( a2 > 0 )
513 {
514 v8 = (char *)&a3->vWorldPosition.z;
515 do
516 {
517 if ( v7->vWorldPosition.x <= (double)*((float *)v8 - 2) )
518 v9 = *((float *)v8 - 2) - v7->vWorldPosition.x;
519 else
520 v9 = v7->vWorldPosition.x - *((float *)v8 - 2);
521 if ( v9 < 2.0 )
522 {
523 v10 = v7->vWorldPosition.y <= (double)*((float *)v8 - 1) ? *((float *)v8 - 1) - v7->vWorldPosition.y : v7->vWorldPosition.y - *((float *)v8 - 1);
524 if ( v10 < 2.0 )
525 {
526 v11 = v7->vWorldPosition.z <= (double)*(float *)v8 ? *(float *)v8 - v7->vWorldPosition.z : v7->vWorldPosition.z - *(float *)v8;
527 if ( v11 < 2.0 )
528 {
529 v12 = v9 + v11 + v10;
530 if ( v12 < v16 )
531 {
532 v16 = v12;
533 v6 = pLightmapa;
534 }
535 }
536 }
537 }
538 ++pLightmapa;
539 v8 += 48;
540 }
541 while ( pLightmapa < a2 );
542 if ( v6 != -1 )
543 {
544 v13 = &a3[v6];
545 ++v15;
546 v7->vWorldPosition.x = v13->vWorldPosition.x;
547 v7->vWorldPosition.y = v13->vWorldPosition.y;
548 v7->vWorldPosition.z = v13->vWorldPosition.z;
549 }
550 }
551 v6 = -1;
552 ++v5;
553 ++v7;
554 v16 = 3.4028235e38;
555 }
556 while ( v5 < (signed int)v4->uNumVertices );
557 }
558 return v15;
559 }
560
561 //----- (0045C7F6) --------------------------------------------------------
562 bool LightmapBuilder::ApplyLights_IndoorFace(unsigned int uFaceID)
563 {
564 auto pFace = &pIndoor->pFaces[uFaceID];
565 auto pSector = pIndoor->pSectors + pFace->uSectorID;
566
567 stru_F8AD28.uCurrentAmbientLightLevel = (stru_F8AD28.uDefaultAmbientLightLevel + pSector->uMinAmbientLightLevel) << 16;
568
569 uint uNumLightsApplied = 0;
570 for (uint i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
571 {
572 if (uNumLightsApplied >= 20)
573 break;
574
575 ApplyLight_BLV((StationaryLight *)(pMobileLightsStack->pLights + i), pFace, &uNumLightsApplied, true, 0);
576 }
577
578 for (uint i = 0; i < pSector->uNumLights; ++i)
579 {
580 if (uNumLightsApplied >= 20 )
581 break;
582
583 auto pLight = &pIndoor->pLights[pSector->pLights[i]];
584 if (~pLight->uAtributes & 0x08)
585 ApplyLight_BLV((StationaryLight *)pLight, pFace, &uFaceID, false, &byte_4E94D0);
586 }
587
588 for (uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
589 {
590 if (uNumLightsApplied >= 20)
591 break;
592
593 ApplyLight_BLV(pStationaryLightsStack->pLights + i, pFace, &uNumLightsApplied, false, &byte_4E94D0);
594 }
595
596 stru_F8AD28.uNumLightsApplied = uNumLightsApplied;
597 return true;
598 }
599
600 //----- (0045C911) --------------------------------------------------------
601 bool LightmapBuilder::ApplyLight_BLV(StationaryLight *pLight, BLVFace *a2, unsigned int *pSlot, bool bLightBackfaces, char *a5)
602 {
603 double v13; // st7@8
604
605 if (!pLight->uRadius)
606 return false;
607
608 if (pLight->vPosition.x > a2->pBounding.x1 - pLight->uRadius &&
609 pLight->vPosition.x < a2->pBounding.x2 + pLight->uRadius &&
610 pLight->vPosition.y > a2->pBounding.y1 - pLight->uRadius &&
611 pLight->vPosition.y < a2->pBounding.y2 + pLight->uRadius &&
612 pLight->vPosition.z > a2->pBounding.z1 - pLight->uRadius &&
613 pLight->vPosition.z < a2->pBounding.z2 + pLight->uRadius)
614 {
615 v13 = (double)pLight->vPosition.z * a2->pFacePlane.vNormal.z +
616 (double)pLight->vPosition.y * a2->pFacePlane.vNormal.y +
617 (double)pLight->vPosition.x * a2->pFacePlane.vNormal.x +
618 a2->pFacePlane.dist;
619 if ((bLightBackfaces || v13 >= 0.0f) && fabsf(v13) <= pLight->uRadius)
620 {
621 auto slot = *pSlot;
622
623 stru_F8AD28._blv_lights_radii[slot] = pLight->uRadius;
624 stru_F8AD28._blv_lights_inv_radii[slot] = 65536 / pLight->uRadius;
625 stru_F8AD28._blv_lights_xs[slot] = pLight->vPosition.x;
626 stru_F8AD28._blv_lights_ys[slot] = pLight->vPosition.y;
627 stru_F8AD28._blv_lights_zs[slot] = pLight->vPosition.z;
628 stru_F8AD28._blv_lights_rs[slot] = (double)pLight->uLightColorR / 255.0f;
629 stru_F8AD28._blv_lights_gs[slot] = (double)pLight->uLightColorG / 255.0f;
630 stru_F8AD28._blv_lights_bs[slot] = (double)pLight->uLightColorB / 255.0f;
631 stru_F8AD28._blv_lights_light_dot_faces[slot] = abs((int)floorf(v13 + 0.5f));
632 stru_F8AD28._blv_lights_types[slot] = pLight->uLightType;
633
634 *pSlot += 1;
635 return true;
636 }
637 }
638
639 return false;
640 }
641
642 //----- (0045CA88) --------------------------------------------------------
643 int LightmapBuilder::_45CA88(stru320 *a2, RenderVertexSoft *a3, int a4, Vec3_float_ *pNormal)
644 {
645 int result; // eax@1
646 stru320 *v6; // ecx@2
647 RenderVertexSoft *v7; // ebx@2
648 double v8; // st7@2
649 double v9; // st6@2
650 char *v10; // eax@3
651 double v11; // st7@5
652 __int64 v12; // ST2C_8@5
653 float v13; // edx@5
654 int v14; // eax@5
655 float v15; // ST10_4@5
656 Vec3_float_ v16; // ST00_12@5
657 double v17; // st7@5
658 int a5; // [sp+2Ch] [bp-1Ch]@1
659 float v19; // [sp+30h] [bp-18h]@1
660 float v20; // [sp+34h] [bp-14h]@1
661 LightmapBuilder *thisa; // [sp+38h] [bp-10h]@1
662 int v22; // [sp+3Ch] [bp-Ch]@1
663 int *j; // [sp+40h] [bp-8h]@3
664 int i; // [sp+44h] [bp-4h]@1
665 int a3a; // [sp+58h] [bp+10h]@2
666
667 *(float *)&a5 = 0.0;
668 v19 = 0.0;
669 thisa = this;
670 v20 = 0.0;
671 result = _45CBD4(a3, a4, dword_69B010, &v22);
672 for ( i = 0; i < v22; result = i )
673 {
674 v6 = a2;
675 a3a = 0;
676 v7 = &a3[dword_69B010[i]];
677 v8 = v7->vWorldPosition.z;
678 v9 = v7->vWorldPosition.y;
679 *(float *)&a5 = v7->vWorldPosition.x;
680 v19 = v9;
681 v20 = v8;
682 v7->flt_2C = 0.0;
683 if ( a2->uNumLightsApplied > 0 )
684 {
685 v10 = (char *)a2->_blv_lights_ys;
686 for ( j = a2->_blv_lights_ys; ; v10 = (char *)j )
687 {
688 v11 = (double)*((signed int *)v10 - 60);
689 LODWORD(v12) = *((unsigned int *)v10 - 20);
690 HIDWORD(v12) = *(unsigned int *)v10;
691 LODWORD(v13) = *((unsigned int *)v10 + 60);
692 v14 = a3a;
693 LOBYTE(v14) = v6->_blv_lights_types[a3a];
694 v15 = v11;
695 *(_QWORD *)&v16.x = v12;
696 v16.z = v13;
697 v17 = _45CC0C_light(v16/*COERCE_VEC3_FLOAT_(v16.x)*/, 1.0, v15, pNormal, *(float *)&a5/*COERCE_FLOAT(&a5)*/, v14)
698 + v7->flt_2C;
699 ++a3a;
700 ++j;
701 v7->flt_2C = v17;
702 if ( a3a >= a2->uNumLightsApplied )
703 break;
704 v6 = a2;
705 }
706 }
707 ++i;
708 }
709 return result;
710 }
711
712 //----- (0045CB89) --------------------------------------------------------
713 int LightmapBuilder::_45CB89(RenderVertexSoft *a1, int a2)
714 {
715 int v3; // edx@1
716 int result; // eax@2
717 char *v5; // ecx@2
718 double v6; // st7@4
719 __int16 v7; // fps@4
720 char v8; // c0@4
721 char v9; // c2@4
722 char v10; // c3@4
723 double v11; // st7@5
724 double v12; // st7@6
725 __int16 v13; // fps@6
726 char v14; // c0@6
727 char v15; // c2@6
728 char v16; // c3@6
729
730 v3 = a2;
731 if ( a2 > 0 )
732 {
733 HIWORD(result) = HIWORD(a1);
734 v5 = (char *)&a1->flt_2C;
735 do
736 {
737 if ( *(float *)v5 < 0.0
738 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) )
739 {
740 v12 = *(float *)v5;
741 //UNDEF(v13);
742 v14 = 0.0 < v12;
743 v15 = 0;
744 v16 = 0.0 == v12;
745 LOWORD(result) = v13;
746 if ( v12 >= 0.0 )
747 v11 = *(float *)v5;
748 else
749 v11 = 0.0;
750 }
751 else
752 {
753 v11 = 1.0;
754 }
755 *(float *)v5 = v11;
756 v5 += 48;
757 --v3;
758 }
759 while ( v3 );
760 }
761 return result;
762 }
763
764 //----- (0045CBD4) --------------------------------------------------------
765 int LightmapBuilder::_45CBD4(RenderVertexSoft *a2, int a3, int *a4, int *a5)
766 {
767 int result; // eax@1
768 int v6; // edx@1
769 int v7; // ecx@2
770 int v8; // esi@2
771
772 result = (int)a5;
773 v6 = 0;
774 for ( *a5 = 0; v6 < a3; ++v6 )
775 {
776 v7 = *a5;
777 v8 = 0;
778 if ( *a5 <= 0 )
779 {
780 LABEL_5:
781 a4[v7] = v6;
782 ++*a5;
783 }
784 else
785 {
786 while ( a4[v8] != v6 )
787 {
788 ++v8;
789 if ( v8 >= v7 )
790 goto LABEL_5;
791 }
792 }
793 }
794 return result;
795 }
796
797 //----- (0045CC0C) --------------------------------------------------------
798 double LightmapBuilder::_45CC0C_light(Vec3_float_ a1, float a2, float a3, Vec3_float_ *pNormal, float a5, int uLightType)
799 {
800 float v7; // esi@1
801 int v8; // eax@1
802 int v9; // ebx@1
803 unsigned int v10; // ecx@1
804 int v11; // edx@2
805 int v12; // edx@4
806 unsigned int v13; // edx@6
807 double v14; // st7@7
808 double result; // st7@8
809 double v16; // st7@9
810 int v17; // esi@9
811 const char *v18; // ecx@9
812 double v19; // st7@10
813 double v20; // st7@10
814 std::string v21; // [sp-10h] [bp-40h]@13
815 const char *v22[6]; // [sp+0h] [bp-30h]@10
816 double v23; // [sp+18h] [bp-18h]@1
817 double v24; // [sp+20h] [bp-10h]@1
818 int v25; // [sp+28h] [bp-8h]@1
819 int v26; // [sp+2Ch] [bp-4h]@1
820
821 v7 = a5;
822 LODWORD(a5) = *(unsigned int *)(LODWORD(a5) + 8);
823 //v24 = a5 + 6.7553994e15;
824 v26 = floorf(a5 + 0.5f);//LODWORD(v24);
825 LODWORD(a5) = *(unsigned int *)(LODWORD(v7) + 4);
826 //v24 = a5 + 6.7553994e15;
827 auto _v24 = floorf(a5 + 0.5f);
828 LODWORD(a5) = *(unsigned int *)LODWORD(v7);
829 //v23 = a5 + 6.7553994e15;
830 auto _v23 = floorf(a5 + 0.5f);
831 //*(_QWORD *)((char *)&v24 + 4) = __PAIR__(LODWORD(v24), LODWORD(v23));
832 v26 = abs((signed)LODWORD(a1.z) - v26);
833 //v25 = abs((signed)LODWORD(a1.y) - (signed)LODWORD(v24));
834 //v8 = abs((int)a1.x - (signed)LODWORD(v23));
835 v25 = abs((signed)LODWORD(a1.y) - (signed)_v24);
836 v8 = abs((int)a1.x - (signed)_v23);
837 LODWORD(a5) = v8;
838 v9 = v25;
839 v10 = v26;
840 if ( v8 < v25 )
841 {
842 v11 = v8;
843 v8 = v25;
844 v9 = v11;
845 }
846 if ( v8 < v26 )
847 {
848 v12 = v8;
849 v8 = v26;
850 v10 = v12;
851 }
852 if ( v9 < (signed int)v10 )
853 {
854 v13 = v10;
855 v10 = v9;
856 v9 = v13;
857 }
858 v14 = (double)(signed int)(((unsigned int)(11 * v9) >> 5) + (v10 >> 2) + v8);
859 if ( v14 <= a3 )
860 {
861 a5 = v14 / a3;
862 v16 = (double)(signed int)a1.x;
863 *(float *)&v23 = (double)SLODWORD(a1.y);
864 LODWORD(a1.x) = *(unsigned int *)LODWORD(v7);
865 v17 = LODWORD(v7) + 4;
866 *((float *)&v23 + 1) = (double)SLODWORD(a1.z);
867 LODWORD(a1.y) = *(unsigned int *)v17;
868 LODWORD(a1.z) = *(unsigned int *)(v17 + 4);
869 a3 = *((float *)&v23 + 1) - a1.z;
870 a1.z = a3;
871 a1.x = v16 - a1.x;
872 a1.y = (float)v23 - a1.y;
873 a1.Normalize();
874 if ( uLightType & 4 )
875 {
876 v22[1] = v18;
877 uLightType = dword_4D86D8;
878 v22[0] = v18;
879 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x);
880 v20 = v19 * *(float *)&uLightType * a2;
881 }
882 else
883 {
884 if ( uLightType & 8 )
885 {
886 v20 = 1.3 * a2;
887 }
888 else
889 {
890 MessageBoxW(nullptr, L"Invalid light type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:783", 0);
891 v20 = *(float *)&uLightType;
892 }
893 }
894 result = v20 - a5 * v20;
895 }
896 else
897 {
898 result = 0.0;
899 }
900 return result;
901 }
902 // 4D86D8: using guessed type int dword_4D86D8;
903
904 //----- (0045CDB7) --------------------------------------------------------
905 bool LightmapBuilder::ApplyLights_OutdoorFace(ODMFace *pFace)
906 {
907 int v2; // esi@1
908 int v3; // eax@1
909 MobileLight *pMobileLight; // ebx@2
910 int v5; // esi@5
911 StationaryLight *pStationaryLight; // ebx@6
912 bool result; // eax@9
913 LightmapBuilder *thisa; // [sp+Ch] [bp-8h]@1
914 int pSlot; // [sp+10h] [bp-4h]@1
915
916 v2 = 0;
917 thisa = this;
918 v3 = stru_F8AD28.uDefaultAmbientLightLevel + pFace->uShadeType;
919 pSlot = 0;
920 stru_F8AD28.uCurrentAmbientLightLevel = v3 << 16;
921 if ( pMobileLightsStack->uNumLightsActive > 0 )
922 {
923 pMobileLight = pMobileLightsStack->pLights;
924 do
925 {
926 if ( pSlot >= 20 )
927 break;
928 ApplyLight_ODM((StationaryLight *)pMobileLight, pFace, (unsigned int *)&pSlot, 1);
929 ++v2;
930 ++pMobileLight;
931 }
932 while ( v2 < pMobileLightsStack->uNumLightsActive );
933 }
934 v5 = 0;
935 if ( pStationaryLightsStack->uNumLightsActive > 0 )
936 {
937 pStationaryLight = pStationaryLightsStack->pLights;
938 do
939 {
940 if ( pSlot >= 20 )
941 break;
942 ApplyLight_ODM(pStationaryLight, pFace, (unsigned int *)&pSlot, 0);
943 ++v5;
944 ++pStationaryLight;
945 }
946 while ( v5 < pStationaryLightsStack->uNumLightsActive );
947 }
948 result = pSlot;
949 stru_F8AD28.uNumLightsApplied = pSlot;
950 return true;
951 }
952
953 //----- (0045CE50) --------------------------------------------------------
954 bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4)
955 {
956 int result; // eax@0
957 signed int v6; // ebx@1
958 int v7; // ecx@2
959 int v8; // esi@4
960 int v9; // edx@6
961 int v10; // ecx@8
962 int v11; // eax@11
963 unsigned int v12; // ebx@11
964 RenderD3D *v13; // ecx@11
965 char v14; // dl@11
966
967 __debugbreak();
968
969 v6 = pLight->uRadius;
970 if ( v6 > 0
971 && (result = (int)pFace, v7 = pLight->vPosition.x, v7 > pFace->pBoundingBox.x1 - v6)
972 && v7 < v6 + pFace->pBoundingBox.x2
973 && (v8 = pLight->vPosition.y, v8 > pFace->pBoundingBox.y1 - v6)
974 && v8 < v6 + pFace->pBoundingBox.y2
975 && (v9 = pLight->vPosition.z, v9 > pFace->pBoundingBox.z1 - v6)
976 && v9 < v6 + pFace->pBoundingBox.z2
977 && ((v10 = (pFace->pFacePlane.dist
978 + pLight->vPosition.x * pFace->pFacePlane.vNormal.x
979 + v8 * pFace->pFacePlane.vNormal.y
980 + v9 * pFace->pFacePlane.vNormal.z) >> 16,
981 a4)
982 || v10 >= 0)
983 && v10 <= v6 )
984 {
985 stru_F8AD28._blv_lights_radii[*pSlot] = v6;
986 stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / v6;
987 stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x;
988 stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y;
989 stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z;
990 stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689;
991 stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689;
992 stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689;
993 v11 = abs(v10);
994 v12 = pRenderer->bUsingSpecular;
995 stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = v11;
996 stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType;
997 v13 = pRenderer->pRenderD3D;
998 v14 = stru_F8AD28._blv_lights_types[*pSlot];
999 if ( pRenderer->pRenderD3D && v12 && v14 & 4 )
1000 v14 = _4E94D2_light_type;
1001 stru_F8AD28._blv_lights_types[*pSlot] = v14;
1002 result = 4 * *pSlot;
1003 if ( v13 && v12 )
1004 {
1005 if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 )
1006 {
1007 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result)
1008 * 0.33000001;
1009 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result)
1010 * 0.33000001;
1011 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result)
1012 * 0.33000001;
1013 }
1014 }
1015 ++*pSlot;
1016 LOBYTE(result) = 1;
1017 }
1018 else
1019 {
1020 LOBYTE(result) = 0;
1021 }
1022 return result;
1023 }
1024 // 4E94D2: using guessed type char _4E94D2_light_type;
1025
1026 //----- (0045D036) --------------------------------------------------------
1027 bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, bool bLightBackfaces)
1028 {
1029 int v6; // esi@1
1030 //LightmapBuilder *v7; // edi@1
1031 MobileLight *v8; // ebx@2
1032 int v9; // esi@5
1033 StationaryLight *v10; // ebx@6
1034 //bool result; // eax@9
1035 unsigned int a7; // [sp+Ch] [bp-4h]@1
1036
1037 v6 = 0;
1038 //v7 = this;
1039 a7 = 0;
1040 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type;
1041 if ( pMobileLightsStack->uNumLightsActive > 0 )
1042 {
1043 v8 = pMobileLightsStack->pLights;
1044 do
1045 {
1046 if ( (signed int)a7 >= 20 )
1047 break;
1048 StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
1049 ++v6;
1050 ++v8;
1051 }
1052 while ( v6 < pMobileLightsStack->uNumLightsActive );
1053 }
1054 v9 = 0;
1055 if ( pStationaryLightsStack->uNumLightsActive > 0 )
1056 {
1057 v10 = pStationaryLightsStack->pLights;
1058 do
1059 {
1060 if ( (signed int)a7 >= 20 )
1061 break;
1062 StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
1063 ++v9;
1064 ++v10;
1065 }
1066 while ( v9 < pStationaryLightsStack->uNumLightsActive );
1067 }
1068
1069 stru_F8AD28.uNumLightsApplied = a7;
1070 return true;
1071 }
1072 // 519AB4: using guessed type int uNumStationaryLightsApplied;
1073
1074 //----- (0045D0D5) --------------------------------------------------------
1075 bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X, unsigned int *pSlot)
1076 {
1077 StationaryLight *v8; // edi@1
1078 bool result; // eax@1
1079 unsigned int v10; // esi@2
1080 RenderVertexSoft *v11; // ebx@2
1081 float v12; // eax@3
1082 float v13; // eax@4
1083 double v14; // st7@11
1084 double maxz; // st7@11
1085 double v16; // st7@11
1086 double v17; // st6@11
1087 __int16 v18; // fps@11
1088 char v19; // c0@11
1089 char v20; // c2@11
1090 char v21; // c3@11
1091 double v22; // st6@12
1092 __int16 v23; // fps@12
1093 char v24; // c0@12
1094 char v25; // c2@12
1095 char v26; // c3@12
1096 double v27; // st7@13
1097 double v28; // st6@13
1098 __int16 v29; // fps@13
1099 char v30; // c0@13
1100 char v31; // c2@13
1101 char v32; // c3@13
1102 double v33; // st6@14
1103 __int16 v34; // fps@14
1104 char v35; // c0@14
1105 char v36; // c2@14
1106 char v37; // c3@14
1107 double v38; // st7@15
1108 double v39; // st6@15
1109 __int16 v40; // fps@15
1110 char v41; // c0@15
1111 char v42; // c2@15
1112 char v43; // c3@15
1113 double v44; // st6@16
1114 __int16 v45; // fps@16
1115 char v46; // c0@16
1116 char v47; // c2@16
1117 char v48; // c3@16
1118 Vec3_float_ *v49; // esi@17
1119 double v50; // st7@17
1120 double v51; // st6@17
1121 signed int v52; // ecx@17
1122 unsigned int *v53; // esi@18
1123 int v54; // eax@18
1124 unsigned int v55; // ebx@18
1125 RenderD3D *v56; // ecx@18
1126 char v57; // dl@18
1127 std::string v58; // [sp-18h] [bp-38h]@10
1128 const char *v59; // [sp-8h] [bp-28h]@10
1129 signed int v60; // [sp-4h] [bp-24h]@10
1130 double v61; // [sp+Ch] [bp-14h]@11
1131 float minz; // [sp+14h] [bp-Ch]@11
1132 int v63; // [sp+18h] [bp-8h]@1
1133 float v64; // [sp+1Ch] [bp-4h]@5
1134
1135 v8 = pLight;
1136 result = pLight->uRadius;
1137 v63 = pLight->uRadius;
1138 if ( result <= 0 )
1139 goto LABEL_27;
1140 v10 = uStripType;
1141 v11 = a1;
1142 if ( uStripType == 4 )
1143 {
1144 pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x);
1145 v12 = a1[3].vWorldPosition.x;
1146 }
1147 else
1148 {
1149 if ( uStripType != 3 )
1150 {
1151 MessageBoxW(nullptr, L"Uknown strip type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:981", 0);
1152 goto LABEL_11;
1153 }
1154 if ( (unsigned char)X )
1155 {
1156 pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x);
1157 uStripType = LODWORD(a1[2].vWorldPosition.x);
1158 a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y);
1159 v13 = v11[2].vWorldPosition.y;
1160 goto LABEL_5;
1161 }
1162 pLight = (StationaryLight *)LODWORD(a1[1].vWorldPosition.x);
1163 v12 = a1[2].vWorldPosition.x;
1164 }
1165 uStripType = LODWORD(v12);
1166 a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y);
1167 v13 = v11->vWorldPosition.y;
1168 LABEL_5:
1169 v64 = v13;
1170 LABEL_11:
1171 v60 = v10;
1172 v59 = (const char *)v11;
1173 v14 = pGame->pIndoorCameraD3D->GetPolygonMinZ(v11, v10);
1174 v60 = v10;
1175 minz = v14;
1176 maxz = pGame->pIndoorCameraD3D->GetPolygonMaxZ(v11, v10);
1177 result = v8->vPosition.x;
1178 *((float *)&v61 + 1) = maxz;
1179 v16 = (double)result;
1180 *(float *)&X = (double)v63;
1181 v17 = *(float *)&pLight - *(float *)&X;
1182 //UNDEF(v18);
1183 v19 = v16 < v17;
1184 v20 = 0;
1185 v21 = v16 == v17;
1186 BYTE1(result) = HIBYTE(v18);
1187 if ( v16 <= v17
1188 || (v22 = *(float *)&X + *(float *)&uStripType,
1189 //UNDEF(v23),
1190 v24 = v16 < v22,
1191 v25 = 0,
1192 v26 = v16 == v22,
1193 BYTE1(result) = HIBYTE(v23),
1194 v16 >= v22)
1195 || (result = v8->vPosition.y,
1196 pLight = (StationaryLight *)v8->vPosition.y,
1197 v27 = (double)(signed int)pLight,
1198 v28 = *(float *)&a1 - *(float *)&X,
1199 //UNDEF(v29),
1200 v30 = v27 < v28,
1201 v31 = 0,
1202 v32 = v27 == v28,
1203 BYTE1(result) = HIBYTE(v29),
1204 v27 <= v28)
1205 || (v33 = *(float *)&X + v64,
1206 //UNDEF(v34),
1207 v35 = v27 < v33,
1208 v36 = 0,
1209 v37 = v27 == v33,
1210 BYTE1(result) = HIBYTE(v34),
1211 v27 >= v33)
1212 || (result = v8->vPosition.z,
1213 pLight = (StationaryLight *)v8->vPosition.z,
1214 v38 = (double)(signed int)pLight,
1215 v39 = minz - *(float *)&X,
1216 //UNDEF(v40),
1217 v41 = v38 < v39,
1218 v42 = 0,
1219 v43 = v38 == v39,
1220 BYTE1(result) = HIBYTE(v40),
1221 v38 <= v39)
1222 || (v44 = *(float *)&X + *((float *)&v61 + 1),
1223 //UNDEF(v45),
1224 v46 = v38 < v44,
1225 v47 = 0,
1226 v48 = v38 == v44,
1227 BYTE1(result) = HIBYTE(v45),
1228 v38 >= v44)
1229 || (v49 = pNormal,
1230 Vec3_float_::NegDot(&v11->vWorldPosition, pNormal, a3),
1231 X = v8->vPosition.y,
1232 v50 = (double)X * v49->y,
1233 X = v8->vPosition.z,
1234 v51 = (double)X * v49->z,
1235 X = v8->vPosition.x,
1236 *(float *)&a3 = v50 + v51 + (double)X * v49->x + *a3,
1237 v61 = *(float *)&a3 + 6.7553994e15,
1238 result = LODWORD(v61),
1239 X = LODWORD(v61),
1240 v52 = v63,
1241 SLODWORD(v61) > v63) )
1242 {
1243 LABEL_27:
1244 LOBYTE(result) = 0;
1245 return result;
1246 }
1247 v53 = pSlot;
1248 v60 = X;
1249 stru_F8AD28._blv_lights_radii[*pSlot] = v63;
1250 stru_F8AD28._blv_lights_inv_radii[*v53] = 65536 / v52;
1251 stru_F8AD28._blv_lights_xs[*v53] = v8->vPosition.x;
1252 stru_F8AD28._blv_lights_ys[*v53] = v8->vPosition.y;
1253 stru_F8AD28._blv_lights_zs[*v53] = v8->vPosition.z;
1254 a3 = (float *)v8->uLightColorR;
1255 stru_F8AD28._blv_lights_rs[*v53] = (double)(signed int)a3 * 0.0039215689;
1256 a3 = (float *)v8->uLightColorG;
1257 stru_F8AD28._blv_lights_gs[*v53] = (double)(signed int)a3 * 0.0039215689;
1258 a3 = (float *)v8->uLightColorB;
1259 stru_F8AD28._blv_lights_bs[*v53] = (double)(signed int)a3 * 0.0039215689;
1260 v54 = abs(v60);
1261 v55 = pRenderer->bUsingSpecular;
1262 stru_F8AD28._blv_lights_light_dot_faces[*v53] = v54;
1263 stru_F8AD28._blv_lights_types[*v53] = v8->uLightType;
1264 v56 = pRenderer->pRenderD3D;
1265 v57 = stru_F8AD28._blv_lights_types[*v53];
1266 if ( pRenderer->pRenderD3D && v55 && v57 & 4 )
1267 v57 = _4E94D2_light_type;
1268 stru_F8AD28._blv_lights_types[*v53] = v57;
1269 result = 4 * *v53;
1270 if ( v56 && v55 )
1271 {
1272 if ( stru_F8AD28._blv_lights_types[*v53] & 4 )
1273 {
1274 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result)
1275 * 0.33000001;
1276 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result)
1277 * 0.33000001;
1278 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result)
1279 * 0.33000001;
1280 }
1281 }
1282 ++*v53;
1283 LOBYTE(result) = 1;
1284 return result;
1285 }
1286 // 4E94D2: using guessed type char _4E94D2_light_type;
1287
1288 //----- (0045D3C7) --------------------------------------------------------
1289 bool LightmapBuilder::_45D3C7(stru148 *a1)
1290 {
1291 LightmapBuilder *v2; // ebx@1
1292 stru148 *result; // eax@1
1293 float v4; // ecx@2
1294 Span *i; // edi@5
1295
1296 v2 = this;
1297 result = (stru148 *)a1->prolly_head;
1298 if ( result && (v4 = result->field_4, *(int *)&v4) != 0 && *(unsigned int *)(LODWORD(v4) + 60) )
1299 {
1300 for ( i = a1->prolly_head; ; i = i->pNext )
1301 {
1302 result = i->pParent;
1303 if ( result->field_108 )
1304 result = (stru148 *)_45D426(
1305 i,
1306 a1->pEdgeList1,
1307 a1->uEdgeList1Size,
1308 (Edge *)a1->pEdgeList2,
1309 a1->uEdgeList2Size);
1310 if ( a1->prolly_tail == i )
1311 break;
1312 }
1313 LOBYTE(result) = 1;
1314 }
1315 else
1316 {
1317 LOBYTE(result) = 0;
1318 }
1319 return (bool)result;
1320 }
1321
1322 //----- (0045D426) --------------------------------------------------------
1323 int LightmapBuilder::_45D426(Span *a1, Edge **a2, unsigned int a3, Edge *a4, int a5)
1324 {
1325 int v6; // edi@1
1326 signed int v7; // ebx@3
1327 signed int v8; // ecx@3
1328 Span *v9; // esi@3
1329 double v10; // st7@4
1330 Edge *v11; // edx@5
1331 double v12; // st7@11
1332 int v13; // edx@12
1333 int v14; // ebx@17
1334 Edge *v15; // edi@17
1335 float v16; // ST04_4@17
1336 float v17; // ST04_4@17
1337 double v18; // st7@17
1338 int result; // eax@19
1339 //double v20; // ST14_8@20
1340 //double v21; // ST14_8@20
1341 double v22; // st7@20
1342 int v23; // ecx@20
1343 double v24; // st6@20
1344 double v25; // st7@23
1345 double v26; // st7@28
1346 __int16 v27; // fps@28
1347 char v28; // c0@28
1348 char v29; // c2@28
1349 char v30; // c3@28
1350 double v31; // st7@29
1351 double v32; // st7@30
1352 __int16 v33; // fps@30
1353 char v34; // c0@30
1354 char v35; // c2@30
1355 char v36; // c3@30
1356 LightmapBuilder *this_4; // [sp+14h] [bp-8h]@1
1357 signed int v38; // [sp+18h] [bp-4h]@3
1358 float a1a; // [sp+24h] [bp+8h]@20
1359 float a2a; // [sp+28h] [bp+Ch]@17
1360 float a3a; // [sp+2Ch] [bp+10h]@17
1361 float a5a; // [sp+34h] [bp+18h]@20
1362 float a5b; // [sp+34h] [bp+18h]@20
1363
1364 v6 = 0;
1365 this_4 = this;
1366 if ( a5 && a3 )
1367 {
1368 v7 = -1;
1369 v8 = 0;
1370 v9 = a1;
1371 v38 = -1;
1372 if ( (signed int)a3 > 0 )
1373 {
1374 v10 = (double)a1->field_A;
1375 while ( 1 )
1376 {
1377 v11 = a2[v8];
1378 if ( v10 >= v11->field_2C )
1379 {
1380 if ( v10 <= v11->field_30 )
1381 break;
1382 }
1383 ++v8;
1384 if ( v8 >= (signed int)a3 )
1385 goto LABEL_10;
1386 }
1387 v38 = v8;
1388 }
1389 LABEL_10:
1390 if ( a5 > 0 )
1391 {
1392 v12 = (double)a1->field_A;
1393 while ( 1 )
1394 {
1395 v13 = *((unsigned int *)&a4->field_0 + v6);
1396 if ( v12 >= *(float *)(v13 + 44) )
1397 {
1398 if ( v12 <= *(float *)(v13 + 48) )
1399 break;
1400 }
1401 ++v6;
1402 if ( v6 >= a5 )
1403 goto LABEL_17;
1404 }
1405 v7 = v6;
1406 }
1407 LABEL_17:
1408 v14 = *((unsigned int *)&a4->field_0 + v7);
1409 v15 = a2[v38];
1410 v16 = (double)a1->field_A;
1411 a3a = _45D643(a2[v38], v16);
1412 v17 = (double)a1->field_A;
1413 v18 = _45D643((Edge *)v14, v17);
1414 a2a = v18;
1415 if ( byte_4D864C && BYTE1(pGame->uFlags) & 0x80 )
1416 {
1417 HIWORD(result) = HIWORD(a3a);
1418 a1->field_14 = v18;
1419 a1->field_10 = a3a;
1420 }
1421 else
1422 {
1423 a5a = ((double)a1->field_A - v15->field_2C) * v15->field_4 + v15->field_24 - 0.5;
1424 //v20 = a5a + 6.7553994e15;
1425 //a5b = (double)SLODWORD(v20);
1426 a5b = (double)floorf(a5a + 0.5f);
1427 a1a = ((double)a1->field_A - *(float *)(v14 + 44)) * *(float *)(v14 + 4) + *(float *)(v14 + 36) + 0.5;
1428 //v21 = a1a + 6.7553994e15;
1429 //v22 = (double)SLODWORD(v21);
1430 v22 = (double)floorf(a1a + 0.5f);
1431 result = v9->field_8;
1432 v23 = v9->field_C;
1433 v24 = -((a3a - a2a) / (v22 - a5b));
1434 v9->field_10 = ((double)result - a5b) * v24 + a3a;
1435 v9->field_14 = a2a - (v22 - (double)(result + v23)) * v24;
1436 }
1437 if ( v9->field_10 < 0.0 || v9->field_10 <= 1.0 )
1438 {
1439 if ( v9->field_10 >= 0.0 )
1440 v25 = v9->field_10;
1441 else
1442 v25 = 0.0;
1443 }
1444 else
1445 {
1446 v25 = 1.0;
1447 }
1448 v9->field_10 = v25;
1449 if ( v9->field_14 < 0.0
1450 || (v26 = v9->field_14,
1451 //UNDEF(v27),
1452 v28 = 1.0 < v26,
1453 v29 = 0,
1454 v30 = 1.0 == v26,
1455 BYTE1(result) = HIBYTE(v27),
1456 v26 <= 1.0) )
1457 {
1458 v32 = v9->field_14;
1459 //UNDEF(v33);
1460 v34 = 0.0 < v32;
1461 v35 = 0;
1462 v36 = 0.0 == v32;
1463 BYTE1(result) = HIBYTE(v33);
1464 if ( v32 >= 0.0 )
1465 v31 = v9->field_14;
1466 else
1467 v31 = 0.0;
1468 }
1469 else
1470 {
1471 v31 = 1.0;
1472 }
1473 v9->field_14 = v31;
1474 LOBYTE(result) = 1;
1475 }
1476 else
1477 {
1478 LOBYTE(result) = 0;
1479 }
1480 return result;
1481 }
1482 // 4D864C: using guessed type char byte_4D864C;
1483
1484 //----- (0045D643) --------------------------------------------------------
1485 double LightmapBuilder::_45D643(Edge *a1, float a2)
1486 {
1487 double result; // st7@1
1488
1489 result = (a1->field_1C - a1->field_20) * -1.0 / (a1->field_30 - a1->field_2C) * (a2 - a1->field_2C) + a1->field_1C;
1490 if ( result < 0.0 || result <= 1.0 )
1491 {
1492 if ( result < 0.0 )
1493 result = 0.0;
1494 }
1495 else
1496 {
1497 result = 1.0;
1498 }
1499 return result;
1500 }
1501
1502 //----- (0045D698) --------------------------------------------------------
1503 bool LightmapBuilder::DrawDebugOutlines(char bit_one_for_list1__bit_two_for_list2)
1504 {
1505 bool result; // eax@1
1506 LightmapBuilder *v3; // esi@1
1507 RenderVertexSoft *v4; // edi@3
1508 RenderVertexSoft *v5; // edi@7
1509 IndoorCameraD3D *thisa; // [sp+10h] [bp-8h]@1
1510 bool v7; // [sp+14h] [bp-4h]@2
1511 bool a2a; // [sp+20h] [bp+8h]@6
1512
1513 result = (bool)pGame->pIndoorCameraD3D;
1514 v3 = this;
1515 thisa = pGame->pIndoorCameraD3D;
1516 if ( bit_one_for_list1__bit_two_for_list2 & 1 )
1517 {
1518 v7 = 0;
1519 if ( (signed int)this->std__vector_000004_size > 0 )
1520 {
1521 v4 = this->std__vector_000004[0].pVertices;
1522 do
1523 {
1524 pGame->pIndoorCameraD3D->debug_outline_sw(v4, *((unsigned int *)v4 - 1), 0xFF00u, 0.0);
1525 ++v7;
1526 v4 = (RenderVertexSoft *)((char *)v4 + 3100);
1527 result = v7;
1528 }
1529 while ( v7 < (signed int)v3->std__vector_000004_size );
1530 }
1531 }
1532 if ( bit_one_for_list1__bit_two_for_list2 & 2 )
1533 {
1534 a2a = 0;
1535 if ( (signed int)v3->std__vector_183808_size > 0 )
1536 {
1537 v5 = v3->std__vector_183808[0].pVertices;
1538 do
1539 {
1540 pGame->pIndoorCameraD3D->debug_outline_sw(v5, *((unsigned int *)v5 - 1), 0xC04000u, 0.00019999999);
1541 ++a2a;
1542 v5 = (RenderVertexSoft *)((char *)v5 + 3100);
1543 result = a2a;
1544 }
1545 while ( a2a < (signed int)v3->std__vector_183808_size );
1546 }
1547 }
1548 LOBYTE(result) = 1;
1549 return result;
1550 }
1551
1552 //----- (0045D73F) --------------------------------------------------------
1553 void LightmapBuilder::DrawLightmaps(int a2)
1554 {
1555 if ( a2 == 2 )
1556 DoDrawLightmaps();
1557 }
1558
1559 //----- (0045D74F) --------------------------------------------------------
1560 char LightmapBuilder::_45D74F_MessWithLight(int a2, int *a3)
1561 {
1562 char v3; // zf@1
1563 IDirect3DDevice3 *v4; // eax@2
1564 HRESULT v5; // eax@2
1565 //char *v6; // eax@2
1566 struct IDirect3DTexture2 *v7; // edi@4
1567 HRESULT v8; // eax@8
1568 HRESULT v9; // eax@8
1569 HRESULT v10; // eax@8
1570 HRESULT v11; // eax@8
1571 HRESULT v12; // eax@8
1572 int *v13; // eax@8
1573 float v14; // ecx@15
1574 IDirect3DDevice3 *v15; // eax@21
1575 HRESULT v16; // eax@21
1576 IDirect3DDevice3 *v17; // eax@21
1577 HRESULT v18; // eax@21
1578 IDirect3DDevice3 *v19; // eax@21
1579 HRESULT v20; // eax@21
1580 IDirect3DDevice3 *v21; // eax@21
1581 HRESULT v22; // eax@21
1582 //IDirect3DDevice3 *v23; // eax@23
1583 std::string v25; // [sp+44h] [bp-44h]@12
1584 signed int v26; // [sp+48h] [bp-40h]@21
1585 signed int v27; // [sp+4Ch] [bp-3Ch]@21
1586 Lightmap *v28; // [sp+50h] [bp-38h]@2
1587 int v29; // [sp+54h] [bp-34h]@2
1588 //float v30; // [sp+58h] [bp-30h]@2
1589 int arg4; // [sp+68h] [bp-20h]@8
1590 float v32; // [sp+6Ch] [bp-1Ch]@8
1591 float v33; // [sp+70h] [bp-18h]@8
1592 int v34; // [sp+74h] [bp-14h]@19
1593 int v35; // [sp+78h] [bp-10h]@2
1594 int *v36; // [sp+7Ch] [bp-Ch]@10
1595 int a1; // [sp+80h] [bp-8h]@12
1596 float v38; // [sp+84h] [bp-4h]@1
1597
1598 v3 = this->std__vector_000004_size == 0;
1599 LODWORD(v38) = (int)this;
1600 if ( !v3 )
1601 {
1602 //v30 = 0.0;
1603 //v4 = pRenderer->pRenderD3D->pDevice;
1604 ErrD3D(v4->SetTextureStageState(0, D3DTSS_ADDRESS, 3u));
1605 //v6 = (char *)stru_69BD44.c_str();
1606 //if ( !stru_69BD44.c_str() )
1607 // v6 = (char *)&dword_4D86F0;
1608 v7 = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03");
1609 if ( pRenderer->bUsingSpecular )
1610 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0);
1611 if ( !byte_4D864C || !(pGame->uFlags & 1) )
1612 {
1613 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
1614 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
1615 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v7));
1616 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
1617 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
1618 v13 = a3;
1619 v33 = 1.0;
1620 v32 = 1.0;
1621 *(float *)&arg4 = 1.0;
1622 if ( a3 )
1623 {
1624 if ( *a3 != -1 )
1625 {
1626 v36 = a3;
1627 do
1628 {
1629 v28 = (Lightmap *)(3100 * *v13 + LODWORD(v38) + 4);
1630 if ( !DrawLightmap(v28, (Vec3_float_ *)&arg4, 0.0) )
1631 {
1632 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1230", 0);
1633 a1 = 5080812;
1634 }
1635 v13 = v36 + 1;
1636 v36 = v13;
1637 }
1638 while ( *v13 != -1 );
1639 }
1640 }
1641 else
1642 {
1643 v14 = v38;
1644 v36 = 0;
1645 if ( *(unsigned int *)(LODWORD(v38) + 1587204) > 0 )
1646 {
1647 a1 = LODWORD(v38) + 4;
1648 while ( 1 )
1649 {
1650 if ( !DrawLightmap((Lightmap *)a1, (Vec3_float_ *)&arg4, 0.0) )
1651 {
1652 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1238", 0);
1653 v35 = 5080812;
1654 }
1655 v36 = (int *)((char *)v36 + 1);
1656 a1 += 3100;
1657 if ( (signed int)v36 >= *(unsigned int *)(LODWORD(v38) + 1587204) )
1658 break;
1659 v14 = v38;
1660 }
1661 }
1662 }
1663 v15 = pRenderer->pRenderD3D->pDevice;
1664 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
1665 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
1666 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
1667 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
1668 }
1669 if ( pRenderer->bUsingSpecular )
1670 {
1671 //LODWORD(v30) = 1;
1672 //v29 = 28;
1673 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice;
1674 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1));
1675 //v30 = pRenderer->uFogColor;
1676 //v23 = pRenderer->pRenderD3D->pDevice;
1677 //v29 = 34;
1678 //v28 = (Lightmap *)v23;
1679 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, pRenderer->uFogColor));
1680 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice;
1681 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, false));
1682 }
1683 }
1684 return 1;
1685 }
1686
1687
1688 //----- (0045DA56) --------------------------------------------------------
1689 bool LightmapBuilder::DrawLightmaps2(float z_bias)
1690 {
1691 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2
1692 v.z = 1.0;
1693 v.y = 1.0;
1694 v.x = 1.0;
1695
1696 for (uint i = 0; i < std__vector_183808_size; ++i)
1697 if (!DrawLightmap(std__vector_183808 + i, &v, z_bias))
1698 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1288", 0);
1699
1700 return true;
1701 }
1702
1703 //----- (0045DAE8) --------------------------------------------------------
1704 bool LightmapBuilder::DrawLightmap(Lightmap *pLightmap, Vec3_float_ *pColorMult, float z_bias)
1705 {
1706 double v10; // st7@4
1707 double v14; // st7@7
1708 __int16 v15; // fps@8
1709 double v18; // st3@8
1710 signed int v24; // [sp-1Ch] [bp-670h]@13
1711 const char *v25; // [sp-18h] [bp-66Ch]@13
1712 int v26; // [sp-14h] [bp-668h]@13
1713 RenderVertexD3D3 a2[32]; // [sp+0h] [bp-654h]@7
1714
1715
1716 if (pLightmap->uNumVertices < 3)
1717 {
1718 Log::Warning(L"Lightmap uNumVertices < 3");
1719 return false;
1720 }
1721
1722 uint uLightmapColorMaskR = (pLightmap->uColorMask >> 16) & 0xFF;
1723 uint uLightmapColorR = floorf(uLightmapColorMaskR * pLightmap->fBrightness * pColorMult->x + 0.5f);
1724
1725 uint uLightmapColorMaskG = (pLightmap->uColorMask >> 8) & 0xFF;
1726 uint uLightmapColorG = floorf(uLightmapColorMaskG * pLightmap->fBrightness * pColorMult->y + 0.5f);
1727
1728 uint uLightmapColorMaskB = pLightmap->uColorMask & 0xFF;
1729 uint uLightmapColorB = floorf(uLightmapColorMaskB * pLightmap->fBrightness * pColorMult->z + 0.5f);
1730
1731 uint uLightmapColor = uLightmapColorB | (uLightmapColorMaskG << 8) | (uLightmapColorMaskR << 16);
1732
1733 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
1734 v10 = (double)pOutdoorCamera->shading_dist_mist;
1735 else
1736 v10 = 16192.0;
1737 v14 = 1.0 / v10;
1738
1739 for (uint i = 0; i < pLightmap->uNumVertices; ++i)
1740 {
1741 v18 = 1.0 - 1.0 / (v14 * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0);
1742 if (fabsf(z_bias) < 1e-5f)
1743 {
1744 v18 = v18 - z_bias;
1745 if (v18 < 0.000099999997)
1746 v18 = 0.000099999997;
1747 }
1748
1749 a2[i].pos.x = pLightmap->pVertices[i].vWorldViewProjX;
1750 a2[i].pos.z = v18;
1751 a2[i].pos.y = pLightmap->pVertices[i].vWorldViewProjY;
1752 a2[i].rhw = 1.0 / pLightmap->pVertices[i].vWorldViewPosition.x;
1753 a2[i].diffuse = uLightmapColor;
1754 a2[i].specular = 0;
1755 a2[i].texcoord.x = pLightmap->pVertices[i].u;
1756 a2[i].texcoord.y = pLightmap->pVertices[i].v;
1757 }
1758
1759 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
1760 v24 = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS;
1761 else
1762 v24 = D3DDP_DONOTLIGHT;
1763
1764 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
1765 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
1766 a2,
1767 pLightmap->uNumVertices,
1768 v24));
1769
1770 return true;
1771 }
1772
1773 //----- (0045DCA9) --------------------------------------------------------
1774 void LightmapBuilder::DoDrawLightmaps()
1775 {
1776 if (!std__vector_183808_size)
1777 return;
1778
1779 if (pRenderer->bUsingSpecular)
1780 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
1781
1782 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1));
1783 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
1784 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
1785 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
1786
1787 auto pTex = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03");
1788 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex));
1789
1790 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
1791 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
1792
1793 DrawLightmaps2(0.00050000002);
1794
1795 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
1796 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
1797 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
1798 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
1799 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
1800 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2));
1801
1802 if (pRenderer->bUsingSpecular)
1803 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u));
1804 }