changeset 206:f9cfc1867efd

Слияние
author Ritor1
date Fri, 15 Feb 2013 22:58:53 +0600
parents e50a81060654 (current diff) d65528fc3bda (diff)
children f96601c7e503
files
diffstat 15 files changed, 317 insertions(+), 291 deletions(-) [+]
line wrap: on
line diff
--- a/DecalBuilder.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/DecalBuilder.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -774,28 +774,28 @@
     return;
 
   if (pRenderer->bUsingSpecular)
-    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 3));
+    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP));
 
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
 
   auto pTex = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("hwsplat04");
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex));
  
   DrawDecals(0.00039999999);
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
 
   if (pRenderer->bUsingSpecular)
-    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u));
+    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
 }
 
 //----- (0049C550) --------------------------------------------------------
--- a/Indoor.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/Indoor.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -22,6 +22,7 @@
 #include "TurnEngine.h"
 #include "PaletteManager.h"
 #include "MapInfo.h"
+#include "IndoorCamera.h"
 
 #include "mm7_data.h"
 
@@ -359,18 +360,18 @@
 //----- (00441BD4) --------------------------------------------------------
 void IndoorLocation::Draw()
 {
-  int v0; // eax@1
+  //int v0; // eax@1
   IndoorLocation_drawstru _this; // [sp+0h] [bp-4Ch]@5
   int v2; // [sp+44h] [bp-8h]@5
   int v3; // [sp+48h] [bp-4h]@5
 
-  v0 = 0;
-  if ( viewparams->field_50_draw_debug_outlines )
-    v0 = 1;
-  if ( viewparams->field_54 )
-    LOBYTE(v0) = v0 | 2;
+  _this.uFlags = 0;
+  if (viewparams->draw_sw_outlines)
+    _this.uFlags |= INDOOR_CAMERA_DRAW_SW_OUTLINES;
+  if (viewparams->draw_d3d_outlines)
+    _this.uFlags |= INDOOR_CAMERA_DRAW_D3D_OUTLINES;
+
   _this.field_0_timer = pEventTimer->uTotalGameTimeElapsed;
-  _this.uFlags = v0;
   _this.vPosition.x = pParty->vPosition.x
                    - ((unsigned __int64)(stru_5C6E00->SinCos(pParty->sRotationY)
                                        * (signed __int64)pParty->y_rotation_granularity) >> 16);
--- a/Indoor.h	Fri Feb 15 22:58:43 2013 +0600
+++ b/Indoor.h	Fri Feb 15 22:58:53 2013 +0600
@@ -493,7 +493,7 @@
 struct IndoorLocation_drawstru
 {
   int field_0_timer;
-  int uFlags;
+  int uFlags;              // & INDOOR_CAMERA_DRAW_D3D_OUTLINES:  render d3d outlines
   Vec3_int_ vPosition;
   int sRotationY;
   int sRotationX;
@@ -528,7 +528,7 @@
   int Reset(struct IndoorLocation_drawstru *a2);
 
   int field_0_timer_;
-  int uFlags;
+  int uFlags;              // & INDOOR_CAMERA_DRAW_D3D_OUTLINES:  render d3d outlines
   Vec3_int_ vPartyPos;
   int sPartyRotY;
   int sPartyRotX;
--- a/IndoorCamera.h	Fri Feb 15 22:58:43 2013 +0600
+++ b/IndoorCamera.h	Fri Feb 15 22:58:53 2013 +0600
@@ -1,6 +1,9 @@
 #pragma once
 #include "VectorTypes.h"
 
+
+#define INDOOR_CAMERA_DRAW_SW_OUTLINES 1
+#define INDOOR_CAMERA_DRAW_D3D_OUTLINES 2
 /*  157 */
 #pragma pack(push, 1)
 struct IndoorCamera
@@ -13,7 +16,7 @@
     flt_1C_fov = 2000.0f;
     flt_20_inv_1C = 32.768002f;
 
-    field_4C = 0;
+    flags = 0;
   }
   void Initialize(int degFov, unsigned int uViewportWidth, unsigned int uViewportHeight);
   void Initialize2();
@@ -37,7 +40,7 @@
   int _int_cosine;
   int _int_sine_2;
   int _int_cosine_2;
-  int field_4C;
+  int flags;  // & INDOOR_CAMERA_DRAW_D3D_OUTLINES:  render terrain outlines in d3d
 };
 #pragma pack(pop)
 
--- a/LightmapBuilder.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/LightmapBuilder.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -1630,11 +1630,11 @@
       pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0);
     if ( !byte_4D864C || !(pGame->uFlags & 1) )
     {
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
       ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v7));
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
       v13 = a3;
       v33 = 1.0;
       v32 = 1.0;
