Sign in to follow this  
angelmu88

Clip plane problem

Recommended Posts

angelmu88    228
Hi!
I'm currently working on creating a reflection map for the water, and I'm using a clip plane so that I can only draw into the texture the geometry above the water.
Here's is my code:
[CODE]
D3DXPLANE refractionClipPlane;
D3DXVECTOR3 point(0.0f, 6.0f, 0.0f);
D3DXVECTOR3 normal(0.0f, 1.0f, 0.0f);
D3DXPlaneFromPointNormal(&refractionClipPlane,&point,&normal);
D3DXMATRIX inver;
D3DXMatrixInverse(&inver,0,&(mView*mProj));
D3DXMATRIX trans;
D3DXMatrixTranspose(&trans,&inver);
D3DXPLANE outRefraction;
D3DXPlaneTransform(&outRefraction,&refractionClipPlane,&trans);
refractionMap->beginScene(); //refraction map is a renderTarget
gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
gd3dDevice->SetClipPlane(0, outRefraction);
gd3dDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0);
drawReflectedByWater(); //draw geometry
gd3dDevice->SetRenderState(D3DRS_CLIPPLANEENABLE,0);
refractionMap->endScene(); //render target ends
[/CODE]

I have this problem, if I only move the camera's position DirectX draws the scene perfectly:
[left][url="http://imageshack.us/photo/my-images/842/clipplaneproblem1.jpg/"]http://imageshack.us...neproblem1.jpg/[/url][/left]


But if I change the camera look vector, for instance, if I aim the camera to the sky the clip plane moves along with te camera too:
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]http://imageshack.us/photo/my-images/696/clipplaneproblem2.jpg/[/left][/size][/font][/color]

As you can see from my code, I've taken into account that if you are not using the fixed pipeline the plane has to be in clipspace coordinates.
Anyone knows what can I do in order to avoid this problem (plane moving along with the camera)?

Share this post


Link to post
Share on other sites
angelmu88    228
[quote name='angelmu88' timestamp='1329567998' post='4914169']
Hi!
I'm currently working on creating a reflection map for the water, and I'm using a clip plane so that I can only draw into the texture the geometry above the water.
Here's is my code:
[CODE]
D3DXPLANE refractionClipPlane;
D3DXVECTOR3 point(0.0f, 6.0f, 0.0f);
D3DXVECTOR3 normal(0.0f, 1.0f, 0.0f);
D3DXPlaneFromPointNormal(&refractionClipPlane,&point,&normal);
D3DXMATRIX inver;
D3DXMatrixInverse(&inver,0,&(mView*mProj));
D3DXMATRIX trans;
D3DXMatrixTranspose(&trans,&inver);
D3DXPLANE outRefraction;
D3DXPlaneTransform(&outRefraction,&refractionClipPlane,&trans);
refractionMap->beginScene(); //refraction map is a renderTarget
gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
gd3dDevice->SetClipPlane(0, outRefraction);
gd3dDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0);
drawReflectedByWater(); //draw geometry
gd3dDevice->SetRenderState(D3DRS_CLIPPLANEENABLE,0);
refractionMap->endScene(); //render target ends
[/CODE]

I have this problem, if I only move the camera's position DirectX draws the scene perfectly:
[left][url="http://imageshack.us/photo/my-images/842/clipplaneproblem1.jpg/"]http://imageshack.us...neproblem1.jpg/[/url][/left]


But if I change the camera look vector, for instance, if I aim the camera to the sky the clip plane moves along with te camera too:
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][url="http://imageshack.us/photo/my-images/696/clipplaneproblem2.jpg/"]http://imageshack.us...neproblem2.jpg/[/url][/size][/font][/color][/left]


As you can see from my code, I've taken into account that if you are not using the fixed pipeline the plane has to be in clipspace coordinates.
Anyone knows what can I do in order to avoid this problem (plane moving along with the camera)?
[/quote]

Ok, I solved it, it has to do with the graphic card, I had to reset de clipplane, here is the solution:
[url="http://www.gamedev.net/topic/523062-setclipplane-and-nvidia-drivers/"]http://www.gamedev.net/topic/523062-setclipplane-and-nvidia-drivers/[/url]

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this