Hi,
i want to render the zbuffer to a depth texture, i've successfuly displayed the content of the backbuffer but i still have problems with the zbuffer this is my code:
i want to render the zbuffer to a depth texture, i've successfuly displayed the content of the backbuffer but i still have problems with the zbuffer this is my code:
C#:
// this is the intialization code of the textures
zbuffer=new Texture( dev,dev.Viewport.Width,dev.Viewport.Height,1,Usage.DepthStencil,dev.DepthStencilSurface.Description.Format,Pool.Default );
bbuffer=new Texture(dev,dev.Viewport.Width,dev.Viewport.Height,1,Usage.RenderTarget,dev.GetRenderTarget(0).Description.Format,Pool.Default);
// this is my rendering code
// i draw a mesh while i'm setting the render target and the zbuffer to the 2 textures i created
//the bbuffer texture correctly display the mesh but the zbuffer doesn't display any data i'm using d16 depth format for the zbuffer
device.BeginScene();
Surface oldbb=device.GetRenderTarget(0);
Surface oldsb=device.DepthStencilSurface;
Viewport ov=device.Viewport;
device.SetRenderTarget(0,bbuffer.GetSurfaceLevel(0));
device.DepthStencilSurface=zbuffer.GetSurfaceLevel(0);
device.Clear( ClearFlags.Target |ClearFlags.ZBuffer, System.Drawing.Color.Red, 1.0f, 0);
SetupMatrices();
for( int i=0; i<meshMaterials.Length; i++ )
{
// Set the material and texture for this subset
device.Material = meshMaterials[i];
device.SetTexture(0, meshTextures[i]);
// Draw the mesh subset
mesh.DrawSubset(i);
}
//restore the original render target and z buffer
device.SetRenderTarget(0,oldbb);
device.DepthStencilSurface=oldsb;
device.Viewport=ov;
device.Clear( ClearFlags.Target |ClearFlags.ZBuffer, System.Drawing.Color.Red, 1.0f, 0);
//sp is a spirit used to display the zbuffer texture
sp.Begin();
// this one is not working just a white spirit appears
sp.Draw(zbuffer,new Rectangle(0,0,device.Viewport.Width,device.Viewport.Height),new Vector2(0.5f,0.5f),new Vector2(0,0),0,new Vector2(1,1),Color.White);
// this one is working and display the bbuffer
//sp.Draw(bbuffer,new Rectangle(0,0,device.Viewport.Width,device.Viewport.Height),new Vector2(0.5f,0.5f),new Vector2(0,0),0,new Vector2(1,1),Color.White);
sp.End();
device.EndScene();
device.Present();