@@ -1681,24 +1681,24 @@
         }
       }
       v15 = pRenderer->pRenderD3D->pDevice;
-      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
-      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
-      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
+      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+      ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
     }
     if ( pRenderer->bUsingSpecular )
     {
       //LODWORD(v30) = 1;
       //v29 = 28;
       //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice;
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
       //v30 = pRenderer->uFogColor;
       //v23 = pRenderer->pRenderD3D->pDevice;
       //v29 = 34;
       //v28 = (Lightmap *)v23;
       ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, pRenderer->uFogColor));
       //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice;
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, false));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
     }
   }
   return 1;
@@ -1797,28 +1797,28 @@
     return;
 
   if (pRenderer->bUsingSpecular)
-    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
+    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE));
  
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
 
   auto pTex = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03");
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex));
 
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
 
   DrawLightmaps2(0.00050000002);
 
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
 
   if (pRenderer->bUsingSpecular)
-    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u));
+    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
 }
\ No newline at end of file
--- a/Monsters.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/Monsters.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -1060,6 +1060,7 @@
           case 0x1A:
             v102->pInfos[v103].uSpell2UseChance = atoi((const char *)v2);
             goto LABEL_325;
+
           case 0x1B:
             strcpy(Dest, (const char *)v2);
             Dest[0] = ' ';
--- a/Outdoor.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/Outdoor.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -46,23 +46,20 @@
 //----- (0047A59E) --------------------------------------------------------
 void OutdoorLocation::ExecDraw(unsigned int bRedraw)
 {
-  int v1; // edi@1
   //unsigned int v2; // ebx@1
   int v3; // ST18_4@3
   int v4; // ST04_4@19
   int v5; // eax@19
 
-  v1 = 0;
-  //v2 = bRedraw;
-  if ( viewparams->field_54 )
-    v1 = 2;
+  pIndoorCamera->flags = 0;
+  if (viewparams->draw_d3d_outlines)
+    pIndoorCamera->flags |= INDOOR_CAMERA_DRAW_D3D_OUTLINES;
+
   pIndoorCamera->sRotationX = pParty->sRotationX;
   pIndoorCamera->sRotationY = pParty->sRotationY;
   pIndoorCamera->pos.x = pParty->vPosition.x
                       - ((unsigned __int64)(stru_5C6E00->SinCos(pParty->sRotationY)
                                           * (signed __int64)pParty->y_rotation_granularity) >> 16);
-  //v3 = stru_5C6E00->SinCos(pParty->sRotationY - stru_5C6E00->uIntegerHalfPi);
-  pIndoorCamera->field_4C = v1;
   pIndoorCamera->pos.y = pParty->vPosition.y - pParty->y_rotation_granularity * ((stru_5C6E00->SinCos(pParty->sRotationY)) >> 16);
   pIndoorCamera->pos.z = pParty->vPosition.z + pParty->sEyelevel;
   if (bRedraw || pRenderer->pRenderD3D)
--- a/Render.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/Render.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -52,7 +52,7 @@
 
 RenderVertexSoft array_73D150[20];
 
-RenderVertexD3D3 arary_77E5C8[50];
+RenderVertexD3D3 d3d_vertex_buffer[50];
 
 RenderVertexSoft *ptr_801A04;
 RenderVertexSoft *ptr_801A08;
@@ -135,7 +135,7 @@
   pRenderer->pRenderD3D->CreateTexture(64u, 64u, &pSurface2, &pTexture2, true, false, 32u);
 
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture1));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 2u));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2u));
@@ -143,7 +143,7 @@
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 1u));
 
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture2));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_ADDRESS, 3u));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1u));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, 7u));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, 2u));
@@ -1743,6 +1743,11 @@
   //struct IndoorCameraD3D *pIndoorCameraD3D;
   //RenderVertexSoft *pVertices; // [sp+C4h] [bp-Ch]@6
 
+
+  //warning: the game uses CW culling by default, ccw is incosistent
+  pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW);
+
+
   v63 = 0;
   // basic optimizations
   unsigned int uStartX, uEndX,
@@ -1782,6 +1787,7 @@
       pGame->pIndoorCameraD3D->Project(&pTerrainVertices[z * 128 + x], 1, 0);
     }
   }
+
   for (unsigned int z = uStartZ; z < uEndZ - 1; ++z)
   {
     for (unsigned int x = uStartX; x < uEndX - 1; ++x)
@@ -1796,6 +1802,7 @@
       v8->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v8->uTileBitmapID];
       if (v8->uTileBitmapID == 0xFFFF)
         continue;
+
       v8->flags = 0x8010 |pOutdoor->GetSomeOtherTileInfo(x, z);
       v8->field_32 = 0;
       v8->field_59 = 1;
