Jump to content
  • Advertisement

Help with oblique near plane for reflection pass

Recommended Posts

I'm currently working on adding a reflective surface to my project. I have most of it down and working properly, but I am struggling with a technique I've read about online (and which seems to be widely used). I'm referring to this technique: "Modifying the Projection Matrix to Perform Oblique Near-Plane Clipping". Without the technique, I'm able to render my reflective surface correctly, but only if I delete all of the objects behind the reflection plane. I'm aware that I could add some code into my pixel shader to clip fragments that are behind the custom clipping plane, but I'd like to avoid doing that if I can.

Without the oblique near plane: https://i.imgur.com/ZxnwKNX.jpg

I've followed several different versions of the technique linked above, but I can't seem to get it right. Invariably, I end up with weird distortions like this:


The last little "preview image" at the top shows the rendered reflection view. You can see that the reflected view is completely warped, and stretches out infinitely rather than just having a regular upside-down perspective.

The function that modifies the projection matrix is really small, so I'm not sure where my mistake is. The one thing I've modified from the link above is I am scaling the clip plane by (1 / dot(clip, q)) instead of (2 / dot(clip, q)), and removed a +1 at the end, because I am using a [0, 1] clip space. I've seen this mentioned in some places online. Regardless, it doesn't help to change that back. Can anyone point me in the right direction here? The relevant code can be seen here. Any help would be much appreciated.

Share this post

Link to post
Share on other sites

Are you using OpenGL or D3D (because they use different projection matrices)?

The article that you linked is based on the GL format (which maps near to -1 and far to +1), so if you're using a D3D style projection matrix (which maps near to 0 and far to +1), perhaps this is what's leading to the craziness. If so, you could convert your matrix to GL style, perform the oblique modification, and then convert it back to D3D style :D

[edit] Sorry, I missed the part where you mention these differences!!

Share this post

Link to post
Share on other sites

@Hodgman I am indeed using a D3D style matrix. I mentioned at the end that I made a couple of modifications that are supposed to account for those differences, which I found from some older discussion threads. I suppose I can go the whole way and try to start with a GL-style matrix and see if it helps.


EDIT: Hrm, using a GL-style matrix didn't seem to affect the results much.

Edited by mellinoe

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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!