Jump to content
  • Advertisement
Sign in to follow this  
megav0xel

Problems with computing reflection vector

This topic is 602 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

Hi all.

 

I encountered a weird bug when computing screen space reflection vector for my SSR feature.

 

Here is a plane facing toward my camera. Color indicates the reflection vector in screen space. Everything works fine currently.

MWOjMdI.jpg

 

When I put my camera closer to the plane, suddenly the reflection vector in the center of the screen will get "mirrored", as shown by the following picture

TRk9I4c.jpg

Here is my code in GLSL. 

    vec3 csDir=normalize(reflect(csPos,csNormal));
    vec4 psPos = ProjectionMatrix * vec4(csPos, 1.0f);
    vec3 ndcsPos = psPos.xyz / psPos.w;
    vec3 ssPos = 0.5f * ndcsPos + 0.5f;

    csDir +=csPos;
    vec4 psDir = ProjectionMatrix * vec4(csDir, 1.0);
    vec3 ndcEndPoint = psDir.xyz / psDir.w;
    vec3 ssEndPoint = 0.5f * ndcEndPoint + 0.5f;

    vec3 ssDir=normalize(ssEndPoint-ssPos);

Any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement

I would not know short of running it in a debugger. But are you sure you're not crossing through the plane of reflection? I believe all reflection is is reversing the sign from positive to negative or vice-versa on one axis. So, if you were to cross to the other side of the plane you would get the opposite results. Is the plane of reflection on the same plane as the triangle you are drawing on?

Share this post


Link to post
Share on other sites

Have you tried outputting csDir to the fragment to see if that is in fact correct? I just managed to get SSR running in my game project a few weeks ago after some tumultuousness.

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!