Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


[Solved] How to render a mesh that has passed across the view plane?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 Bunker   Members   -  Reputation: 151

Like
0Likes
Like

Posted 09 June 2014 - 05:16 AM

I wrote a demo before, it's a software renderer that renders a teapot which partly passes across the screen(view plane).The program tracks my eye's position and then correct the perspective projection in real-time,so it is able to render a stereoscopic scene on an ordinary LCD screen.
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!

Sponsor:

#2 groverman   Members   -  Reputation: 168

Like
0Likes
Like

Posted 09 June 2014 - 02:22 PM

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


Edited by groverman, 09 June 2014 - 02:22 PM.


#3 Hodgman   Moderators   -  Reputation: 31926

Like
0Likes
Like

Posted 09 June 2014 - 03:58 PM

What do you mean by view plane? I don't thing this concept exists in D3D, so you should be able to use a near plane that's at your users eye and then say the view plane is wherever you want it to be.

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!

#4 Jason Z   Crossbones+   -  Reputation: 5395

Like
0Likes
Like

Posted 09 June 2014 - 05:47 PM

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...).



#5 Aardvajk   Crossbones+   -  Reputation: 6239

Like
0Likes
Like

Posted 10 June 2014 - 01:32 AM

I'm curious - what has clipping things at the near plane got to do with stereoscopic vision?



#6 Tom KQT   Members   -  Reputation: 1622

Like
0Likes
Like

Posted 10 June 2014 - 01:37 AM

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).



#7 Bunker   Members   -  Reputation: 151

Like
0Likes
Like

Posted 10 June 2014 - 05:23 AM

http://b236.photo.store.qq.com/psb?/V107xbRs1mVv6O/K1tJMuSembFHoemkDGwPBiPMFTetICWwD*N0HwxmECY!/c/dKUQuoxPBgAA&bo=VQOAAkAGsAQBAAE!&rf=mood_app

 

 

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.smile.png

 


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?



#8 Aardvajk   Crossbones+   -  Reputation: 6239

Like
0Likes
Like

Posted 10 June 2014 - 05:34 AM

That image link is dead, by the way. Doesn't matter, I was just curious.



#9 Bunker   Members   -  Reputation: 151

Like
0Likes
Like

Posted 10 June 2014 - 05:59 AM

Demo.jpg

 

Thanks for telling me.This link should be okay.



#10 Aardvajk   Crossbones+   -  Reputation: 6239

Like
0Likes
Like

Posted 10 June 2014 - 09:39 AM

Demo.jpg
 
Thanks for telling me.This link should be okay.


Thanks. That's really cool. How are you tracking the eye?

#11 Jason Z   Crossbones+   -  Reputation: 5395

Like
0Likes
Like

Posted 10 June 2014 - 08:15 PM

Now I can see what you meant :)

 

What you are actually doing is rendering the scene from the point of view of the person sitting in front of your monitor, and then projecting that rendered image onto the window coordinates.  That actually doesn't have to be messed up by the clipping planes, since you can just use your clipping plane close to the actual viewer (and hence it wouldn't get anywhere near your teapot...).



#12 Tom KQT   Members   -  Reputation: 1622

Like
1Likes
Like

Posted 11 June 2014 - 01:49 AM

Demo.jpg

 

Thanks for telling me.This link should be okay.

 

I did something very similar 5 years ago (picture) and all the magic with projection was done very simply by using D3DXMatrixPerspectiveOffCenterLH to create the projection matrix. Try to look at this D3DX function ;)



#13 Bunker   Members   -  Reputation: 151

Like
0Likes
Like

Posted 11 June 2014 - 01:53 AM

I thought the concepts of the near clipping plane and the view plane(or projection plane) are unified in DirectX's world before,but they're not actually. The view plane are set to z = 1 while the near clipping plane are adjustable. So it's possible to adjust the near clipping plane while keeping the view plane unmoved.

 

I searched MSDN for the functions that can be used for generating projection matrix, there are two of them:

The first one is commonly used. The second one is which I am using because the point of view is movable in my projection model so the matrix will be offcenter.

 

Details as follows:

D3DXMATRIX* D3DXMatrixPerspectiveFovLH(
  _Inout_  D3DXMATRIX *pOut,
  _In_     FLOAT fovy,
  _In_     FLOAT Aspect,
  _In_     FLOAT zn,
  _In_     FLOAT zf
);


D3DXMATRIX* D3DXMatrixPerspectiveOffCenterLH(
  _Inout_  D3DXMATRIX *pOut,
  _In_     FLOAT l,
  _In_     FLOAT r,
  _In_     FLOAT b,
  _In_     FLOAT t,
  _In_     FLOAT zn,
  _In_     FLOAT zf
);

These two functions compute the returned matrices as shown:

 

  • D3DXMatrixPerspectiveFovLH
xScale     0          0               0
0        yScale       0               0
0          0       zf/(zf-zn)         1
0          0       -zn*zf/(zf-zn)     0
where:
yScale = cot(fovY/2)

xScale = yScale / aspect ratio 

Parameter zn represents the position of the near clipping plane,while FOV is determined by fovy.

 

  • D3DXMatrixPerspectiveOffCenterLH
2*zn/(r-l)   0            0              0
0            2*zn/(t-b)   0              0
(l+r)/(l-r)  (t+b)/(b-t)  zf/(zf-zn)     1
0            0            zn*zf/(zn-zf)  0

In this matrix, zn determines both the near clipping plane and FOV. To keep FOV unchanged while zn is changing, I have to adjust the size of the view volume at the same time.

Tell me if I am wrong.

 

 


Thanks. That's really cool. How are you tracking the eye?

 

Well,I use a Kinect to track the eye.



#14 Bunker   Members   -  Reputation: 151

Like
0Likes
Like

Posted 11 June 2014 - 02:06 AM

 


Demo.jpg
 
Thanks for telling me.This link should be okay.

 
I did something very similar 5 years ago (picture) and all the magic with projection was done very simply by using D3DXMatrixPerspectiveOffCenterLH to create the projection matrix. Try to look at this D3DX function ;)
 

That's awesome.It could be better if the cup is "outside" the screen.

#15 Aardvajk   Crossbones+   -  Reputation: 6239

Like
0Likes
Like

Posted 11 June 2014 - 10:48 AM

I must confess, I thought this was another raving lunatic post when I read the OP. We have had a spate of them recently.

Glad I was wrong. This stuff looks fascinating.

#16 Bunker   Members   -  Reputation: 151

Like
2Likes
Like

Posted 11 June 2014 - 07:25 PM

Problem Solved! After calling D3DXMatrixPerspectiveOffCenterLH,I simply divide the elements M(0,0) and M(1,1) by zn in the output matrix to make the view plane come back to z=1. Now it looks just fine! Maybe I didn't describe my problem properly since it's my first time to post in English. Anyway,thank you guys here for helping so much :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS