diff --git a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp index 07f874f8b..56c8907e5 100644 --- a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp @@ -347,8 +347,16 @@ void ParallaxFeatGLSL::processPix( Vector &componentList, Var *normalMap = getNormalMapTex(); // Call the library function to do the rest. - meta->addStatement( new GenOp( " @.xy += parallaxOffset( @, @.xy, @, @ );\r\n", - texCoord, normalMap, texCoord, negViewTS, parallaxInfo ) ); + if (fd.features.hasFeature(MFT_IsDXTnm, getProcessIndex())) + { + meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @ );\r\n", + texCoord, normalMap, texCoord, negViewTS, parallaxInfo)); + } + else + { + meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @ );\r\n", + texCoord, normalMap, texCoord, negViewTS, parallaxInfo)); + } // TODO: Fix second UV maybe? diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp index eba99371a..6922cf577 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp @@ -468,8 +468,16 @@ void TerrainDetailMapFeatGLSL::processPix( Vector &component Var *normalMap = _getNormalMapTex(); // Call the library function to do the rest. - meta->addStatement( new GenOp( " @.xy += parallaxOffset( @, @.xy, @, @.z * @ );\r\n", - inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend ) ); + if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex)) + { + meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n", + inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend)); + } + else + { + meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @.z * @ );\r\n", + inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend)); + } } // If this is a prepass then we skip color. diff --git a/Templates/Empty/game/shaders/common/gl/torque.glsl b/Templates/Empty/game/shaders/common/gl/torque.glsl index 42965b7c3..9032a57f7 100644 --- a/Templates/Empty/game/shaders/common/gl/torque.glsl +++ b/Templates/Empty/game/shaders/common/gl/torque.glsl @@ -139,12 +139,27 @@ mat3x3 quatToMat( vec4 quat ) vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale ) { float depth = texture( texMap, texCoord ).a; - vec2 offset = negViewTS.xy * ( depth * depthScale ); + vec2 offset = negViewTS.xy * vec2( depth * depthScale ); for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ ) { depth = ( depth + texture( texMap, texCoord + offset ).a ) * 0.5; - offset = negViewTS.xy * ( depth * depthScale ); + offset = negViewTS.xy * vec2( depth * depthScale ); + } + + return offset; +} + +/// Same as parallaxOffset but for dxtnm where depth is stored in the red channel instead of the alpha +vec2 parallaxOffsetDxtnm(sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale) +{ + float depth = texture(texMap, texCoord).r; + vec2 offset = negViewTS.xy * vec2(depth * depthScale); + + for (int i = 0; i < PARALLAX_REFINE_STEPS; i++) + { + depth = (depth + texture(texMap, texCoord + offset).r) * 0.5; + offset = negViewTS.xy * vec2(depth * depthScale); } return offset; diff --git a/Templates/Full/game/shaders/common/gl/torque.glsl b/Templates/Full/game/shaders/common/gl/torque.glsl index 42965b7c3..9032a57f7 100644 --- a/Templates/Full/game/shaders/common/gl/torque.glsl +++ b/Templates/Full/game/shaders/common/gl/torque.glsl @@ -139,12 +139,27 @@ mat3x3 quatToMat( vec4 quat ) vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale ) { float depth = texture( texMap, texCoord ).a; - vec2 offset = negViewTS.xy * ( depth * depthScale ); + vec2 offset = negViewTS.xy * vec2( depth * depthScale ); for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ ) { depth = ( depth + texture( texMap, texCoord + offset ).a ) * 0.5; - offset = negViewTS.xy * ( depth * depthScale ); + offset = negViewTS.xy * vec2( depth * depthScale ); + } + + return offset; +} + +/// Same as parallaxOffset but for dxtnm where depth is stored in the red channel instead of the alpha +vec2 parallaxOffsetDxtnm(sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale) +{ + float depth = texture(texMap, texCoord).r; + vec2 offset = negViewTS.xy * vec2(depth * depthScale); + + for (int i = 0; i < PARALLAX_REFINE_STEPS; i++) + { + depth = (depth + texture(texMap, texCoord + offset).r) * 0.5; + offset = negViewTS.xy * vec2(depth * depthScale); } return offset;