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