Clipping planes with programmable pipeline

Started by
6 comments, last by pickups 19 years, 11 months ago
hello. i need to use user defined clip planes, and i want to include pixel and vertex shaders. now, from the docs, i see that when using pixel/vertex shaders, the clip planes are defined in clip space. i searched through the docs, to try and figure out what is clipping space, but the only helpfull words i found, is, that when using vertex shaders the world space and clipping space are the same, and somewhere else, i saw that clipping space is where the vertices reside after transformations, ie. in the output register. this doesnt mean the same as the previous statement. so my question is, how should i define the clip planes? how should i transform them to clip space? multiply the plane equation with a projection matrix? thnx.
Advertisement
ok. so you dont know.
do you know whether the clip planes equation are transformed by the some matrix, or should i transfrom it myself?
iirc you should multiply the plane by view*projection.
Homogeneous clip-space is the one vertices are transformed to using the worldViewProjection matrix. So, I think you should do as AP said.

Peace,
Muhammad Haggag

hello. sorry for the delay.
thanx for the answers.
i tried multiplying the plane equation with the W*V*P matrix i use for rendering. but it doesnt work, i can see some clipping but not in place. maybe i should transpose or inverse the matrix? i tried, but it didnt work, maybe i did the wrong thing.
any ideas?
Hi, I''ve got exactly the same problem. I use the D3DXPlaneFromPoints function to create the points for the general plane equation. Before using that funtion I multiply the points (0,0,0), (0,0,1) and (1,0,0) with my WVP matrix. First the result looks good, but when I turn the camera about 90 degrees or so the plane seems to flip. The geometry on the other side of the plane is clipped.
*push*

No one got an idea?
** I REALISE THIS THREAD IS QUITE OLD **


anyway. I''ve been trying to find a solution to this exact problem all day... Couldn''t find anything on the web, so I did it by trial-and-error.. This is what I got, some people may find it quite useful:

D3DXPLANE CDirect3DRenderer::projectPlaneToClipSpace(D3DXPLANE plane, D3DXMATRIX view, D3DXMATRIX projection){	const D3DXVECTOR3 x(-10,0,0), y(0,-10,0), z(0,0,-10), zero(0,0,0);	D3DXVECTOR3 planeNorm(plane.a,plane.b,plane.c);	D3DXVECTOR3 p1=planeNorm*-plane.d;	D3DXVECTOR3 p2,p3,p4;	D3DXVec3Cross(&p2,&x,&planeNorm);	D3DXVec3Cross(&p3,&y,&planeNorm);	D3DXVec3Cross(&p4,&z,&planeNorm);	if (p2==zero)		p2=p4;	else		if (p3==zero)			p3=p4;	p2+=p1;	p3+=p1;	D3DXVECTOR4 dp1(p1.x,p1.y,p1.z,1);	D3DXVECTOR4 dp2(p2.x,p2.y,p2.z,1);	D3DXVECTOR4 dp3(p3.x,p3.y,p3.z,1);	D3DXVECTOR4 dpOut1,dpOut2,dpOut3;	D3DXVec4Transform(&dpOut1,&dp1,(D3DXMATRIX*)&view);	D3DXVec4Transform(&dp1,&dpOut1,(D3DXMATRIX*)&projection);	D3DXVec4Transform(&dpOut2,&dp2,(D3DXMATRIX*)&view);	D3DXVec4Transform(&dp2,&dpOut2,(D3DXMATRIX*)&projection);	D3DXVec4Transform(&dpOut3,&dp3,(D3DXMATRIX*)&view);	D3DXVec4Transform(&dp3,&dpOut3,(D3DXMATRIX*)&projection);	dp1/=dp1.w;	dp2/=dp2.w;	dp3/=dp3.w;		D3DXPlaneFromPoints(&plane,(D3DXVECTOR3*)&dp1,(D3DXVECTOR3*)&dp2,(D3DXVECTOR3*)&dp3);	if ((dpOut1.z>0) ^ (dpOut2.z>0) ^ (dpOut3.z>0))		plane*=-1;	return plane;}


| - My project website - | - email me - |

This topic is closed to new replies.

Advertisement