Jump to content
  • Advertisement
Sign in to follow this  
hgoel0974

How to deal with perpective projection issue in reflection shader

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

I'm sorry, I should have been more clear, I was referring to the circle like area where the reflection is suddenly different around the ship.

The changing filter type idea did give me the idea to see if that was due to missing information by disabling texture wrapping, which did eliminate the issue, sort of, it replaced the circle with stretching, which works better.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!