Advertisement Jump to content
Sign in to follow this  

Problems with computing reflection vector

This topic is 701 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.



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


Here is my code in GLSL. 

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

    csDir +=csPos;
    vec4 psDir = ProjectionMatrix * vec4(csDir, 1.0);
    vec3 ndcEndPoint = / 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

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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!