[workaround] pinches parallax steps so the 0-1 range has minimal artifacting

This commit is contained in:
Azaezel 2016-12-06 23:41:28 -06:00
parent 0db0a53333
commit 0049678c25
2 changed files with 16 additions and 16 deletions

View file

@ -138,13 +138,13 @@ mat3x3 quatToMat( vec4 quat )
/// ///
vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale ) vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale )
{ {
float depth = texture( texMap, texCoord ).a; float depth = texture( texMap, texCoord ).a/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2( depth * depthScale ); vec2 offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ ) for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ )
{ {
depth = ( depth + texture( texMap, texCoord + offset ).a ) * 0.5; depth = ( depth + texture( texMap, texCoord + offset ).a )/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2( depth * depthScale ); offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
} }
return offset; return offset;
@ -153,13 +153,13 @@ vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float dept
/// Same as parallaxOffset but for dxtnm where depth is stored in the red channel instead of the alpha /// 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) vec2 parallaxOffsetDxtnm(sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale)
{ {
float depth = texture(texMap, texCoord).r; float depth = texture(texMap, texCoord).r/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2(depth * depthScale); vec2 offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++) for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{ {
depth = (depth + texture(texMap, texCoord + offset).r) * 0.5; depth = (depth + texture(texMap, texCoord + offset).r)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2(depth * depthScale); offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
} }
return offset; return offset;

View file

@ -140,13 +140,13 @@ float3x3 quatToMat( float4 quat )
/// ///
float2 parallaxOffset(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 negViewTS, float depthScale) float2 parallaxOffset(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 negViewTS, float depthScale)
{ {
float depth = TORQUE_TEX2D(texMap, texCoord).a; float depth = TORQUE_TEX2D(texMap, texCoord).a/(PARALLAX_REFINE_STEPS*2);
float2 offset = negViewTS.xy * (depth * depthScale); float2 offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++) for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{ {
depth = (depth + TORQUE_TEX2D(texMap, texCoord + offset).a) * 0.5; depth = (depth + TORQUE_TEX2D(texMap, texCoord + offset).a)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * (depth * depthScale); offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS);
} }
return offset; return offset;
@ -155,13 +155,13 @@ float2 parallaxOffset(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 negViewT
/// Same as parallaxOffset but for dxtnm where depth is stored in the red channel instead of the alpha /// Same as parallaxOffset but for dxtnm where depth is stored in the red channel instead of the alpha
float2 parallaxOffsetDxtnm(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 negViewTS, float depthScale) float2 parallaxOffsetDxtnm(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 negViewTS, float depthScale)
{ {
float depth = TORQUE_TEX2D(texMap, texCoord).r; float depth = TORQUE_TEX2D(texMap, texCoord).r/(PARALLAX_REFINE_STEPS*2);
float2 offset = negViewTS.xy * (depth * depthScale); float2 offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS*2);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++) for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{ {
depth = (depth + TORQUE_TEX2D(texMap, texCoord + offset).r) * 0.5; depth = (depth + TORQUE_TEX2D(texMap, texCoord + offset).r)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * (depth * depthScale); offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS*2);
} }
return offset; return offset;