• 11
• 9
• 10
• 9
• 11

How to deal with perpective projection issue in reflection shader

This topic is 746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I was playing around with some shader code when I ended up with something that seemed to be working rather well as a reflection shader. However it has artifacts near the camera due to the transformation by the projection matrix, however, if the transformation is not there, while the artifact is gone, the reflections are no longer perspective correct. I'm not sure how to deal with this.

Code:

#version 430 core

in vec2 UV;

layout(location = 0) out vec4 reflection;

uniform sampler2D colorMap;
uniform sampler2D normData;
uniform sampler2D specularData;
uniform sampler2D worldData;
uniform sampler2D envMap;
uniform sampler2D depthMap;
uniform vec3 EyePos;
uniform mat4 View;
uniform mat4 Projection;

void main(){
vec3 n = 2.0 * texture2D(normData, UV).xyz - 1.0;
n = normalize(n);
vec3 worldCoord = texture2D(worldData, UV).rgb;
vec3 v = EyePos - worldCoord;
v = normalize(-v);
float depth = texture2D(depthMap, UV).r;

vec4 vis = vec4(0);
vec3 refNorm = (Projection * View * vec4(reflect(v, n), 0)).rgb;
refNorm = 0.5 * refNorm + 0.5;
vis = texture2D(colorMap, refNorm.xy);
reflection = vis;
}


Without Projection matrix:

http://i.imgur.com/FUxqgdy.png

With Projection Matrix:

http://i.imgur.com/Q2jsnxC.png

The artifact kind of gets hidden as I start to move faster, but it'd still be nice to get rid of it. Just had the thought while writing the question, is the artifact possibly due to missing information?

Edited by HimanshuGoel97

Share on other sites

Looks like nearest-neighbor sampling on your reflection map. Change your filter type to linear.