Sign in to follow this  

Projecting Textures in DirectX 9

Recommended Posts

Hi everyone. Im trying to project a reflection of my terrain/objects in my water. * Iv'e got the reflected geometry saved in a texture correctly. * Now I'm trying to project that texture on to my water quad. The problem is that the projection comes out tiled or the projection position doesnt quite match with the geometry positions. Also, when I move the camera the projection moves too. When I rotate the reflections dont match the geometry( they seem to rotate around some point on the texture ). I've looked on the net but only found some small code snippets that didn't really help. Heres my setup code:
	//refix/clamp matrix
	D3DXMATRIX bias( 0.5f, 0.0f, 0.0f, 0.0f,
	                 0.0f, 0.5f, 0.0f, 0.0f,
			 0.5f, 0.5f, 1.0f, 0.0f,
			 0.0f, 0.0f, 0.0f, 0.0f );

	//view matrices
	D3DXMATRIX view = pView->GetCamera()->GetView();
        D3DXMATRIX viewInv = pView->GetCamera()->GetView();
	D3DXMatrixInverse( &viewInv, NULL, &viewInv );

	D3DXMATRIX viewTrans = pView->GetCamera()->GetView();
	D3DXMatrixTranspose( &viewTrans, &viewTrans );

	//projection matrices
	D3DXMATRIX proj = pView->GetCamera()->GetProjection();
	D3DXMATRIX projTrans = pView->GetCamera()->GetProjection();
	D3DXMatrixTranspose( &projTrans, &projTrans );

	D3DXMATRIX projInv = pView->GetCamera()->GetProjection();
	D3DXMatrixInverse( &projInv, NULL, &projInv );
	//world matrices
	D3DXMATRIX world;
	D3DXMatrixIdentity( &world );
	// Create view * projection matrix
	D3DXMATRIX viewproj = viewInv * view * proj;
	//D3DXMatrixInverse( &viewproj, NULL, &viewproj );
	//D3DXMatrixTranspose( &viewproj, &viewproj );

	D3DXMATRIX trans = viewproj * bias;
	mesh->SetTransform( trans );
	mesh->SetTexture( reflectionTexture );

        //texture projection setup in my mesh class
	m_pDxDevice->SetTransform( D3DTS_TEXTURE0, &matTransform );

Could someone please post a COMPLETE guide on how to do texture projection? Any help would be great. Thanks Pete

Share this post

Link to post
Share on other sites

There are some reflection/refraction samples in Ati RenderMonkey, you could look up those.
As far as I can remember, there was an article about the same topic in the ShaderX2 book.
However, all these examples use shaders, and you are using FFP, but maybe you can get some ideas.


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