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

Water Reflection

Started by Grigou Sep 1, 2008 at 7:17 AM 1 replies 1.2k views
Original Post
Grigou
Grigou
Hi, I've been working on a HLSL water shader for my engine, everything is working fine except when it comes to reflecting the skybox.... I am using render to textures and user clip planes to generate the reflection and refraction textures. Landscape and meshes are reflected perfectly but the skybox doesn't appear on the reflection texture. I think the problem is rendering the skybox with the reflection view matrix... This is how I render the skybox :

D3DXMatrixTranslation(&mWorld,CDXObjects::Instance().getCameraPosition()->x,CDXObjects::Instance().getCameraPosition()->y,CDXObjects::Instance().getCameraPosition()->z);
CDXObjects::Instance().setWorldMatrix(mWorld);  
CDXObjects::Instance().getDevice()->SetFVF(SBVertex::FVF);
CDXObjects::Instance().getDevice()->SetStreamSource(0,vBuffer,0,sizeof(SBVertex));	TLfx2->SetMatrix(hWorldViewProj,CDXObjects::Instance().getWorldViewProj());
TLfx2->Begin(NULL,0);
for (unsigned int i=0;i<6;++i)
{
	TLfx2->BeginPass(0); 
        CDXObjects::Instance().getDevice()->SetTexture(0,SBTex);
   CDXObjects::Instance().getDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP,i*4,2);
	TLfx2->EndPass(); 
}
TLfx2->End();

For reflection the view matrix is replaced by the reflection view matrix. These are the render states for the shader :

technique main
{
	pass p0
	{
		vertexshader = compile vs_1_1 VShader();
		pixelshader = compile ps_2_0 PShader();
		LIGHTING = FALSE;
		ZENABLE = FALSE;
		ZWRITEENABLE = FALSE;
		CULLMODE = NONE;
	}
}

If someone has an idea.... Thanks
jollyjeffers
jollyjeffers
Have you checked the winding order? I remember having a similar sounding problem when I implemented this algorithm - the reflected geometry was getting culled due to being back-facing. Try D3DRS_CULLMODE = D3DCULL_NONE to see if it appears.

Failing that, stepping through in PIX can be very useful to figure out when and why something isn't being rendered.

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Grigou
Grigou
Hi,
First of all, thanks for your reply.
So I tried messing arround with culling but it didn't change anything...
I think the problem comes from the reflection view matrix and translating the skybox for it to follow the player.
This is how I calculate the reflection view matrix :
void CCamera::computeReflectionViewMatrix(){	D3DXPLANE p;	D3DXMATRIX * tmp = DXObjects::Instance().getViewMatrix();        D3DXMatrixIdentity(&mReflecView);D3DXPlaneFromPointNormal(&p,&D3DXVECTOR3(0.0f,CDXObjects::Instance().getWaterHeight(),0.0f),&D3DXVECTOR3(0.0f,1.0f,0.0f));	D3DXMatrixReflect(&mReflecView,&p);	mReflecView = mReflecView * (*tmp);	CDXObjects::Instance().setReflectionViewMatrix(mReflecView);  }


Thanks

Topic Locked

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

Sign in to reply to this topic.