Skip to main content
GameDev.net gamedev.net
🔒 Locked

water reflection problem

Started by flery Sep 10, 2006 at 2:49 AM 6 replies 1.8k views
Original Post
flery
flery
Hi, i have a problem with my water reflections. it seems i dont get it to work correctly. to explain the problem better i made a video of the RTT reflection map and the result of using it. download videos as you can see in the screenshots the white object is reflected correctly (at least i think so) but the top of the grasshill is displayed totally wrong. the vertex/pixel shader displaying the texture:

//vs    
OUT.position = mul(float4(IN.position.xyz ,1.0), ModelViewProj);

OUT.project.x = 0.5 * (OUT.position.w + OUT.position.x);
OUT.project.y = 0.5 * (OUT.position.w - OUT.position.y);
OUT.project.z = OUT.position.w;

//ps
float2 projcoord = (IN.project.xy / IN.project.z);
float4 reflect = tex2D(texSampler0, projcoord.xy);

OUT.color = reflect;

the camera reflection

    D3DXMATRIXA16 matView;	
	D3DXMATRIXA16 matRef;
	D3DXPLANE	ReflectionPlane;
	ReflectionPlane.a = 0;
	ReflectionPlane.b = 0;
	ReflectionPlane.c = 1;
	ReflectionPlane.d = 0;

	D3DXMatrixIdentity(&matRef);
   
	pd3dDevice->GetTransform( D3DTS_VIEW, &matView );
	D3DXMatrixReflect(&matRef, &ReflectionPlane);
	

    D3DXMatrixMultiply(&matView2, &matRef, &matView);
    pd3dDevice->SetTransform( D3DTS_VIEW, &matView );



i hope someone has an idea i tried the whole night without any major success... mfg flery
flery
flery
i kind of found the explaination for the problem myself the reflection is correct if the camera is on the same level as the water. if anyone has a quick suggestion how to fix this...
probably a simple matrix error.

mfg
flery
Matt Aufderheide
Matt Aufderheide
Just some quick questions:

is your water plane on 0,0,0 ? Becasue your reflect plane is set up that way...

Are you reversing culling when rendering the reflection?

Are you setting up your clipping plane?
flery
flery
>> is your water plane on 0,0,0 ? Becasue your reflect plane is set up that way...

yes

>> Are you reversing culling when rendering the reflection?

yes

>> Are you setting up your clipping plane?

void f3dCamera::SetupProjectionMatrixA1(){    D3DXMATRIXA16 matProj;    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, fNearPlane, fFarPlane );    pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );}

hope thats what you ment :)

here a little sample application use 'w' and 'a' to switch to problem camera postion and back. Download
Matt Aufderheide
Matt Aufderheide
well by clipping plane I meant the water reflections clipping plane.. you have to have a clipping plane set at the water level or reflections wont render right..when you render your reflections, enable the a clipping plane to clip out everything above the water.

I tried your demo and i'm certain that this is your problem. you can eitehr us e ahardware clipping plane or do it in a pixel shader, which is easier.

herese an exmaple from my code..this clips everythign above 0:

D3DXVECTOR3 point(0, 0, 0 );
D3DXVECTOR3 normal(0, -1, 0 );
D3DXPLANE clipplane;
D3DXPlaneFromPointNormal( &clipplane, &point, &normal );

pd3ddev->SetClipPlane(0, clipplane );
pd3ddev->SetRenderState(D3DRS_CLIPPLANEENABLE,D3DCLIPPLANE0);
flery
flery
i'll test thx for the fast answer
flery
flery
thanks very very much .... :)
jamesw
jamesw
Quote:
D3DXVECTOR3 point(0, 0, 0 );
D3DXVECTOR3 normal(0, -1, 0 );
D3DXPLANE clipplane;
D3DXPlaneFromPointNormal( &clipplane, &point, &normal );

pd3ddev->SetClipPlane(0, clipplane );
pd3ddev->SetRenderState(D3DRS_CLIPPLANEENABLE,D3DCLIPPLANE0);


You have to specify the clip plane in clip space when used with a shader.

Clip space transform topic

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.