Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
bool tcGen_Environment;
bool tcGen_Lightmap;

bool heightMapInNormalMap; // material has normalmap suited for parallax mapping
bool implicitLightmap;

Color::Color32Bit constantColor; // for CGEN_CONST and AGEN_CONST
Expand Down
30 changes: 15 additions & 15 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ static void Render_vertexLighting_DBS_entity( int stage )
GL_State( stateBits );

bool normalMapping = r_normalMapping->integer && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = pStage->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
bool specularMapping = r_specularMapping->integer && ( pStage->bundle[ TB_SPECULARMAP ].image[ 0 ] );
bool glowMapping = r_glowMapping->integer && ( pStage->bundle[ TB_GLOWMAP ].image[ 0 ] != nullptr );
Expand Down Expand Up @@ -787,7 +787,7 @@ static void Render_vertexLighting_DBS_entity( int stage )
depthScale *= parallaxDepthScale == 0 ? 1 : parallaxDepthScale;
gl_vertexLightingShader_DBS_entity->SetUniform_ParallaxDepthScale( depthScale );
gl_vertexLightingShader_DBS_entity->SetUniform_ParallaxOffsetBias( tess.surfaceShader->parallaxOffsetBias );
gl_vertexLightingShader_DBS_entity->SetUniform_HeightMapInNormalMap( tess.surfaceShader->heightMapInNormalMap );
gl_vertexLightingShader_DBS_entity->SetUniform_HeightMapInNormalMap( pStage->heightMapInNormalMap );
}

// bind u_DiffuseMap
Expand Down Expand Up @@ -938,7 +938,7 @@ static void Render_vertexLighting_DBS_world( int stage )
stateBits = pStage->stateBits;

bool normalMapping = r_normalMapping->integer && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = pStage->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
bool specularMapping = r_specularMapping->integer && ( pStage->bundle[ TB_SPECULARMAP ].image[ 0 ] );
bool glowMapping = r_glowMapping->integer && ( pStage->bundle[ TB_GLOWMAP ].image[ 0 ] != nullptr );
Expand Down Expand Up @@ -1026,7 +1026,7 @@ static void Render_vertexLighting_DBS_world( int stage )
depthScale *= parallaxDepthScale == 0 ? 1 : parallaxDepthScale;
gl_vertexLightingShader_DBS_world->SetUniform_ParallaxDepthScale( depthScale );
gl_vertexLightingShader_DBS_world->SetUniform_ParallaxOffsetBias( tess.surfaceShader->parallaxOffsetBias );
gl_vertexLightingShader_DBS_world->SetUniform_HeightMapInNormalMap( tess.surfaceShader->heightMapInNormalMap );
gl_vertexLightingShader_DBS_world->SetUniform_HeightMapInNormalMap( pStage->heightMapInNormalMap );
}

if( tr.world ) {
Expand Down Expand Up @@ -1139,7 +1139,7 @@ static void Render_lightMapping( int stage )

bool normalMapping = r_normalMapping->integer && hasNormalMap;
bool deluxeMapping = r_deluxeMapping->integer && tr.worldDeluxeMapping && normalMapping;
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && hasNormalMap;
bool heightMapInNormalMap = pStage->heightMapInNormalMap && hasNormalMap;
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
bool specularMapping = r_specularMapping->integer && hasSpecularMap;
bool glowMapping = r_glowMapping->integer && hasGlowMap;
Expand Down Expand Up @@ -1193,7 +1193,7 @@ static void Render_lightMapping( int stage )
depthScale *= parallaxDepthScale == 0 ? 1 : parallaxDepthScale;
gl_lightMappingShader->SetUniform_ParallaxDepthScale( depthScale );
gl_lightMappingShader->SetUniform_ParallaxOffsetBias( tess.surfaceShader->parallaxOffsetBias );
gl_lightMappingShader->SetUniform_HeightMapInNormalMap( tess.surfaceShader->heightMapInNormalMap );
gl_lightMappingShader->SetUniform_HeightMapInNormalMap( pStage->heightMapInNormalMap );
}

