Skip to content

Commit

Permalink
UPBGE: Fix parallax mapping artifacts.
Browse files Browse the repository at this point in the history
Previously artifacts were noticed in the area where the shader change of step, after
some test it appears that using a mipmapped texture to compute the parallax uv is
unsafe.

Replacing a call to texture2D by a call to textureLod(..., 0) avoid using any mipmap
and resolve the artifacts. Even if we don't use mipmapping to compute the parallax uv,
all the texture using this uv can keep using mipmapping.

In the same time the unused function parallax_scale is removed.
  • Loading branch information
panzergame committed Dec 29, 2016
1 parent bfe217c commit 9f621ad
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions source/blender/gpu/shaders/gpu_shader_material.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3783,11 +3783,6 @@ void node_output_world(vec4 surface, vec4 volume, out vec4 result)
result = surface;
}

vec2 parallax_scale(vec2 texuv, vec2 size)
{
return (texuv * size) + (vec2(1.0) - size) / 2.0;
}

void parallax_out(vec3 texco, vec3 vp, vec4 tangent, vec3 vn, vec3 size, mat3 mat, sampler2D ima, float scale, float numsteps,
float bumpscale, float discarduv, out vec3 ptexcoord)
{
Expand All @@ -3810,7 +3805,7 @@ void parallax_out(vec3 texco, vec3 vp, vec4 tangent, vec3 vn, vec3 size, mat3 ma

// Linear sample from top.
for (int i = 0; i < numsteps; ++i) {
height = texture2D(ima, texco.xy - delta * (1.0 - depth)).a;
height = textureLod(ima, texco.xy - delta * (1.0 - depth), 0).a;
// Stop if the texture height is greater than current depth.
if (height > depth) {
break;
Expand All @@ -3833,7 +3828,7 @@ void parallax_out(vec3 texco, vec3 vp, vec4 tangent, vec3 vn, vec3 size, mat3 ma
// The shift between the texture height and the last depth.
float depthshiftcurlay = height - depth;
// The shift between the texture height with precedent uv computed with pre detph and the pre depth.
float depthshiftprelay = texture2D(ima, texuvprelay).a - depthprelay;
float depthshiftprelay = textureLod(ima, texuvprelay, 0).a - depthprelay;

float weight = 1.0;
// If the height is right in the middle of two step the difference of the two shifts will be null.
Expand Down

1 comment on commit 9f621ad

@youle31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc texture2DLod didn't work on TwisterGE old computer: https://www.opengl.org/sdk/docs/man4/html/textureLod.xhtml (doesn't work on VERSION < 130)

Please sign in to comment.