diff Render.cpp @ 638:ccf8b4815a1f

GetActorTintColor fixed Outdoor sunlight works on terrain & bmodels (not sure about billboards though)
author Nomad
date Mon, 11 Mar 2013 21:43:26 +0200
parents d7b14091e434
children 4f2837124c69
line wrap: on
line diff
--- a/Render.cpp	Mon Mar 11 17:07:51 2013 +0200
+++ b/Render.cpp	Mon Mar 11 21:43:26 2013 +0200
@@ -338,13 +338,13 @@
               v14 = *(int *)&v4->flags;
               if ( v14 & 0x10 && v4->field_59 != 5 )
               {
-                dword_80AA20 = (v4->field_5C - 64) << 25;
+                dword_80AA20 = (v4->terrain_grid_z - 64) << 25;
                 dword_80AA1C = dword_80AA20 + 0x1FF0000;
-                dword_80AA14 = (v4->field_5D << 25) + 0x7FFF0000;
+                dword_80AA14 = (v4->terrain_grid_x << 25) + 0x7FFF0000;
                 dword_80AA18 = dword_80AA14 - 0x1FF0000;
                 byte_80AA10 = ((unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(
-                                               v4->field_5C,
-                                               v4->field_5D - 1) >> 9) & 1;
+                                               v4->terrain_grid_z,
+                                               v4->terrain_grid_x - 1) >> 9) & 1;
                 if ( *(int *)&v4->flags & 2 || (v15 = *(int *)&v4->flags, BYTE1(v15) & 1) )
                 {
                   if ( *(int *)&v4->flags & 2 )
@@ -372,15 +372,15 @@
                         sr_sub_48408A_prolly_odm_water_no_waves(v3);
                       else
                         sr_sub_485407_prolly_odm_water_wavy(v3);
-                      v18 = v4->field_5C - 64;
+                      v18 = v4->terrain_grid_z - 64;
                       v4->pTexture = v16;
                       dword_80AA20 = v18 << 25;
                       dword_80AA1C = (v18 << 25) + 0x1FF0000;
-                      dword_80AA14 = (v4->field_5D << 25) + 0x7FFF0000;
+                      dword_80AA14 = (v4->terrain_grid_x << 25) + 0x7FFF0000;
                       dword_80AA18 = dword_80AA14 - 0x1FF0000;
                       byte_80AA10 = ((unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(
-                                                     v4->field_5C,
-                                                     v4->field_5D - 1) >> 9) & 1;
+                                                     v4->terrain_grid_z,
+                                                     v4->terrain_grid_x - 1) >> 9) & 1;
                       sr_sub_484442(v3);
                       v3->field_E = LOWORD(unnamed_6BE060[1]);
                       if ( v4->prolly_tail == v3 )
@@ -427,13 +427,13 @@
                   {
                     if ( v19 == 1 )
                     {
-                      dword_80AA20 = (v4->field_5C - 64) << 25;
+                      dword_80AA20 = (v4->terrain_grid_z - 64) << 25;
                       dword_80AA1C = dword_80AA20 + 33488896;
-                      dword_80AA14 = (v4->field_5D << 25) + 0x7FFF0000;
+                      dword_80AA14 = (v4->terrain_grid_x << 25) + 0x7FFF0000;
                       dword_80AA18 = dword_80AA14 - 33488896;
                       byte_80AA10 = ((unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(
-                                                     v4->field_5C,
-                                                     v4->field_5D - 1) >> 9) & 1;
+                                                     v4->terrain_grid_z,
+                                                     v4->terrain_grid_x - 1) >> 9) & 1;
                       while ( 1 )
                       {
                         if ( !sr_sub_4847EB(v3) )
@@ -606,9 +606,9 @@
         v2 = (stru148 *)&pBitmaps_LOD->pTextures[pOutdoor->uMainTile_BitmapID],
         (array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uMainTile_BitmapID != -1 ? (int)v2 : 0)) == 0) )
     return (signed __int16)v2;
-  array_77EC08[1999].field_58 = 23 - (-20 * pOutdoor->vSunlight.z >> 16);
-  if ( array_77EC08[1999].field_58 > 20 )
-    array_77EC08[1999].field_58 = 20;
+  array_77EC08[1999].dimming_level = 23 - (-20 * pOutdoor->vSunlight.z >> 16);
+  if ( array_77EC08[1999].dimming_level > 20 )
+    array_77EC08[1999].dimming_level = 20;
   v10 = stru_5C6E00->Sin(pIndoorCamera->sRotationX);
   array_77EC08[1999].v_18.y = 0;
   array_77EC08[1999].v_18.x = v10;
@@ -625,7 +625,7 @@
   array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0);
   if ( !(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0) )
     return (signed __int16)v2;
-  array_77EC08[1999].field_58 = 0;
+  array_77EC08[1999].dimming_level = 0;
   v11 = stru_5C6E00->Sin(pIndoorCamera->sRotationX + 16);
   array_77EC08[1999].v_18.y = 0;
   array_77EC08[1999].v_18.x = -v11;
@@ -1822,7 +1822,17 @@
       v8->pODMFace = nullptr;
       v8->uNumVertices = 4;
       v8->field_59 = 5;
-      v8->field_58 = 0;
+
+
+      uint norm_idx = pTerrainNormalIndices[2 * (x + 128 * z) + 1];
+      assert(norm_idx < uNumTerrainNormals);
+
+      auto norm = pTerrainNormals + norm_idx;
+      float _f = (norm->x * (float)pOutdoor->vSunlight.x / 65536.0 -
+                  norm->y * (float)pOutdoor->vSunlight.y / 65536.0 -
+                  norm->z * (float)pOutdoor->vSunlight.z / 65536.0);
+      v8->dimming_level = 20.0 - floorf(20.0 * _f + 0.5f);
+
       ++pOutdoorCamera->numStru148s;
       ++pOutdoorCamera->field_44;
       assert(pOutdoorCamera->numStru148s < 20000);
@@ -2000,7 +2010,7 @@
   v4 = 0;
   v88 = 0;
   v84 = v3 - 1;
-  v90 = (float)pOutdoor->vSunlight.x / 65536,0;
+  v90 = (float)pOutdoor->vSunlight.x / 65536.0;
   v91 = (float)pOutdoor->vSunlight.y / 65536.0;
   v92 = (float)pOutdoor->vSunlight.z / 65536.0;
   if ( v3 - 1 > 0 )
@@ -2067,22 +2077,22 @@
           v16->field_32 = 0;
           v20 = v93;
           v16->field_59 = 1;
-          v16->field_5D = (char)v19;
+          v16->terrain_grid_x = (char)v19;
           v16->field_34 = *(_WORD *)(v20 + 2);
           v21 = v89;
-          v16->field_5C = v89;
+          v16->terrain_grid_z = v89;
           v22 = pTerrainNormalIndices[2 * (v19 + 128 * v21) + 1];
           if ( v22 < 0 || v22 > uNumTerrainNormals - 1 )
             v23 = 0;
           else
             v23 = &pTerrainNormals[v22];
-          v24 = v92 * v23->y;
+          v24 = v92 * v23->z;
           //v99 = v23;
-          thisf = 20.0 - (-v24 - v91 * v23->z - v90 * v23->x) * 20.0;
+          thisf = 20.0 - (-v24 - v91 * v23->y - v90 * v23->x) * 20.0;
           //v25 = thisf + 6.7553994e15;
           //v27 = pOutdoorCamera->numStru148s > 1999;
           //v26 = pOutdoorCamera->numStru148s - 1999 < 0;
-          v16->field_58 = floorf(thisf + 0.5f);
+          v16->dimming_level = floorf(thisf + 0.5f);
           if ( pOutdoorCamera->numStru148s >= 1999 )
             return;
           ++pOutdoorCamera->numStru148s;
@@ -2142,7 +2152,7 @@
               v33 = v108 != 0 ? 5 : 0;
             static_sub_0048034E_stru_154._49B0C9(v23, v95);
             if ( pDecalBuilder->uNumDecals > 0 )
-              pDecalBuilder->ApplyDecals(31 - v16->field_58, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1);
+              pDecalBuilder->ApplyDecals(31 - v16->dimming_level, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1);
           }
           if ( stru_F8AD28.uNumLightsApplied > 0 )
             pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33);
@@ -2205,10 +2215,10 @@
       *(int *)&v40->flags = v42;
       v44 = v93;
       v40->field_59 = 1;
-      v40->field_5D = (char)v43;
+      v40->terrain_grid_x = (char)v43;
       v40->field_34 = *(_WORD *)(v44 + 2);
       v45 = v89;
-      v40->field_5C = v89;
+      v40->terrain_grid_z = v89;
       v46 = 4 * ((char)v43 + (v45 << 7));
       v85 = v46;
       v47 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v46 + 2);//    v47 = pTerrainNormalIndices[v46 + 1];
@@ -2220,9 +2230,9 @@
       //v99 = v48;
       thisg = 20.0 - (-v49 - v91 * v48->z - v90 * v48->x) * 20.0;
       v50 = thisg + 6.755399441055744e15;
-      v40->field_58 = LOBYTE(v50);
+      v40->dimming_level = LOBYTE(v50);
       if ( LOBYTE(v50) < 0 )
-        v40->field_58 = 0;
+        v40->dimming_level = 0;
       if ( pOutdoorCamera->numStru148s >= 1999 )
         return;
       ++pOutdoorCamera->numStru148s;
@@ -2287,7 +2297,7 @@
         //a8 = (RenderVertexSoft *)(this_3a ? 3 : v108 != 0 ? 5 : 0);
         static_sub_0048034E_stru_76D590._49B0C9(v48, *(float *)&a4);
         if ( pDecalBuilder->uNumDecals > 0 )
-          pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices, -1);
+          pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 4, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices, -1);
       }
       if ( stru_F8AD28.uNumLightsApplied > 0 )
         v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D590, uNumVertices, array_50AC10, 0, (char)pVertices);
@@ -2339,8 +2349,8 @@
       v61 = v93;
       v59->field_59 = 1;
       v59->field_34 = *(_WORD *)(v61 + 2);
-      v59->field_5C = v89;
-      v59->field_5D = v97;
+      v59->terrain_grid_z = v89;
+      v59->terrain_grid_x = v97;
       v62 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v85);
       if ( v62 > (signed int)(uNumTerrainNormals - 1) )
         v63 = 0;
@@ -2349,9 +2359,9 @@
       v64 = v92 * v63->y;
       //v99 = v63;
       thish = 20.0 - (-v64 - v91 * v63->y - v90 * v63->x) * 20.0;
-      v59->field_58 = floorf(thish + 0.5f);
-      if ( v59->field_58 < 0 )
-        v59->field_58 = 0;
+      v59->dimming_level = floorf(thish + 0.5f);
+      if ( v59->dimming_level < 0 )
+        v59->dimming_level = 0;
       if ( pOutdoorCamera->numStru148s >= 1999 )
         return;
       ++pOutdoorCamera->numStru148s;
@@ -2410,7 +2420,7 @@
           v70 = v108 != 0 ? 5 : 0;
         static_sub_0048034E_stru_76D578._49B0C9(v63, v87);
         if ( pDecalBuilder->uNumDecals > 0 )
-          pDecalBuilder->ApplyDecals(31 - v40->field_58, 4, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70, -1);
+          pDecalBuilder->ApplyDecals(31 - v40->dimming_level, 4, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70, -1);
       }
       if ( stru_F8AD28.uNumLightsApplied > 0 )
         v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70);
@@ -2588,9 +2598,9 @@
   v6 = 0;
   v90 = 0;
   v81 = v3 - 1;
-  v95 = (double)pOutdoor->vSunlight.x * 0.000015258789;
-  v96 = (double)pOutdoor->vSunlight.y * 0.000015258789;
-  v97 = (double)pOutdoor->vSunlight.z * 0.000015258789;
+  v95 = (double)pOutdoor->vSunlight.x / 65536.0;
+  v96 = (double)pOutdoor->vSunlight.y / 65536.0;
+  v97 = (double)pOutdoor->vSunlight.z / 65536.0;
   if ( v3 - 1 > 0 )
   {
     while ( 1 )
@@ -2643,10 +2653,10 @@
         *(int *)&v17->flags = v19;
         v21 = v92;
         v17->field_59 = 1;
-        v17->field_5D = LOBYTE(v20);
+        v17->terrain_grid_x = LOBYTE(v20);
         v17->field_34 = v21->distance;
         v22 = v94;
-        v17->field_5C = v94;
+        v17->terrain_grid_z = v94;
         v23 = pTerrainNormalIndices[2 * (LODWORD(v20) + (v22 << 7)) + 1];
         if ( v23 < 0 || v23 > (signed int)(uNumTerrainNormals - 1) )
           v24 = 0;
@@ -2661,11 +2671,11 @@
           v99 = v25 * 31.0;
           v76 = v99 + 6.7553994e15;
           v84 = LODWORD(v76);
-          v17->field_58 = 31 - LOBYTE(v76);
+          v17->dimming_level = 31 - LOBYTE(v76);
         }
         else
         {
-          v17->field_58 = 0;
+          v17->dimming_level = 0;
         }
         if ( pOutdoorCamera->numStru148s >= 1999 )
           return;
@@ -2760,10 +2770,10 @@
     *(int *)&v38->flags = v40;
     v42 = v92;
     v38->field_59 = 1;
-    v38->field_5D = LOBYTE(v41);
+    v38->terrain_grid_x = LOBYTE(v41);
     v38->field_34 = v42->distance;
     v43 = v94;
-    v38->field_5C = v94;
+    v38->terrain_grid_z = v94;
     v44 = 2 * (LODWORD(v41) + (v43 << 7));
     LODWORD(v93) = v44 * 2;
     v45 = pTerrainNormalIndices[v44 + 1];
@@ -2780,14 +2790,14 @@
       v88 = v47 * 31.0;
       v74 = v88 + 6.7553994e15;
       v87 = LODWORD(v74);
-      v38->field_58 = 31 - LOBYTE(v74);
+      v38->dimming_level = 31 - LOBYTE(v74);
     }
     else
     {
-      v38->field_58 = 0;
-    }
-    if ( v38->field_58 < 0 )
-      v38->field_58 = 0;
+      v38->dimming_level = 0;
+    }
+    if ( v38->dimming_level < 0 )
+      v38->dimming_level = 0;
     if ( pOutdoorCamera->numStru148s >= 1999 )
       return;
     ++pOutdoorCamera->numStru148s;
@@ -2849,8 +2859,8 @@
           v58 = v92;
           v17->field_59 = 1;
           v17->field_34 = v58->distance;
-          v17->field_5C = v94;
-          v17->field_5D = LOBYTE(v99);
+          v17->terrain_grid_z = v94;
+          v17->terrain_grid_x = LOBYTE(v99);
           v59 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + LODWORD(v93));
           if ( v59 > (signed int)(uNumTerrainNormals - 1) )
           {
@@ -2870,14 +2880,14 @@
             v93 = v61 * 31.0;
             v72 = v93 + 6.7553994e15;
             v83 = LODWORD(v72);
-            v17->field_58 = 31 - LOBYTE(v72);
+            v17->dimming_level = 31 - LOBYTE(v72);
           }
           else
           {
-            v17->field_58 = 0;
+            v17->dimming_level = 0;
           }
-          if ( v17->field_58 < 0 )
-            v17->field_58 = 0;
+          if ( v17->dimming_level < 0 )
+            v17->dimming_level = 0;
           if ( pOutdoorCamera->numStru148s >= 1999 )
             return;
           ++pOutdoorCamera->numStru148s;
@@ -4478,7 +4488,7 @@
   unsigned int v55; // [sp+5Ch] [bp-Ch]@34
   unsigned int v56; // [sp+60h] [bp-8h]@12
   int v57; // [sp+60h] [bp-8h]@34
-  HRESULT a2; // [sp+64h] [bp-4h]@4
+  unsigned int a2; // [sp+64h] [bp-4h]@4
 
   v5 = this;
   v6 = 0;
@@ -4488,11 +4498,11 @@
     v53 = v7;
     v54 = v7->std__vector_000004_size;
     if ( v7->std__vector_000004_size)
-      a2 = -1;
-    pGame->_44EE30(a4, (int)&a2);
+      a2 = 0xFFFFFFFF;
+    pGame->AlterGamma_ODM(a4, &a2);
     if ( byte_4D864C && pGame->uFlags & 1 )
     {
-      v8 = GetActorTintColor(a3->field_58, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
+      v8 = ::GetActorTintColor(a3->dimming_level, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
       v7->_45D74F_MessWithLight(v8, 0);
     }
     else
@@ -4514,8 +4524,8 @@
           v55 = uNumVertices;
           do
           {
-            a2 = GetActorTintColor(a3->field_58, 0, *(float *)v45, 0, 0);
-            pGame->_44EE30(a4, (int)&a2);
+            a2 = ::GetActorTintColor(a3->dimming_level, 0, *(float *)v45, 0, 0);
+            pGame->AlterGamma_ODM(a4, &a2);
             v46 = v57;
             v47 = *(float *)v45 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist;
             *(int *)(v57 - 4) = *((int *)v45 + 3);
@@ -4576,7 +4586,7 @@
             v9->pFacePlane.vNormal.x = *((int *)v10 + 4);
             *(float *)&v9->pFacePlane.vNormal.y = 1.0 - 1.0 / v12;
             *(float *)&v9->pFacePlane.vNormal.z = 1.0 / (*(float *)v10 + 0.0000001);
-            v13 = GetActorTintColor(a3->field_58, 0, *(float *)v10, 0, 0);
+            v13 = GetActorTintColor(a3->dimming_level, 0, *(float *)v10, 0, 0);
             v14 = a4;
             v15 = *(float *)v10;
             a4->pFacePlane.dist = v13;
@@ -7305,6 +7315,7 @@
 //----- (004A2031) --------------------------------------------------------
 unsigned int Render::GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6)
 {
+  __debugbreak(); // should not fire outside decal builder
   return ::GetActorTintColor(tint, a4, a2, a5, a6);
 }
 
@@ -7503,7 +7514,7 @@
     v10 = v9->std__vector_000004_size;*/
     if ( byte_4D864C && pGame->uFlags & 1 )
     {
-      v11 = GetActorTintColor(a4->field_58, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
+      v11 = ::GetActorTintColor(a4->dimming_level, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
       pGame->pLightmapBuilder->_45D74F_MessWithLight(v11, 0);
     }
     else
@@ -7546,7 +7557,7 @@
             *(int *)v51 = *((int *)v52 + 4);
             *(float *)(v51 + 4) = 1.0 - 1.0 / v54;
             *(float *)(v51 + 8) = 1.0 / (*(float *)v52 + 0.0000001);
-            v55 = GetActorTintColor(a4->field_58, 0, *(float *)v52, 0, 0);
+            v55 = ::GetActorTintColor(a4->dimming_level, 0, *(float *)v52, 0, 0);
             v56 = a7;
             v57 = *(float *)v52;
             *(int *)(a7 + 12) = v55;
@@ -7596,7 +7607,7 @@
             *(int *)v12 = *((int *)v13 + 4);
             *(float *)(v12 + 4) = 1.0 - 1.0 / v15;
             *(float *)(v12 + 8) = 1.0 / (*(float *)v13 + 0.0000001);
-            v16 = GetActorTintColor(a4->field_58, 0, *(float *)v13, 0, 0);
+            v16 = GetActorTintColor(a4->dimming_level, 0, *(float *)v13, 0, 0);
             v17 = a7;
             v18 = *(float *)v13;
             *(int *)(a7 + 12) = v16;
@@ -7738,7 +7749,7 @@
    pVertices[i].pos.z = 0.99989998;
    pVertices[i].rhw = array_50AC10[i]._rhw;
 
-   pVertices[i].diffuse = GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, 1, 0);
+   pVertices[i].diffuse = ::GetActorTintColor(31, 0, array_50AC10[i].vWorldViewPosition.x, true, false);
    v7 = 0;
    if (this->bUsingSpecular)
    {
@@ -7816,9 +7827,9 @@
     if ( a2 >= 3 )
     {
       ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
-      v5 = 31 - (a3->field_58 & 0x1F);
-      if ( v5 < pOutdoor->field_CBC_terrain_triangles_shade_type )
-        v5 = pOutdoor->field_CBC_terrain_triangles_shade_type;
+      v5 = 31 - (a3->dimming_level & 0x1F);
+      if ( v5 < pOutdoor->max_terrain_dimming_level )
+        v5 = pOutdoor->max_terrain_dimming_level;
       v6 = 8 * v5 | ((8 * v5 | (v5 << 11)) << 8);
       if ( a2 > 0 )
       {
@@ -7903,7 +7914,7 @@
   auto uCorrectedColor = uColor;
   if (pGame->pLightmapBuilder->std__vector_000004_size)
     uCorrectedColor = 0xFFFFFFFF;
-  pGame->AlterGamma(pFace, &uCorrectedColor);
+  pGame->AlterGamma_BLV(pFace, &uCorrectedColor);
 
   if (byte_4D864C && pGame->uFlags & 1)
   {
@@ -8570,7 +8581,7 @@
   v30 = (a2->_screenspace_x_scaler_packedfloat & 0xFFFF) / 65530.0 + HIWORD(a2->_screenspace_x_scaler_packedfloat);
   v29 = (a2->_screenspace_y_scaler_packedfloat & 0xFFFF) / 65530.0 + HIWORD(a2->_screenspace_y_scaler_packedfloat);
 
-  unsigned int diffuse = GetActorTintColor(paletteSubindex, 0, a2->zbuffer_depth, 0, pBillboard);
+  unsigned int diffuse = ::GetActorTintColor(paletteSubindex, 0, a2->zbuffer_depth, 0, pBillboard);
   if (a2->uTintColor & 0x00FFFFFF && bTinting)
   {
     diffuse = sub_4A19D8(a2->uTintColor, diffuse);