// bind u_DiffuseMap
Expand Down Expand Up @@ -1427,7 +1427,7 @@ static void Render_forwardLighting_DBS_omni( shaderStage_t *diffuseStage,
GLimp_LogComment( "--- Render_forwardLighting_DBS_omni ---\n" );

bool normalMapping = r_normalMapping->integer && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = diffuseStage->heightMapInNormalMap && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
bool specularMapping = r_specularMapping->integer && ( diffuseStage->bundle[ TB_SPECULARMAP ].image[ 0 ] );
bool shadowCompare = ( r_shadows->integer >= Util::ordinal(shadowingMode_t::SHADOWING_ESM16) && !light->l.noShadows && light->shadowLOD >= 0 );
Expand Down Expand Up @@ -1488,7 +1488,7 @@ static void Render_forwardLighting_DBS_omni( shaderStage_t *diffuseStage,
depthScale *= parallaxDepthScale == 0 ? 1 : parallaxDepthScale;
gl_forwardLightingShader_omniXYZ->SetUniform_ParallaxDepthScale( depthScale );
gl_forwardLightingShader_omniXYZ->SetUniform_ParallaxOffsetBias( tess.surfaceShader->parallaxOffsetBias );
gl_forwardLightingShader_omniXYZ->SetUniform_HeightMapInNormalMap( tess.surfaceShader->heightMapInNormalMap );
gl_forwardLightingShader_omniXYZ->SetUniform_HeightMapInNormalMap( heightMapInNormalMap );
}

// set uniforms
Expand Down Expand Up @@ -1613,7 +1613,7 @@ static void Render_forwardLighting_DBS_proj( shaderStage_t *diffuseStage,
GLimp_LogComment( "--- Render_fowardLighting_DBS_proj ---\n" );

bool normalMapping = r_normalMapping->integer && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = diffuseStage->heightMapInNormalMap && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
bool specularMapping = r_specularMapping->integer && ( diffuseStage->bundle[ TB_SPECULARMAP ].image[ 0 ] );
bool shadowCompare = ( r_shadows->integer >= Util::ordinal(shadowingMode_t::SHADOWING_ESM16) && !light->l.noShadows && light->shadowLOD >= 0 );
Expand Down Expand Up @@ -1674,7 +1674,7 @@ static void Render_forwardLighting_DBS_proj( shaderStage_t *diffuseStage,
depthScale *= parallaxDepthScale == 0 ? 1 : parallaxDepthScale;
gl_forwardLightingShader_projXYZ->SetUniform_ParallaxDepthScale( depthScale );
gl_forwardLightingShader_projXYZ->SetUniform_ParallaxOffsetBias( tess.surfaceShader->parallaxOffsetBias );
gl_forwardLightingShader_projXYZ->SetUniform_HeightMapInNormalMap( tess.surfaceShader->heightMapInNormalMap );
gl_forwardLightingShader_projXYZ->SetUniform_HeightMapInNormalMap( heightMapInNormalMap );
}

// set uniforms
Expand Down Expand Up @@ -1798,7 +1798,7 @@ static void Render_forwardLighting_DBS_directional( shaderStage_t *diffuseStage,
GLimp_LogComment( "--- Render_forwardLighting_DBS_directional ---\n" );

bool normalMapping = r_normalMapping->integer && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = diffuseStage->heightMapInNormalMap && ( diffuseStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
bool specularMapping = r_specularMapping->integer && ( diffuseStage->bundle[ TB_SPECULARMAP ].image[ 0 ] );
bool shadowCompare = ( r_shadows->integer >= Util::ordinal(shadowingMode_t::SHADOWING_ESM16) && !light->l.noShadows && light->shadowLOD >= 0 );
Expand Down Expand Up @@ -1859,7 +1859,7 @@ static void Render_forwardLighting_DBS_directional( shaderStage_t *diffuseStage,
depthScale *= parallaxDepthScale == 0 ? 1 : parallaxDepthScale;
gl_forwardLightingShader_directionalSun->SetUniform_ParallaxDepthScale( depthScale );
gl_forwardLightingShader_directionalSun->SetUniform_ParallaxOffsetBias( tess.surfaceShader->parallaxOffsetBias );
gl_forwardLightingShader_directionalSun->SetUniform_HeightMapInNormalMap( tess.surfaceShader->heightMapInNormalMap );
gl_forwardLightingShader_directionalSun->SetUniform_HeightMapInNormalMap( heightMapInNormalMap );
}

// set uniforms
Expand Down Expand Up @@ -1998,7 +1998,7 @@ static void Render_reflection_CB( int stage )
GL_State( pStage->stateBits );

bool normalMapping = r_normalMapping->integer && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = pStage->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;

// choose right shader program ----------------------------------
Expand Down Expand Up @@ -2061,7 +2061,7 @@ static void Render_reflection_CB( int stage )
depthScale *= parallaxDepthScale == 0 ? 1 : parallaxDepthScale;
gl_reflectionShader->SetUniform_ParallaxDepthScale( depthScale );
gl_reflectionShader->SetUniform_ParallaxOffsetBias( tess.surfaceShader->parallaxOffsetBias );
gl_reflectionShader->SetUniform_HeightMapInNormalMap( tess.surfaceShader->heightMapInNormalMap );
gl_reflectionShader->SetUniform_HeightMapInNormalMap( pStage->heightMapInNormalMap );
}

// bind u_NormalFormat
Expand Down Expand Up @@ -2261,7 +2261,7 @@ static void Render_liquid( int stage )
GLimp_LogComment( "--- Render_liquid ---\n" );

bool normalMapping = r_normalMapping->integer && ( pStage->bundle[ TB_COLORMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = tess.surfaceShader->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool heightMapInNormalMap = pStage->heightMapInNormalMap && ( pStage->bundle[ TB_NORMALMAP ].image[ 0 ] != nullptr );
bool parallaxMapping = r_parallaxMapping->integer && tess.surfaceShader->parallax && !tess.surfaceShader->noParallax && heightMapInNormalMap;
bool specularMapping = r_specularMapping->integer; // TODO: specular map?

Expand Down
28 changes: 20 additions & 8 deletions src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,14 +1410,16 @@ static bool LoadMap( shaderStage_t *stage, const char *buffer, const int bundleI
imageBits |= IF_NOPICMIP;
}

if ( stage->type == stageType_t::ST_NORMALMAP || stage->type == stageType_t::ST_HEATHAZEMAP || stage->type == stageType_t::ST_LIQUIDMAP )
switch ( stage->type )
{
imageBits |= IF_NORMALMAP;
}

if ( stage->type == stageType_t::ST_NORMALMAP && shader.heightMapInNormalMap )
{
imageBits |= IF_DISPLACEMAP;
case stageType_t::ST_NORMALMAP:
case stageType_t::ST_HEATHAZEMAP:
case stageType_t::ST_LIQUIDMAP:
imageBits |= IF_NORMALMAP;
if ( stage->heightMapInNormalMap || shader.heightMapInNormalMap )
{
imageBits |= IF_DISPLACEMAP;
}
}

if ( stage->stateBits & ( GLS_ATEST_BITS ) )
Expand Down Expand Up @@ -1465,7 +1467,7 @@ static bool LoadMap( shaderStage_t *stage, const char *buffer, const int bundleI
if ( stage->bundle[ bundleIndex ].image[ 0 ]->bits & IF_NORMALMAP )
{
Log::Debug("found heightmap embedded in normalmap '%s'", buffer);
shader.heightMapInNormalMap = true;
stage->heightMapInNormalMap = true;
shader.parallax = true;
}
}
Expand Down Expand Up @@ -1814,6 +1816,16 @@ static bool ParseStage( shaderStage_t *stage, const char **text )

ParseNormalMap( stage, text );
}
else if ( !Q_stricmp( token, "normalHeightMap" ) )
{
if ( stage->collapseType == collapseType_t::COLLAPSE_none )
{
stage->collapseType = collapseType_t::COLLAPSE_generic;
}

stage->heightMapInNormalMap = true;
ParseNormalMap( stage, text );
}
else if ( !Q_stricmp( token, "specularMap" ) )
{
if ( stage->collapseType == collapseType_t::COLLAPSE_reflection_CB )
Expand Down