Jump to content
  • Advertisement
Sign in to follow this  

Projecting Textures in DirectX 9

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!