Skip to content

Commit 38a3192

Browse files
committed
perf(terrain): Hoist global light ray computation out of per-vertex loop
In HeightMapRenderObjClass::updateVB, the light ray directions were recomputed from TheGlobalData->m_terrainLightPos for every terrain quad in the nested i,j loops. These values are constant for the entire update region, so move the computation before the loops. Eliminates (width * height - 1) redundant recomputations per update tile (typically 255 iterations saved for a 16x16 tile).
1 parent 6e4e5f0 commit 38a3192

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ Int HeightMapRenderObjClass::updateVB(DX8VertexBufferClass *pVB, VERTEX_FORMAT *
327327
// At the bottom, we will copy the final vertex data for one cell into the
328328
// hardware vertex buffer.
329329

330+
for (Int lightIndex=0; lightIndex < TheGlobalData->m_numGlobalLights; lightIndex++)
331+
{
332+
lightPos=&TheGlobalData->m_terrainLightPos[lightIndex];
333+
lightRay[lightIndex].Set(-lightPos->x,-lightPos->y, -lightPos->z);
334+
}
335+
330336
for (j=y0; j<y1; j++)
331337
{
332338
VERTEX_FORMAT *vb = vBase;
@@ -362,12 +368,6 @@ Int HeightMapRenderObjClass::updateVB(DX8VertexBufferClass *pVB, VERTEX_FORMAT *
362368
pMap->getUVData(mapX, mapY, U, V);
363369
pMap->getAlphaUVData(mapX, mapY, UA, VA, alpha, &flipForBlend);
364370

365-
for (Int lightIndex=0; lightIndex < TheGlobalData->m_numGlobalLights; lightIndex++)
366-
{
367-
lightPos=&TheGlobalData->m_terrainLightPos[lightIndex];
368-
lightRay[lightIndex].Set(-lightPos->x,-lightPos->y, -lightPos->z);
369-
}
370-
371371
//top-left sample
372372
l2r.Set(2*MAP_XY_FACTOR,0,MAP_HEIGHT_SCALE*(pMap->getDisplayHeight(mapX+cellOffset, mapY) - pMap->getDisplayHeight(un0, mapY)));
373373
n2f.Set(0,2*MAP_XY_FACTOR,MAP_HEIGHT_SCALE*(pMap->getDisplayHeight(mapX, (mapY+cellOffset)) - pMap->getDisplayHeight(mapX, vn0)));

0 commit comments

Comments
 (0)