@@ -1836,6 +1843,7 @@
         array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097);
       }
 
+      bool transparent = false;
             if ( v8->flags & 2 && v8->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
             {
               //v80 = false;
@@ -1844,11 +1852,23 @@
             else
             {
               v6 = v8->uTileBitmapID;
-              //v80 = true;
+              transparent = true;
             }
 
       assert(v6 < 1000); // many random crashes here
-      pRenderer->DrawTerrainPolygon(v8, pBitmaps_LOD->pHardwareTextures[v6]);
+
+      // for all shore tiles - draw a tile water under them since they're half-empty
+      if (!strnicmp(pBitmaps_LOD->pTextures[v8->uTileBitmapID].pName, "wtrdr", 5))  // all shore tile filenames are wtrdrXXX
+      {
+        pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE);  // no Z writing: the shore tile will be draw in the same place, so taking care about z-fighting
+        pRenderer->DrawTerrainPolygon(v8->uNumVertices, v8, pBitmaps_LOD->pHardwareTextures[pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]], false, true);
+        pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE);
+        
+      }
+
+      pRenderer->DrawTerrainPolygon(v8->uNumVertices, v8, pBitmaps_LOD->pHardwareTextures[v6], transparent, true);
+
+
       --pOutdoorCamera->numStru148s;
       --pOutdoorCamera->field_44;
     }
@@ -1996,6 +2016,7 @@
       v5 = abs(X);//v5 = 13108
       v6 = abs(v83);//v6 = 13108
       --X;
