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