Skip to content

Commit

Permalink
renderer: enable lightmapping with whiteimage on nolightmap shader, fix
Browse files Browse the repository at this point in the history
#326

- enable lightmapping with whiteimage on nolightmap shader, fix #326
- enable lightmapping with whiteimage when there is no lightmap neither lightgrid
- enable deluxemapping with blackimage when there is no deluxemap
- rework the code and functions around those features
  • Loading branch information
illwieckz committed Apr 23, 2020
1 parent 9130b08 commit 1851568
Showing 1 changed file with 62 additions and 54 deletions.
116 changes: 62 additions & 54 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,33 +350,27 @@ ALIGNED( 16, shaderCommands_t tess );
GetLightMap
=================
*/
static image_t* GetLightMap( bool noLightMap )
static image_t* GetLightMap()
{
image_t *lightmap;

if ( noLightMap )
if ( !tr.lightmaps.currentElements )
{
lightmap = nullptr;
return tr.whiteImage;
}
else if ( tr.fatLightmap )
{
lightmap = tr.fatLightmap;
return tr.fatLightmap;
}
else if ( tess.lightmapNum >= 0 && tess.lightmapNum < tr.lightmaps.currentElements )
{
// TODO: Check if this test is needed.
image_t *lightmap;
lightmap = ( image_t * ) Com_GrowListElement( &tr.lightmaps, tess.lightmapNum );
return lightmap == nullptr ? tr.whiteImage : lightmap;
}
else
{
lightmap = nullptr;
}

if ( !tr.lightmaps.currentElements || !lightmap )
{
return tr.whiteImage;
}

return lightmap;
}

/*
Expand All @@ -386,23 +380,22 @@ GetDeluxeMap
*/
static image_t* GetDeluxeMap()
{
image_t *deluxemap;

if ( tess.lightmapNum >= 0 && tess.lightmapNum < tr.deluxemaps.currentElements )
if ( !tr.deluxemaps.currentElements )
{
deluxemap = ( image_t * ) Com_GrowListElement( &tr.deluxemaps, tess.lightmapNum );
return tr.blackImage;
}
else
else if ( tess.lightmapNum >= 0 && tess.lightmapNum < tr.deluxemaps.currentElements )
{
deluxemap = nullptr;
// TODO: Check if this test is needed.
image_t *deluxemap;
deluxemap = ( image_t * ) Com_GrowListElement( &tr.deluxemaps, tess.lightmapNum );
return deluxemap == nullptr ? tr.blackImage : deluxemap;
}

if ( !tr.deluxemaps.currentElements || !deluxemap )
else
{
return tr.blackImage;
}

return deluxemap;
}

/*
Expand Down Expand Up @@ -735,6 +728,10 @@ static void Render_lightMapping( int stage )
&& tess.bspSurface \
&& tr.worldDeluxeMapping;

bool noLightMap = !pStage->implicitLightmap
&& (tess.surfaceShader->surfaceFlags & SURF_NOLIGHTMAP)
&& !(tess.numSurfaceStages > 0 && tess.surfaceStages[0]->rgbGen == colorGen_t::CGEN_VERTEX);

bool isWorldEntity = backEnd.currentEntity == &tr.worldEntity;

uint32_t stateBits = pStage->stateBits;
Expand Down Expand Up @@ -774,6 +771,47 @@ static void Render_lightMapping( int stage )
break;
}

// u_LightMap, u_DeluxeMap
image_t *lightmap;
image_t *deluxemap;

if ( noLightMap )
{
lightmap = tr.whiteImage;
enableLightMapping = true;
}
else if ( enableLightMapping )
{
lightmap = GetLightMap();
}
else if ( tr.lightGrid1Image )
{
// Store lightGrid1 as lightmap,
// the GLSL code will know to deal with it.
lightmap = tr.lightGrid1Image;
}
else
{
lightmap = tr.whiteImage;
enableLightMapping = true;
}

if ( enableDeluxeMapping )
{
deluxemap = GetDeluxeMap();
}
else if ( tr.lightGrid2Image )
{
// Store lightGrid2 as deluxemap,
// the GLSL code will know to deal with it.
deluxemap = tr.lightGrid2Image;
}
else
{
deluxemap = tr.blackImage;
enableDeluxeMapping = true;
}

// choose right shader program ----------------------------------
tess.vboVertexSprite = false;

Expand Down Expand Up @@ -1009,40 +1047,10 @@ static void Render_lightMapping( int stage )
}

// bind u_LightMap
if ( enableLightMapping )
{
bool noLightMap = !pStage->implicitLightmap
&& (tess.surfaceShader->surfaceFlags & SURF_NOLIGHTMAP)
&& !(tess.numSurfaceStages > 0 && tess.surfaceStages[0]->rgbGen == colorGen_t::CGEN_VERTEX);

image_t *lightmap = GetLightMap( noLightMap );
GL_BindToTMU( BIND_LIGHTMAP, lightmap );
}
else if ( tr.lightGrid1Image )
{
// FIXME: enable lightmapping with whiteImage if not tr.lightGrid1Image
GL_BindToTMU( BIND_LIGHTMAP, tr.lightGrid1Image );
}
else
{
GL_BindToTMU( BIND_LIGHTMAP, tr.whiteImage );
}
GL_BindToTMU( BIND_LIGHTMAP, lightmap );

// bind u_DeluxeMap
if ( enableDeluxeMapping )
{
image_t *deluxemap = GetDeluxeMap();
GL_BindToTMU( BIND_DELUXEMAP, deluxemap );
}
else if ( tr.lightGrid2Image )
{
// FIXME: enable deluxemapping with blackImage if not tr.lightGrid2Image
GL_BindToTMU( BIND_DELUXEMAP, tr.lightGrid2Image );
}
else
{
GL_BindToTMU( BIND_DELUXEMAP, tr.blackImage );
}
GL_BindToTMU( BIND_DELUXEMAP, deluxemap );

// bind u_GlowMap
GL_BindToTMU( BIND_GLOWMAP, pStage->bundle[ TB_GLOWMAP ].image[ 0 ] );
Expand Down

0 comments on commit 1851568

Please sign in to comment.