diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index 40d9d088f9..f738d00823 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -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 diff --git a/src/engine/renderer/tr_shade.cpp b/src/engine/renderer/tr_shade.cpp index b60d8cfcc2..f8e3f39d30 100644 --- a/src/engine/renderer/tr_shade.cpp +++ b/src/engine/renderer/tr_shade.cpp @@ -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 ); @@ -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 @@ -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 ); @@ -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 ) { @@ -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; @@ -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 @@ -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 ); @@ -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 @@ -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 ); @@ -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 @@ -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 ); @@ -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 @@ -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 ---------------------------------- @@ -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 @@ -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? diff --git a/src/engine/renderer/tr_shader.cpp b/src/engine/renderer/tr_shader.cpp index c84139c31a..be41c14463 100644 --- a/src/engine/renderer/tr_shader.cpp +++ b/src/engine/renderer/tr_shader.cpp @@ -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 ) ) @@ -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; } } @@ -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 )