[Solved] How to render a mesh that has passed across the view plane?
Now I want to achieve the same thing using Direct3D9 APIs for better performance,but I found the view plane is considered the same plane as the near clip plane acquiescently in its pipeline process,which causes any primitive passes across the view plane will be clipped.So I wonder if it's allowed to toggle the near clipping process off and if there are tricks to render the primitive that passes across the view plane.Thanks!
I think you may be looking for:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb172599%28v=vs.85%29.aspx
D3DRS_CLIPPLANEENABLE
Enables or disables user-defined clipping planes. Valid values are any DWORD in which the status of each bit (set or not set) toggles the activation state of a corresponding user-defined clipping plane. The least significant bit (bit 0) controls the first clipping plane at index 0, and subsequent bits control the activation of clipping planes at higher indexes. If a bit is set, the system applies the appropriate clipping plane during scene rendering. The default value is 0. The D3DCLIPPLANEn macros are defined to provide a convenient way to enable clipping planes.
Note: there is also D3DRS_CLIPPING
I've never toyed around with turning off clip planes myself, so not sure how well this is supported across the various cards. However, I would suggest leaving the clip planes on and tackle your problem another way if possible. A couple of suggestions off the top of my head are:
- Adjust your near view clipping plane to be smaller/closer, which will allow you to render meshes closer to the camera as needed.
- Or you can try to add a hack w-offset amount to the mesh positions as you render them, which would push/pull them away from the camera along the view vector when rendering them.
Also If you havent seen so already, here is the breakdown of how the viewport works in the Direct3D 9 API. It may give you a better idea of how the viewport is setup and functions: http://msdn.microsoft.com/en-us/library/windows/desktop/bb206341%28v=vs.85%29.aspx
IIRC, D3D9 has no way to disable the near clip, but D3d10/11 do... But the near clip is usually so close to the tip of the frustum (tip of the pyramid made by the side/top/bottom planes), that meshes closer than the near plane would often be inverted inside out if not clipped!
I'm assuming you are calling the view plane the same plane where the view would flip, and the near clip plane as the plane where everything that is 'behind' the clip plane gets clipped. The good news is that you can control where the clip plane is - it is completely a construct of your perspective matrix. Basically your perspective matrix will transform the object's vertices in such a way that if they should be visible then the z-coordinate will be between 0 and 1 (after divide by w). If the z-coordinate falls outside this range, then the vertex gets clipped, and any polygons that it is a part of get clipped too.
So if you want make it so that your geometry doesn't get clipped at all, then just ensure that your post-divide z value is between 0 and 1 at the output of the vertex shader. This could be all of the geometry in the entire scene, even the items that are behind your viewing plane (as Hodgman said, they will be upside down unless you clip them...).
I'm curious - what has clipping things at the near plane got to do with stereoscopic vision?
Maybe his algorithm works with the mesh rendered at zero depth (center of the mesh), so that some parts of it are in front of the near clipping plane? I have no idea, that's just a guess.
In this case it would probably be best to modify it to work with any depth, to be able to use the 0-1 depth range (between near and far clipping planes).
This is a picture shows the visual effect of that demo.You can see part of the teapot is seems to be "outside" the screen(view plane).To achieve this,I have to find a way to render the "outside" part instead of clipping .However, the DirectX API will arbitrarily clip any primitive that behind the view plane, which is the major problem.Any one can give some suggestions please.
Or you can try to add a hack w-offset amount to the mesh positions as you render them, which would push/pull them away from the camera along the view vector when rendering them.
Hi, groverman! I've read your suggestions?I think your idea about adding a hack w-offset amount might be an executable way.But I get no idea how to push/pull three vertices (the triangle) at the same time in a vertex shader.So would you mind giving further explanation?