+      __debugbreak(); // uncoment & refactor following large if
       v93 = (int)&stru_76E5C8[(v5 << 7) + v6];
       /*if ( !v93->field_0 || ((v7 = 48 * v4, v8 = &pVerticesSR_806210[v4], a2 = v8, !v82) ? (v9 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7),
                                                                        v10 = &pVerticesSR_806210[1] + v7) : (v9 = &pVerticesSR_806210[1] + v7, v10 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7)),
@@ -2168,7 +2189,7 @@
             v77 = (int)v16;
             //v76 = v16->uNumVertices;
 //LABEL_161:
-            pRenderer->DrawTerrainPolygon(v16, pBitmaps_LOD->pHardwareTextures[v39]);//pRenderer->DrawTerrainPolygon(v16->uNumVertices, v16, pBitmaps_LOD->pHardwareTextures[v39], false, v80);
+            pRenderer->DrawTerrainPolygon(v16->uNumVertices, v16, pBitmaps_LOD->pHardwareTextures[v39], false, v80);
             goto LABEL_162;
           }
           v38 = v16;
@@ -2312,7 +2333,7 @@
           v58 = v40->uTileBitmapID;
           v81 = 1;
         }
-        pRenderer->DrawTerrainPolygon(v40, pBitmaps_LOD->pHardwareTextures[v58]);
+        pRenderer->DrawTerrainPolygon(v40->uNumVertices, v40, pBitmaps_LOD->pHardwareTextures[v58], 0, v81);
       }
 LABEL_112:
       v59 = &array_77EC08[pOutdoorCamera->numStru148s];
@@ -2433,7 +2454,7 @@
             //v77 = (int)v71;
             //v76 = v71->uNumVertices;
             //goto LABEL_161;
-            pRenderer->DrawTerrainPolygon(v71, pBitmaps_LOD->pHardwareTextures[v75]);//pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80);
+            pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80);
             goto LABEL_162;
           }
           v38 = (stru148 *)v71;
@@ -4413,18 +4434,18 @@
     {
       if ( !v54 || byte_4D864C && pGame->uFlags & 2 )
       {
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));//   
+        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));//   
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
         if (bUsingSpecular)
         {
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
         }
         if ( (signed int)uNumVertices > 0 )
         {
           v45 = (char *)&array_50AC10[0].vWorldViewPosition;
-          v57 = (int)&arary_77E5C8[0].pos.y;
+          v57 = (int)&d3d_vertex_buffer[0].pos.y;
           v55 = uNumVertices;
           do
           {
@@ -4458,7 +4479,7 @@
         pRenderD3D->pDevice->SetTexture(0, pTexture);
         pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                                            D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                                           arary_77E5C8,
+                                           d3d_vertex_buffer,
                                            uNumVertices,
                                            D3DDP_DONOTLIGHT);
       }
@@ -4466,9 +4487,9 @@
       {
         if ( (signed int)uNumVertices > 0 )
         {
-          v9 = (ODMFace *)&arary_77E5C8[0].pos.y;
+          v9 = (ODMFace *)&d3d_vertex_buffer[0].pos.y;
           v10 = (char *)&array_50AC10[0].vWorldViewPosition;
-          a4 = (ODMFace *)&arary_77E5C8[0].pos.y;
+          a4 = (ODMFace *)&d3d_vertex_buffer[0].pos.y;
           v56 = uNumVertices;
           while ( 1 )
           {
@@ -4503,15 +4524,15 @@
             v9 = a4;
           }
         }
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
         if (bUsingSpecular)
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE));
 
         ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
         ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                                                   D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
-                                                  arary_77E5C8,
+                                                  d3d_vertex_buffer,
                                                   uNumVertices,
                                                   D3DDP_DONOTLIGHT));
         //v50 = (const char *)v5->pRenderD3D->pDevice;
@@ -4521,7 +4542,7 @@
         v23 = uNumVertices;
         if ( (signed int)uNumVertices > 0 )
         {
-          v24 = (char *)&arary_77E5C8[0].diffuse;
+          v24 = (char *)&d3d_vertex_buffer[0].diffuse;
           do
           {
             *(int *)v24 = a2;
@@ -4531,26 +4552,26 @@
           while ( v23 );
         }
         ErrD3D(pRenderD3D->pDevice->SetTexture(0, pTexture));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
+        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
         if ( !pRenderer->bUsingSpecular )
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true));
-
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 1));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR));
         ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                                                   D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
-                                                  arary_77E5C8,
+                                                  d3d_vertex_buffer,
                                                   uNumVertices,
                                                   D3DDP_DONOTLIGHT));
         if (bUsingSpecular)
         {
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
 
           v33 = uNumVertices;
           if ( (signed int)uNumVertices > 0 )
           {
-            v34 = (char *)&arary_77E5C8[0].specular;
+            v34 = (char *)&d3d_vertex_buffer[0].specular;
             do
             {
               v35 = *(int *)v34;
@@ -4562,22 +4583,22 @@
             while ( v33 );
           }
           ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 6));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 5));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_INVSRCALPHA));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCALPHA));
           ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                                                     D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
-                                                    arary_77E5C8,
+                                                    d3d_vertex_buffer,
                                                     uNumVertices,
                                                     D3DDP_DONOTLIGHT));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, true));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
           //v40 = pRenderer->pRenderD3D->pDevice->lpVtbl;
           v41 = GetLevelFogColor();
           pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF);
           v6 = 0;
           pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0);
         }
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, v6));
       }
     }
@@ -7207,7 +7228,7 @@
   return ::GetActorTintColor(a3, a4, a2, a5, a6);
 }
 
-void Render::DrawTerrainPolygon(stru148 *a3, IDirect3DTexture2 *pTexture)//new function
+/*void Render::DrawTerrainPolygon_new(stru148 *a3, IDirect3DTexture2 *pTexture)//new function
 {
   int v5; // ebx@1
   int v6; // edi@1
@@ -7267,13 +7288,13 @@
 
 
  
-     this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1);
+     this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP);
      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
      if (this->bUsingSpecular)
      {
-      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
-      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2);
-      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
      }
 
      pVertices[0].pos.x = array_50AC10[0].vWorldViewProjX;
@@ -7319,12 +7340,13 @@
      this->pRenderD3D->pDevice->SetTexture(0, pTexture);
      this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, pVertices, 6, D3DDP_DONOTLIGHT);
 
-}
+}*/
+
 //----- (004A26BC) --------------------------------------------------------
