Sign in to follow this  

Rendering to texture problem

This topic is 3298 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, I am trying to make a water surface from the perspective of looking out from in the sea so I am simply rendering above the water line to a texture and then projecting the texture onto the surface and applying a water bump over it for refraction which all works and looks great apart from one thing. When I render to the texture it draws the faces back to front, faces that should be behind are infront?? If I don't render to a texture and just to screen it looks fine. my code...
Quote:
LPDIRECT3DSURFACE9 pOldRT = NULL; D3DXPLANE plane; m_pd3dDevice->GetRenderTarget( 0, &pOldRT ); // clip anything under the water line... D3DXPlaneFromPointNormal( &plane, &D3DXVECTOR3(0,-0.2f,0), &D3DXVECTOR3(0,1,0) ); m_pd3dDevice->SetClipPlane( 0, *D3DXPlaneTransform(&plane, &plane, pInvWorldViewProjMatrix) ); m_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 ); LPDIRECT3DSURFACE9 pRefracSurf; // Render the environment to the texture map if( SUCCEEDED( m_pRefractionMap->GetSurfaceLevel( 0, &pRefracSurf ) ) ) { m_pd3dDevice->SetRenderTarget( 0, pRefracSurf ); SAFE_RELEASE( pRefracSurf ); m_pEffect->SetTechnique("MeshRefract"); m_pEffect->SetMatrix( "xWorld", envir->GetWorldMatrix()); // Clear the backbuffer to a blue color m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); // Begin the scene m_pd3dDevice->BeginScene(); DrawStatic(envir); // End the scene m_pd3dDevice->EndScene(); } // remove the clipping plane and reset the render target m_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, 0x00 ); m_pd3dDevice->SetRenderTarget( 0, pOldRT ); SAFE_RELEASE( pOldRT ); // Clear the backbuffer to a blue color m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); // Begin the scene m_pd3dDevice->BeginScene(); //render my two objects in my scene for (DWORD i=0; i< 2; i++) { CMesh* model = m_aObjects.GetAt(i); m_pEffect->SetMatrix( "xWorld", model->GetWorldMatrix()); SimpleDraw( model ); } // render the water surface m_pEffect->SetTechnique("Water"); m_pEffect->SetTexture( "xRefractionMap", m_pRefractionMap ); m_pEffect->SetMatrix( "xWorld", water->GetWorldMatrix()); DrawStatic(water); // End the scene m_pd3dDevice->EndScene();
Thanks, Andy

Share this post


Link to post
Share on other sites

This topic is 3298 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.

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