Skip to content

Commit

Permalink
renderer: make a difference between a light style map and a light map…
Browse files Browse the repository at this point in the history
… with useless “tcGen lightmap”
  • Loading branch information
illwieckz committed Jan 13, 2024
1 parent d176b09 commit 56516a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,8 @@ enum class deluxeMode_t { NONE, GRID, MAP };
ST_HEATHAZEMAP, // heatHaze post process effect
ST_LIQUIDMAP,
ST_LIGHTMAP,
ST_LIGHTSTYLEMAP,
ST_STYLELIGHTMAP,
ST_STYLECOLORMAP,
ST_COLLAPSE_lighting_PBR, // map|diffusemap + opt:normalmap + opt:glowmap + opt:physicalmap
ST_COLLAPSE_lighting_PHONG, // map|diffusemap + opt:normalmap + opt:glowmap + specularmap
ST_COLLAPSE_reflection_CB, // color cubemap + normalmap
Expand Down
5 changes: 3 additions & 2 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ static void Render_generic( shaderStage_t *pStage )
// bind u_ColorMap
GL_SelectTexture( 0 );

if ( pStage->type == stageType_t::ST_LIGHTSTYLEMAP )
if ( pStage->type == stageType_t::ST_STYLELIGHTMAP )
{
GL_Bind( GetLightMap() );
}
Expand Down Expand Up @@ -2793,7 +2793,8 @@ void Tess_StageIteratorGeneric()

break;

case stageType_t::ST_LIGHTSTYLEMAP:
case stageType_t::ST_STYLELIGHTMAP:
case stageType_t::ST_STYLECOLORMAP:
Render_generic( pStage );
break;

Expand Down
47 changes: 34 additions & 13 deletions src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3848,14 +3848,21 @@ static bool ParseShader( const char *_text )
/* Examples of shaders with light styles, those
shaders are generated by the q3map2 map compiler.
All stages with “tcGen lightmap” are light style
stages, even if using the “$lightmap” keyword for
the texture path, or if using a direct path to
the lightmap image like “maps/<nam>/lm_<num>[ext]”.
All color stages with “tcGen lightmap” are light style
stages, they use direct path to the light map image
like “maps/<nam>/lm_<num>[ext]”.
Light map stages using the “$lightmap” image don't
need “tcGen lightmap” and then such stage with such
keyword should be light style stages, but some legacy
materials may needlessly set “tcGen lightmap” on the
light map stage so we need more data to not wrongly
detect them as light style stages.
It looks like all light style stages use
the “blendFunc GL_SRC_ALPHA GL_ONE” blend operation,
so we may also detect them by looking for that.
so we use that to know if a light map stage is a
light map one or a light style one.
gloom2/673A7C895A24ECE49A80324DF57B0CC1
{ // Q3Map2 defaulted
Expand Down Expand Up @@ -3954,10 +3961,20 @@ static bool ParseShader( const char *_text )
Light style map stages using the direct image path
are already rendered by Render_lightmap as they have
a ST_COLORMAP type so we don't have to change them. */

bool lightStyleBlend = ( stage->stateBits & GLS_SRCBLEND_BITS ) == GLS_SRCBLEND_SRC_ALPHA
&& ( stage->stateBits & GLS_DSTBLEND_BITS ) == GLS_DSTBLEND_ONE;

if ( stage->type == stageType_t::ST_LIGHTMAP
&& stage->tcGen_Lightmap
&& lightStyleBlend )
{
stage->type = stageType_t::ST_STYLELIGHTMAP;
}
else if ( stage->type != stageType_t::ST_LIGHTMAP
&& stage->tcGen_Lightmap )
{
stage->type = stageType_t::ST_LIGHTSTYLEMAP;
stage->type = stageType_t::ST_STYLECOLORMAP;
}

/* Light styles are only compatible with light mapping
Expand All @@ -3972,12 +3989,15 @@ static bool ParseShader( const char *_text )
is disabled. */
if ( tr.lightMode != lightMode_t::MAP || r_lightStyles->integer == 0 )
{
/* All light styles, either as ST_LIGHTSTYLEMAP
or as ST_COLORMAP have tcGen_Lightmap so we can
detect both at once. */
if ( stage->tcGen_Lightmap )
switch ( stage->type )
{
stage->active = false;
case stageType_t::ST_STYLELIGHTMAP:
case stageType_t::ST_STYLECOLORMAP:
stage->active = false;
break;

default:
break;
}
}

Expand Down Expand Up @@ -5397,7 +5417,7 @@ static shader_t *FinishShader()
{
case stageType_t::ST_LIQUIDMAP:
case stageType_t::ST_LIGHTMAP:
case stageType_t::ST_LIGHTSTYLEMAP:
case stageType_t::ST_STYLELIGHTMAP:
// skip
break;

Expand Down Expand Up @@ -6265,7 +6285,8 @@ void R_ShaderList_f()
stageTypeStrings[stageType_t::ST_HEATHAZEMAP] = "HEATHAZEMAP";
stageTypeStrings[stageType_t::ST_LIQUIDMAP] = "LIQUIDMAP";
stageTypeStrings[stageType_t::ST_LIGHTMAP] = "LIGHTMAP";
stageTypeStrings[stageType_t::ST_LIGHTSTYLEMAP] = "LIGHTSTYLEMAP";
stageTypeStrings[stageType_t::ST_STYLELIGHTMAP] = "STYLELIGHTMAP";
stageTypeStrings[stageType_t::ST_STYLECOLORMAP] = "STYLECOLORMAP";
stageTypeStrings[stageType_t::ST_COLLAPSE_lighting_PBR] = "LIGHTING_PBR";
stageTypeStrings[stageType_t::ST_COLLAPSE_lighting_PHONG] = "LIGHTING_PHONG";
stageTypeStrings[stageType_t::ST_COLLAPSE_reflection_CB] = "REFLECTION_CB";
Expand Down

0 comments on commit 56516a8

Please sign in to comment.