-void Render::DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, int a6, int a7)
-{
-  RenderVertexSoft *pVertices; // esi@0
-  int v7; // edi@1
+void Render::DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders)
+{
+  //RenderVertexSoft *pVertices; // esi@0
+  //int v7; // edi@1
   unsigned int v8; // ebx@1
   LightmapBuilder *v9; // esi@3
   unsigned int v10; // edx@3
@@ -7366,7 +7388,7 @@
   HRESULT v46; // eax@29
   HRESULT v47; // eax@29
   HRESULT v48; // eax@29
-  IDirect3DDevice3 *v49; // eax@35
+  //IDirect3DDevice3 *v49; // eax@35
   //IDirect3DDevice3Vtbl *v50; // ecx@35
   int v51; // eax@40
   char *v52; // esi@40
@@ -7377,23 +7399,25 @@
   double v57; // st7@42
   float v58; // ST7C_4@43
   int v59; // eax@43
-  signed int v60; // [sp+78h] [bp-14h]@31
-  RenderVertexSoft *v61; // [sp+7Ch] [bp-10h]@3
+  //signed int v60; // [sp+78h] [bp-14h]@31
+  //RenderVertexSoft *v61; // [sp+7Ch] [bp-10h]@3
   const char *v62; // [sp+80h] [bp-Ch]@0
   const char *v63; // [sp+80h] [bp-Ch]@19
   int v64; // [sp+84h] [bp-8h]@0
   LightmapBuilder *v65; // [sp+88h] [bp-4h]@3
   unsigned int v66; // [sp+88h] [bp-4h]@40
   unsigned int a6a; // [sp+A0h] [bp+14h]@11
-
-  v7 = (int)this;
+  int a7;
+
+  //v7 = (int)this;
   v8 = 0;
-  if ( !this->uNumD3DSceneBegins )
+  if (!this->uNumD3DSceneBegins)
      return;
   if ( uNumVertices < 3)
      return;
 
-  v61 = pVertices;
+  //v61 = pVertices;
+
   /*  v9 = pGame->pLightmapBuilder;
     v65 = v9;
     v10 = v9->std__vector_000004_size;*/
@@ -7404,37 +7428,35 @@
     }
     else
     {
-      if ( a6 || !pGame->pLightmapBuilder->std__vector_000004_size || 
+      if (transparent || !pGame->pLightmapBuilder->std__vector_000004_size || 
           byte_4D864C && pGame->uFlags & 2 )
       {
-        if ( (_BYTE)a7 )
-          v60 = 3;
+        if (clampAtTextureBorders)
+          this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP);
         else
-          v60 = 1;
-        this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, v60);
-        if ( a6 || this->bUsingSpecular )
-        {
-          this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
-          v49 = this->pRenderD3D->pDevice;
-          //v50 = v49->lpVtbl;
-          if ( a6 )
+          this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP);
+
+        if (transparent || this->bUsingSpecular)
+        {
+          this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+          if (transparent)
           {
-            this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 5);
-            //this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 6);
+            this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
+            this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
+            //this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO);
+            //this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
           }
           else
           {
-            this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2);
-            //this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1);
-            __debugbreak;//it's error
+            this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
+            this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
           }
-
-        }
-        if ( (signed int)uNumVertices > 0 )
-        {
-          v51 = (int)&arary_77E5C8[0].pos.y;
+        }
+        if (uNumVertices > 0)
+        {
+          v51 = (int)&d3d_vertex_buffer[0].pos.y;
           v52 = (char *)&array_50AC10[0].vWorldViewPosition;
-          a7 = (int)&arary_77E5C8[0].pos.y;
+          a7 = (int)&d3d_vertex_buffer[0].pos.y;
           v66 = uNumVertices;
           while ( 1 )
           {
@@ -7470,22 +7492,21 @@
           }
         }
         this->pRenderD3D->pDevice->SetTexture(0, a5);
-        this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-          arary_77E5C8, uNumVertices, 16);
-        if ( a6 )
-        {
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
+        this->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, d3d_vertex_buffer, uNumVertices, 16);
+        if (transparent)
+        {
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
         }
       }
       else
       {
         if ( (signed int)uNumVertices > 0 )
         {
-          v12 = (int)&arary_77E5C8[0].pos.y;
+          v12 = (int)&d3d_vertex_buffer[0].pos.y;
           v13 = (char *)&array_50AC10[0].vWorldViewPosition;
-          a7 = (int)&arary_77E5C8[0].pos.y;
+          a7 = (int)&d3d_vertex_buffer[0].pos.y;
           a6a = uNumVertices;
           while ( 1 )
           {
@@ -7520,26 +7541,25 @@
             v12 = a7;
           }
         }
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
-        if ( pRenderer->bUsingSpecular )
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
+        if (pRenderer->bUsingSpecular)
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE));
 
         ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));
-        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-                D3DPT_TRIANGLEFAN,
+        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                arary_77E5C8,
+                d3d_vertex_buffer,
                 uNumVertices,
                 16));
         //v63 = (const char *)v7->pRenderD3D->pDevice;
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
         //(*(void (**)(void))(*(int *)v63 + 88))();
         pGame->pLightmapBuilder->_45D74F_MessWithLight(-1, 0);
         v26 = uNumVertices;
         if ( (signed int)uNumVertices > 0 )
         {
-          v27 = (char *)&arary_77E5C8[0].diffuse;
+          v27 = (char *)&d3d_vertex_buffer[0].diffuse;
           do
           {
             *(int *)v27 = -1;
@@ -7549,28 +7569,27 @@
           while ( v26 );
         }
         ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
+        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
         if ( !pRenderer->bUsingSpecular )
         {
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
-        }
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 1u));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3u));
-        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-                D3DPT_TRIANGLEFAN,
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+        }
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR));
+        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                arary_77E5C8,
+                d3d_vertex_buffer,
                 uNumVertices,
                 16));
         if ( pRenderer->bUsingSpecular )
         {
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
           ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));
           v37 = uNumVertices;
           if ( (signed int)uNumVertices > 0 )
           {
-            v38 = (char *)&arary_77E5C8[0].specular;
+            v38 = (char *)&d3d_vertex_buffer[0].specular;
             do
             {
               v39 = *(int *)v38;
@@ -7582,28 +7601,29 @@
             while ( v37 );
           }
           ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));//problem
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 6u));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 5u));
-          ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-                  D3DPT_TRIANGLEFAN,
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_INVSRCALPHA));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCALPHA));
+          ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                   D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                  arary_77E5C8,
+                  d3d_vertex_buffer,
                   uNumVertices,
                   16));
