Sign in to follow this  

Render to Texture problems

This topic is 4766 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

Ive been trying to get water rendered correctly for a while now and have come across a number of problems. To create waves I was initiallay displacing the vertices but was recieving artifacts in the reflection as show in the following screenshot:
After no look getting rid of these artifacts I decided to try using reflective bump mapping. I got this working fine but was also getting artifacts in it, as show below:
I then tried replacing my reflection texture that I generated using render to texture techniques with a texture file. I got no artifacts at all with this, as seen below:
From this I can only presume that there must be something wrong with my render to texture texture. What does anyone think? My render to texture code is as follows:
void CVisualisation::setuprendertotexture()
{
	if( FAILED( gDevice->CreateTexture(512, 512, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_reflect_map, NULL) ) )
    {
    }
}

void CVisualisation::startrendertotexture_reflect()
{
	D3DXMATRIXA16 matView, reflect_matrix, matProj;
	D3DXPLANE reflect_plane;

	//store current projection matrix as is altered when clipping
	gDevice->GetTransform(D3DTS_PROJECTION,&matProj);
	matProj_orig = matProj;

	setclipplane();

	gDevice->GetRenderTarget( 0, &m_BackBuffer );
	gDevice->GetTransform(D3DTS_VIEW,&matView);

	gDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
	// Set up a reflection plane
	reflect_plane.a = 0;
	reflect_plane.b = 1;
	reflect_plane.c = 0;
	reflect_plane.d = 0;
	//store current view matrix
	matView_orig = matView;
	// Create a reflection matrix and multiply it with the view matrix
	D3DXMatrixReflect(&reflect_matrix, &reflect_plane);
	D3DXMatrixMultiply(&matView, &reflect_matrix, &matView);

	gDevice->SetTransform(D3DTS_VIEW,&matView);
	m_reflect_map->GetSurfaceLevel(0, &m_reflect_surface);
	gDevice->SetRenderTarget(0, m_reflect_surface);

	gDevice->Clear( 0, NULL, D3DCLEAR_TARGET| D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(167,187,211), 1.0f, 0 );
}

void CVisualisation::endrendertotexture()
{  
//restore view and projection matrices and culling order
	gDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
	gDevice->SetTransform(D3DTS_VIEW,&matView_orig);
	gDevice->SetTransform(D3DTS_PROJECTION,&matProj_orig);
}






The only thought I had was that I am using the same zbuffer for the render to texture and the backbuffer. I read somewhere that i should create a new one for the render to texture. Would this help. If so how would I go about doing this? Any help would be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Look up in the DirectX Docs the functions:

IDirect3DDevice9::CreateDepthStencilSurface
and
IDirect3DDevice9::SetDepthStencilSurface

Those should help you along a little bit ;)

Share this post


Link to post
Share on other sites
Yeah if i render it to a quad i get this:



To test it before I was just rendering what I`d see on the texture to the backbuffer then viewing it on screen. So I thought it was working right, obviously not!

Any ideas why I`m getting that dodgy background. Would what MrFlibble said help?

Share this post


Link to post
Share on other sites
Ive now give the render to texture its own zbuffer and I`m getting this now:



I think I`m creating the zbuffer right. Im using this to create the zbuffer:

if( FAILED(gDevice->CreateDepthStencilSurface(512,512,D3DFMT_D24S8,D3DMULTISAMPLE_NONE,0,TRUE,&m_TextureZbuffer,NULL)))
{
}

then this to get the current zbuffer(so I can restore it later) and set the new zbuffer as the current one:

gDevice->GetDepthStencilSurface(&m_Zbuffer);
gDevice->SetDepthStencilSurface(m_TextureZbuffer);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The "binary noise" is there because you have mipmapping enabled but you're not generating any mipmaps.

Either disable mipmapping or enable the D3DUSAGE_AUTOGENMIPMAP for your texture.

Share this post


Link to post
Share on other sites
If i`m right in saying I dont think i can set it to D3DUSAGE_AUTOGENMIPMAP when I create my texture as I have to set it to D3DUSAGE_RENDERTARGET as its a render target.

Therefore I suppose I`ll have to disable mipmaps then. How do I do this? Is it a problem not having mipmaps for this?

Thanks

Share this post


Link to post
Share on other sites
Have sorted it now thanks for all the help. Had the mipfilter in my shader set to MIPFILTER = LINEAR; I just removed this and it works fine now.

Thanks again!

Share this post


Link to post
Share on other sites

This topic is 4766 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