Jump to content
  • Advertisement
Sign in to follow this  
xycsoscyx

User Defined Clip Planes

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

Back to mirrors, oy! XD First off, thanks to all the help from everyone, I'm gonna post some screen shots and full source code sooner or later, once I finish up a few things. Now onto the question. I want to use user defined clip planes to clip rendering at the mirror plane. I want to use them over the "clip" instruction because the user defined clip planes happen before the pixel program process, so it can save a bit of time (especially for expensive rendering). As it is, I know I have to Invert then Transpose my transformation matrix, then transform the plane by it, all because I am using vertex and pixel programs (is it actually only one or the other?).
		GEKPLANE kPlane(m_kClipPlane);

		GEKMATRIX4 kTransform(m_pkCurrentViewer->eye.transform);
		kTransform.Inverse();
		kTransform.Transpose();
		kPlane = kTransform.Transform(kPlane);

		m_pkEngine->m_pkVideo->SetClipPlane(0, kPlane);
		m_pkEngine->m_pkVideo->SetRenderState(GEKRS_CLIPPLANES, GEKCP_ENABLE(0));
The Transform function is copied right from D3DX, it's the formula for transforming a plane by a matrix. When I do this for the regular camera (I use the cameras X axis as a normal, and origin as a point, and construct a plane from that), it works correctly. The scene is only rendered on one half of the screen, sweeeeet. As a note, the eye.transform matrix is just the standard (View * Project) total. So for rendering the regular world, this all works fine. Now for the kink in the chain, when I try to do this when I'm rendering a mirror, it goes fubar (so far, I can't really tell what's wrong with it). My transform matrix for mirrors is (Reflect * View * Project), where View and Project are same as before, but Reflect is a reflection matrix generated from the mirror plane. Soooo, am I missing something here? I've tried not having the Reflect matrix in the total, doing it a matrix at a time (this works fine, too, for the regular camera), etcetc. So I need to modify the plane or something before hand, THEN transform it to clip space? Am I just way off? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Whoops, I just noticed that I posted this in the general graphics forum, I should have posted it in the DirectX forum instead. Anyways, someones got to know what's going on, I'm sure many people have gotten user defined clip planes to work when rendering mirrors.

Share this post


Link to post
Share on other sites
Like I said, it works for regular rendering of the scene, but not when rendering the reflection (when the view matrix is the combined (Reflect * OriginalView). For the regular scene, I can clip anywhere correctly, and it will be transformed to clip space properly. When rendering the reflection scene, it goes fubar, the thread you linked to says about the regular "transforming a plane into clip space", but doesn't mention specifically about the reflected scene (unless I missed something).

Share this post


Link to post
Share on other sites
Hmm, now that I have power again (I live in Washington, power was out for three days, PLUS I had to replace my power supply 'cause it seems to have blown when power was restored). Anyone have any thoughts on this? It's really bugging me 'cause I can't seem to wrap my head about what's going on (math-wise) even. :( Sad panda am I!

Share this post


Link to post
Share on other sites

Could you be more specific about what 'Goes fubar' means? Does it not clip or does it clip the wrong way? Pics might help.

Share this post


Link to post
Share on other sites
That's the thing, I can't quite tell what it's doing, to be honest. It's not backwards rotation or anything simple, I'll have to redesign a scene to make it visible (the current scene has the back of the mirror in the way when things don't clip properly), then I can take some pics. Basically, if I transform the plane normally (transform by the transpose of the inverse of the matrix), then nothing is rendered in my reflection.

It SEEEEEMS that it's just the wrong direction, that it's cliping at the right distance, but wrong direction. If I try to reverse my normal, then I see that the direction becomes wrong (reversed, like it should since I just reversed the direction), but the distance (which I didn't touch) is wrong, it's the other side of the room (reverse distance) that the plane is located at.

Like I said, I'll try to redesign the room a bit to show (hopefully) what I am seeing.

Share this post


Link to post
Share on other sites
I remember having problems setting up clip planes once because I assumed it used the a*N.x + b*N.y + c*N.z = d plane equation, but dx really uses a*N.x + b*N.y + c*N.z + d = 0, so try keeping your normal the same and just flip d. Hooking up a slider to tweak the d can help you get a better idea of what's going on quickly.

Share this post


Link to post
Share on other sites
Wow, I figured out what's going on, and I have no idea how to fix it (and it kinda means I can't actually show what's going on). Basically, if the camera is behind the clip plane, nothing is rendering (at all). I need to see if I'm intentionally doing that (and just completely didn't notice in my engine), but has anyone else encounterd that issue before? It's clipping properly aside from that (when I reverse the plane normal, it clips it properly the other way, but when it's facing the way it should be, the camera should always be behind it, so for some reason nothing renders).

James, thanks for the suggestion to add a slider, that helped me figure out what was going on, now if I can just solve it. :D

Share this post


Link to post
Share on other sites
Okay, here are some screenshots, fuuuubar. At extreme angles, it all goes funky and things are way off, from straight on, the clipping plane seems correct (the normal, but not the distance). I really have no idea what's going on in the shots here, where the clipping plane seems to affect the transformation itself for a small slice on the mirror! XD

Other then that is the issue that it still seems to overclip. If the camera is behind the clipping plane, then everything is clipped, not just the pixels behind the plane?




edit: Whoops, wrong HTML for images. :D

[Edited by - xycsoscyx on December 19, 2006 12:44:15 PM]

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!