-          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1));
+          ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
           //v44 = pRenderer->pRenderD3D->pDevice;
           v45 = GetLevelFogColor();
           ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, v45 & 0xFFFFFF));
           v8 = 0;
           ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
         }
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, v8));
       }
     }
-    if ( pIndoorCamera->field_4C & 2 || pBLVRenderParams->uFlags & 2 )
-      pGame->pIndoorCameraD3D->debug_outline_d3d(arary_77E5C8, uNumVertices, 0xFFFFFFu, 0.0);
+
+    if (pIndoorCamera->flags & INDOOR_CAMERA_DRAW_D3D_OUTLINES ||
+        pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_D3D_OUTLINES )
+      pGame->pIndoorCameraD3D->debug_outline_d3d(d3d_vertex_buffer, uNumVertices, 0x00FFFFFF, 0.0);
   }
 
 // 4A26BC: could not find valid save-restore pair for esi
@@ -7623,12 +7643,12 @@
 
  if (uNumVertices >= 3)
  {
-  this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1);
+  this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP);
   if (this->bUsingSpecular)
   {
-   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
-   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2);
-   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1);
+   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
+   this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
   }
   
   for (i = 0; i < uNumVertices; ++i)
@@ -7666,12 +7686,12 @@
     return;
   if ( uNumVertices >= 3 )
   {
-    this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1);
+    this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP);
     if ( this->bUsingSpecular )
     {
-      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
-      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2);
-      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
+      this->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
     }
     for (i = 0; i < uNumVertices; ++i)
     {
@@ -7715,14 +7735,14 @@
     v4 = a2;
     if ( a2 >= 3 )
     {
-      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
+      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;
       v6 = 8 * v5 | ((8 * v5 | (v5 << 11)) << 8);
       if ( a2 > 0 )
       {
-        v7 = (char *)&arary_77E5C8[0].pos.y;
+        v7 = (char *)&d3d_vertex_buffer[0].pos.y;
         v8 = (char *)&array_507D30[0].vWorldViewProjY;
         do
         {
@@ -7744,10 +7764,9 @@
         while ( v4 );
       }
       ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
-      ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-        D3DPT_TRIANGLEFAN,
+      ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
         D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-        arary_77E5C8,
+        d3d_vertex_buffer,
         a2,
         28));
     }
@@ -7810,11 +7829,11 @@
   {
       __debugbreak();
       ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
-      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
+      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
       if ( (signed int)uNumVertices > 0 )
       {
         v12 = (char *)&array_507D30[0].vWorldViewPosition;
-        v13 = (char *)&arary_77E5C8[0].pos.y;
+        v13 = (char *)&d3d_vertex_buffer[0].pos.y;
         auto a7 = uNumVertices;
         uint v18;
         do
@@ -7840,12 +7859,12 @@
         }
         while ( !v18 );
       }
-      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
+      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
       ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
       ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
               D3DPT_TRIANGLEFAN,
               D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-              arary_77E5C8,
+              d3d_vertex_buffer,
               uNumVertices,
               28));
       pGame->pLightmapBuilder->_45D74F_MessWithLight(-1, 0);
@@ -7857,21 +7876,21 @@
     {
       for (uint i = 0; i < uNumVertices; ++i)
       {
-        arary_77E5C8[i].pos.x = array_507D30[i].vWorldViewProjX;
-        arary_77E5C8[i].pos.y = array_507D30[i].vWorldViewProjY;
-        arary_77E5C8[i].pos.z = 1.0 - 1.0 / (array_507D30[i].vWorldViewPosition.x * 0.061758894);
-        arary_77E5C8[i].rhw = 1.0 / array_507D30[i].vWorldViewPosition.x;
-        arary_77E5C8[i].diffuse = uCorrectedColor;
-        arary_77E5C8[i].specular = 0;
-        arary_77E5C8[i].texcoord.x = array_507D30[i].u / (double)pTex->uTextureWidth;
-        arary_77E5C8[i].texcoord.y = array_507D30[i].v / (double)pTex->uTextureHeight;
-      }
-
-      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
+        d3d_vertex_buffer[i].pos.x = array_507D30[i].vWorldViewProjX;
+        d3d_vertex_buffer[i].pos.y = array_507D30[i].vWorldViewProjY;
+        d3d_vertex_buffer[i].pos.z = 1.0 - 1.0 / (array_507D30[i].vWorldViewPosition.x * 0.061758894);
+        d3d_vertex_buffer[i].rhw = 1.0 / array_507D30[i].vWorldViewPosition.x;
+        d3d_vertex_buffer[i].diffuse = uCorrectedColor;
+        d3d_vertex_buffer[i].specular = 0;
+        d3d_vertex_buffer[i].texcoord.x = array_507D30[i].u / (double)pTex->uTextureWidth;
+        d3d_vertex_buffer[i].texcoord.y = array_507D30[i].v / (double)pTex->uTextureHeight;
+      }
+
+      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
       ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
       ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                arary_77E5C8,
