Render-To-Texture and Z-buffer issues

Started by
5 comments, last by Tispe 10 years, 5 months ago

Hello

I have followed the this guide http://www.two-kings.de/tutorials/dxgraphics/dxgraphics16.html to render to a texture.

I have no trouble rendering to the backbuffer. But when I swap out the backbuffer with a surface from a texture the z buffer does not work. I keep everything else the same except the render target. I can draw the colors, view/perspective just fine, but there are no depth test going on even though all states are the same.

The clear function returns with no errors and every draw is within a begin() and end(), just like with the backbuffer as target.


device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);

device->CreateTexture(512, 512,
		1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8,	//D3DFMT_R32F
		D3DPOOL_DEFAULT, &pShadowMapTexture, NULL);

What could cause this?

Advertisement
D3DFMT_X8R8G8B8 is not a depth buffer format, I guess that's why if doesn't work.
Depth formats have 'D' in them, like D3DFMT_D16.
You should also call CreateDepthStencilSurface(), not CreateTexture().

Check http://msdn.microsoft.com/en-us/library/windows/desktop/bb219616(v=vs.85).aspx for info on DX9 depth buffers.

The depth buffer is created with these present parameters way before this texture is created:


pp.AutoDepthStencilFormat = D3DFMT_D24S8; //D3DFMT_D24X8 also not working

D3DFMT_X8R8G8B8 is the format for the texture, which holds the surface I want to render to, it is not the depth buffer format. I tried D3DFMT_R5G6B5 as in the tutorial but it didn't work either.

Fixed it -.-


pp.MultiSampleType = D3DMULTISAMPLE_NONE;

  • The multisample type must be the same for the render target and the depth stencil surface.

Doesn't it need to have the same size as well?

Just don't have it bigger it says. But I guess I need to make an additional zbuffer for the new render target, because now my edges are jagged.

Or is it possible to create a Texture with D3DUSAGE_RENDERTARGET and D3DMULTISAMPLE_8_SAMPLES?

Is it possible to change the MultiSampleType of a surface inside a IDirect3DTexture9?

I don't want to render to a surface and then have to StretchRect to place it into the shadow map texture as a work around for the zbuffer/render target compability issue.

The IDirect3DTexture9::GetSurfaceLevel method returns the Address of a pointer to an IDirect3DSurface9 interface. Would DirectX be upset If I grabbed the surface, released it twice and created a new surface using the same pointer using the IDirect3DDevice9::CreateRenderTarget method?

This topic is closed to new replies.

Advertisement