Original Post
I´m trying to create a zbuffer texture to be used as shadows. I have not yet been able to create any shadows, because whatever i do, the zbuffer texture is allways white (blank).
I´m essentially trying to copy what nvidia did in their direct3d shadowbuffer demo. The demo works on my 3dcard, so there shouldn´t be any reason why it shouldn´t work in my program. Some code:
Creating the textures to be used as rendertargets
I do check that those are supported and created without errors)
Then i get the surfaces of those textures, and use them as rendertargets:
Then i render all my stuff ie:
now all this works fine, i put the rendertargets back to my usual rendertargets, and render my world, with those textures. The colorbuffer works fine as a texture, but whatever i do the zbuffer remains white. I have tried, clearing/!clearing the zbuffer, enabling/disabling zbuffer, not using the "automatic" zbuffer in initizalizing the d3d app, instead using a "by hand" created zbuffer, I´ve tried a lot of different zbufffer and color formats including: D3DFMT_D24S8, D3DFMT_D16, D3DFMT_X8R8G8B8, D3DFMT_R5G6B5.
The original demo used the D3DFMT_D24S8 zbuffer format.
Now there is probably something I´m missing...Please do help, i´ve used a lot of hours for this stupid thing and its really starting to bugg me....
g_d3d_device->CreateTexture(TEXDEPTH_WIDTH, TEXDEPTH_HEIGHT, 1, D3DUSAGE_RENDERTARGET, colorFormat, D3DPOOL_DEFAULT, &m_pSMColorTexture); g_d3d_device->CreateTexture(TEXDEPTH_WIDTH, TEXDEPTH_HEIGHT, 1, D3DUSAGE_DEPTHSTENCIL, zFormat, D3DPOOL_DEFAULT, &m_pSMZTexture); |
g_d3d_device->SetRenderTarget(m_pSMColorSurface, m_pSMZSurface) |
if(SUCCEEDED(g_d3d_device->BeginScene())){
//DRAWSTUFF
g_d3d_device->EndScene();
}
|