+                d3d_vertex_buffer,
                 uNumVertices,
                 28));
     }
@@ -7882,7 +7901,7 @@
         {
           v23 = pTex;
           v24 = (char *)&array_507D30[0].vWorldViewPosition;
-          v25 = (char *)&arary_77E5C8[0].pos.y;
+          v25 = (char *)&d3d_vertex_buffer[0].pos.y;
           pTex = (Texture *)uNumVertices;
           uint v18;
           do
@@ -7908,12 +7927,11 @@
           while ( !v18 );
         }
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
+        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
         ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
-        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-                D3DPT_TRIANGLEFAN,
+        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                arary_77E5C8,
+                d3d_vertex_buffer,
                 uNumVertices,
                 28));
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1));
@@ -7921,7 +7939,7 @@
         v33 = uNumVertices;
         if ( (signed int)uNumVertices > 0 )
         {
-          v34 = (char *)&arary_77E5C8[0].diffuse;
+          v34 = (char *)&d3d_vertex_buffer[0].diffuse;
           do
           {
             *(int *)v34 = uCorrectedColor;
@@ -7931,20 +7949,19 @@
           while ( v33 );
         }
         ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 1));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3));
-        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-                D3DPT_TRIANGLEFAN,
+        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR));
+        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                arary_77E5C8,
+                d3d_vertex_buffer,
                 uNumVertices,
                 28));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
     }
   }
 }
@@ -8708,12 +8725,12 @@
   v29[3].pos.y = v18 + srcY;
   v29[3].texcoord.x = 0.0;
   v29[3].texcoord.y = 0.0;
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, a9));
   ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(
     D3DPT_TRIANGLEFAN,
@@ -8721,12 +8738,12 @@
     v29,
     4,
     24));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2u));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
 }
 
 
@@ -9186,25 +9203,25 @@
     v36[3].texcoord.x = 0.0;
     v36[3].texcoord.y = 0.0;
     ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 5u));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 6u));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 8u));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS));
     ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
       D3DPT_TRIANGLEFAN,
       D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
       v36,
       4,
       28));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
