Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problems with computing reflection vector

Started by megav0xel Feb 18, 2017 at 8:08 AM 1 replies 2.4k views
Original Post
megav0xel
megav0xel

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.

BBeck
BBeck

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?

deftware
deftware

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.

[ deftware.org ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.