Skip to content

Commit 6891f15

Browse files
committed
tr_shade: enable PBR for lightMapping
1 parent 4d150fd commit 6891f15

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

src/engine/renderer/tr_shade.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,18 @@ static void Render_vertexLighting_DBS_entity( int stage )
810810
GL_BindToTMU( 1, tr.flatImage );
811811
}
812812

813-
if ( specularMapping )
813+
if ( physicalMapping || specularMapping )
814814
{
815-
// bind u_SpecularMap
816-
GL_BindToTMU( 2, pStage->bundle[ TB_SPECULARMAP ].image[ 0 ] );
815+
// bind u_MaterialMap
816+
GL_BindToTMU( 2, pStage->bundle[ TB_MATERIALMAP ].image[ 0 ] );
817817

818-
float minSpec = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
819-
float maxSpec = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
818+
if ( specularMapping )
819+
{
820+
float minSpec = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
821+
float maxSpec = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
820822

821-
gl_vertexLightingShader_DBS_entity->SetUniform_SpecularExponent( minSpec, maxSpec );
823+
gl_vertexLightingShader_DBS_entity->SetUniform_SpecularExponent( minSpec, maxSpec );
824+
}
822825
}
823826
else
824827
{
@@ -1136,15 +1139,18 @@ static void Render_lightMapping( int stage )
11361139
&& (tess.surfaceShader->surfaceFlags & SURF_NOLIGHTMAP)
11371140
&& !(tess.numSurfaceStages > 0 && tess.surfaceStages[0]->rgbGen == colorGen_t::CGEN_VERTEX);
11381141

1142+
bool isMaterialPhysical = pStage->collapseType == collapseType_t::COLLAPSE_lighting_PBR;
1143+
11391144
bool hasNormalMap = pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr;
1140-
bool hasSpecularMap = pStage->bundle[ TB_SPECULARMAP ].image[ 0 ] != nullptr;
1145+
bool hasMaterialMap = pStage->bundle[ TB_MATERIALMAP ].image[ 0 ] != nullptr;
11411146
bool hasGlowMap = pStage->bundle[ TB_GLOWMAP ].image[ 0 ] != nullptr;
11421147

11431148
bool normalMapping = r_normalMapping->integer && hasNormalMap;
11441149
bool deluxeMapping = r_deluxeMapping->integer && tr.worldDeluxeMapping && normalMapping;
11451150
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && hasNormalMap;
11461151
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
1147-
bool specularMapping = r_specularMapping->integer && hasSpecularMap;
1152+
bool physicalMapping = r_physicalMapping->integer && hasMaterialMap && isMaterialPhysical;
1153+
bool specularMapping = r_specularMapping->integer && hasMaterialMap && !isMaterialPhysical;
11481154
bool glowMapping = r_glowMapping->integer && hasGlowMap;
11491155

11501156
// choose right shader program ----------------------------------
@@ -1156,6 +1162,8 @@ static void Render_lightMapping( int stage )
11561162

11571163
tess.vboVertexSprite = false;
11581164

1165+
gl_lightMappingShader->SetPhysicalShading( physicalMapping );
1166+
11591167
gl_lightMappingShader->BindProgram( pStage->deformIndex );
11601168

11611169
// end choose right shader program ------------------------------
@@ -1224,15 +1232,18 @@ static void Render_lightMapping( int stage )
12241232
GL_BindToTMU( 1, tr.flatImage );
12251233
}
12261234

1227-
if ( specularMapping )
1235+
if ( physicalMapping || specularMapping )
12281236
{
1229-
// bind u_SpecularMap
1230-
GL_BindToTMU( 2, pStage->bundle[ TB_SPECULARMAP ].image[ 0 ] );
1237+
// bind u_MaterialMap
1238+
GL_BindToTMU( 2, pStage->bundle[ TB_MATERIALMAP ].image[ 0 ] );
12311239

1232-
float specExpMin = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
1233-
float specExpMax = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
1240+
if ( specularMapping )
1241+
{
1242+
float specExpMin = RB_EvalExpression( &pStage->specularExponentMin, r_specularExponentMin->value );
1243+
float specExpMax = RB_EvalExpression( &pStage->specularExponentMax, r_specularExponentMax->value );
12341244

1235-
gl_lightMappingShader->SetUniform_SpecularExponent( specExpMin, specExpMax );
1245+
gl_lightMappingShader->SetUniform_SpecularExponent( specExpMin, specExpMax );
1246+
}
12361247
}
12371248
else
12381249
{

0 commit comments

Comments
 (0)