-    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2u));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
+    ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESS));
   }
   else
   {
@@ -11295,9 +11312,9 @@
 //----- (004A1C1E) --------------------------------------------------------
 void DoRenderBillboards_D3D()
 {
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 3u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
   
   /*if (pRenderer->uNumBillboardsToDraw)
@@ -11348,16 +11365,16 @@
   if (pRenderer->bFogEnabled)
   {
     pRenderer->bFogEnabled = false;
-    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1));
+    ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
     ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF));
     ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
   }
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
 }
 
 
@@ -11374,14 +11391,14 @@
       if (pRenderer->bFogEnabled)
       {
         pRenderer->bFogEnabled = false;
-        ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u));
+        ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
         ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF));
         ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
       }
 
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 5));
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 6u));
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
     }
     break;
 
@@ -11394,13 +11411,13 @@
         if (!pRenderer->bFogEnabled)
         {
           pRenderer->bFogEnabled = true;
-          ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
-        }
-      }
-
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
+          ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE));
+        }
+      }
+
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
     }
     break;
 
--- a/Render.h	Fri Feb 15 22:58:43 2013 +0600
+++ b/Render.h	Fri Feb 15 22:58:53 2013 +0600
@@ -313,9 +313,8 @@
   void DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
   unsigned int GetActorTintColor(float a2, int a3, int a4, int a5, RenderBillboard *a6);
   void DrawPolygon(unsigned int uNumVertices, stru148 *a3, ODMFace *a4, IDirect3DTexture2 *pTexture);
-  void DrawTerrainPolygon(stru148 *a3, IDirect3DTexture2 *pTexture);
-  void DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, int a6, int a7);
-  void Render::DrawStrip(unsigned int uNumVertices, struct stru148 *a3, IDirect3DTexture2 *pTexture);
+  void DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders);
+  void DrawStrip(unsigned int uNumVertices, struct stru148 *a3, IDirect3DTexture2 *pTexture);
   void DrawFan(unsigned int uNumVertices, stru148 *a3, IDirect3DTexture2 *a4);
   void _4A2ED5(signed int a2, stru148 *a3, IDirect3DTexture2 *pHwTex);
   void DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, Texture *pTex, int uPackedID, unsigned int uColor, int a8);
@@ -513,7 +512,7 @@
 
 extern RenderVertexSoft array_73D150[20];
 
-extern RenderVertexD3D3 arary_77E5C8[50];
+extern RenderVertexD3D3 d3d_vertex_buffer[50];
 
 extern RenderVertexSoft *ptr_801A04;
 extern RenderVertexSoft *ptr_801A08;
--- a/Viewport.h	Fri Feb 15 22:58:43 2013 +0600
+++ b/Viewport.h	Fri Feb 15 22:58:53 2013 +0600
@@ -43,6 +43,12 @@
 #pragma pack(push, 1)
 struct ViewingParams
 {
+  inline ViewingParams()
+  {
+    draw_sw_outlines = false;
+    draw_d3d_outlines = false;
+  }
+
   int _443291();
   unsigned int _443343();
   int _443219();
@@ -76,8 +82,8 @@
   int bRedrawGameUI;
   int field_48;
   int field_4C;
-  int field_50_draw_debug_outlines;
-  int field_54;
+  int draw_sw_outlines;
+  int draw_d3d_outlines;
   int field_58;
   int field_5C;
   int field_60;
--- a/mm7_2.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/mm7_2.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -4872,10 +4872,11 @@
   static_stru_F8BA58.field_0 = 0;
   if ( _this && *_this )
   {
-    v2 = (char *)&unk_F8B668;
+    int i = 0;
+    v2 = (char *)&array_F8B668;
     v3 = 1;
     v7 = 0;
-    v4 = _this - (char *)&unk_F8B668;
+    v4 = _this - (char *)&array_F8B668;
     do
     {
       v5 = v2[v4];
@@ -4920,8 +4921,9 @@
       if ( static_stru_F8BA58.field_0 >= 30 )
         break;
       ++v2;
-    }
-    while ( (unsigned int)v2 < (unsigned int)&unk_F8BA50 );
+      ++i;
+    }
+    while (i < 1000);
     *v2 = 0;
   }
   result = a2;
--- a/mm7_3.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/mm7_3.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -9699,6 +9699,8 @@
 //----- (004811A3) --------------------------------------------------------
 void stru148::_4811A3()
 {
+  __debugbreak();
+
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
   pRenderer->DrawTerrainPolygon(uNumVertices, this,
     pBitmaps_LOD->pHardwareTextures[pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid]],
--- a/mm7_data.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/mm7_data.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -1856,8 +1856,8 @@
 int dword_F8B1F4; // weak
 _UNKNOWN unk_F8B1F8; // weak
 _UNKNOWN unk_F8B5E0; // weak
-_UNKNOWN unk_F8B668; // weak
-_UNKNOWN unk_F8BA50; // weak
+char array_F8B668[1000]; // weak
+//_UNKNOWN unk_F8BA50; // weak
 char byte_F8BC0C; // weak
 int bGameoverLoop = 0; // weak
 __int16 word_F8BC48_displaced_face_intersect_plane_coords_a; // idb
--- a/mm7_data.h	Fri Feb 15 22:58:43 2013 +0600
+++ b/mm7_data.h	Fri Feb 15 22:58:53 2013 +0600
@@ -1711,8 +1711,8 @@
 extern _UNKNOWN unk_F8B1F8; // weak
 extern _UNKNOWN unk_F8B5E0; // weak
 extern struct FrameTableTxtLine stru_F8B5E8; // weak
-extern _UNKNOWN unk_F8B668; // weak
-extern _UNKNOWN unk_F8BA50; // weak
+extern char array_F8B668[]; // weak
+//extern _UNKNOWN unk_F8BA50; // weak
 extern char byte_F8BC0C; // weak
 extern int bGameoverLoop; // weak
 extern __int16 word_F8BC48_displaced_face_intersect_plane_coords_a; // idb
--- a/stru6.cpp	Fri Feb 15 22:58:43 2013 +0600
+++ b/stru6.cpp	Fri Feb 15 22:58:53 2013 +0600
@@ -1553,27 +1553,25 @@
       pRenderer->pRenderD3D->pDevice->SetTexture(
         0,
         pSprites_LOD->pHardwareSprites[v11].pTexture);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 8u);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS);
       pRenderer->pRenderD3D->pDevice->DrawPrimitive(
         D3DPT_TRIANGLEFAN,
         D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
         vd3d,
         4,
         28);
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2),
-                  "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\seffects.cpp:1348");
-      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1),
-                  "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\seffects.cpp:1349");
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, true);
-      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2);
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+      ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE);
+      pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESS);
     }
     else
     {