Question regarding planes - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Question regarding planes (/thread-2496.html)
Question regarding planes - TomorrowPlusX - Jul 31, 2008 05:42 AM
I'm debugging my code for trimming near and far planes for shadow mapping ( to increase precision ) and as far as I can tell, my math is all wrong.
I'm trimming near and far by creating a plane passing through the camera's origin, facing in the same direction as the camera. Then, by checking the distance of the objects being rendered against this plane, I expand/contract my far/near values. Later, those values are used to build the projection matrix. Obviously, I'm not using the rendered entities' positions, but rather bounding spheres. You'll see below.
The trouble is, it's looking like my math for creating that reference plane is wrong.
I adapted this code -- IIRC -- from some NVIDIA sample code. It's a constructor for my plane class which creates a plane facing along a normal passing through a point.
And here's my code to check the distance of a point from the plane:
This is a snippet of my code for trimming near and far for a depth pass:
Does anything look obviously wrong? I'm getting negative values, and the values don't seem to always make sense. My gut reaction is that my 'cameraPlane' is not what I want it to be: e.g., a plane passing through the camera's position facing the same direction as the camera.
Question regarding planes - TomorrowPlusX - Jul 31, 2008 05:55 AM
I've gotten it to work by inverting cameraPlane.d...
This tells me I've got something wonky in my plane maths. Any suggestions?
Question regarding planes - Fenris - Jul 31, 2008 04:43 PM
No, that's correct, the plane's D value is defined as -dot(n, point). Remember, Ax + By + Cz + D = 0.
(So you should invert all planes' d values.)
Question regarding planes - DoG - Aug 1, 2008 02:38 AM
I always prefered not to use the plane equation, and just do the vector algebra. Namely, if N is your normal, P is the point on the plane, and X is the point you're checking,
then the signed distance is d = (X-P) dot N
Admittedly, this means two additional operations in this form, but if refactored into d = X dot N - P dot N, you pretty much have the plane equation. Except that it's not a,b,c,d, but meaningfully named components