Skip to main content
GameDev.net gamedev.net
🔒 Locked

Zbuffer as texture

Started by BugzzBunny Jan 5, 2002 at 6:42 AM 4 replies 900+ views
Original Post
BugzzBunny
BugzzBunny
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)
  
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);
  
Then i get the surfaces of those textures, and use them as rendertargets:
  
g_d3d_device->SetRenderTarget(m_pSMColorSurface, m_pSMZSurface)
  
Then i render all my stuff ie:
  
if(SUCCEEDED(g_d3d_device->BeginScene())){
 //DRAWSTUFF

 g_d3d_device->EndScene();
}
  
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....
BugzzBunny
BugzzBunny
BUMP!

Anybody? Please? Please? Pertty Please?
S1CA
S1CA
My guess is that the Z buffer texture isn''t being created (check the return code and the messages on the debug spew with the debug runtime and the output level turned up).

You''ll find many chips are *very* choosy about what you do with depth buffers. Many won''t let you touch a depth buffer which was an output of a previous scene, and definately won''t let you use it as a texture in the same scene.

If you really must create a depth buffer for SetRenderTarget, then create it with this call:

IDirect3DDevice8::CreateDepthStencilSurface


[depending on what you''re doing, and dependence on how values are stored in the depth buffer is a bad idea in terms of compatibility - some chips don''t even use Z buffers]

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
BugzzBunny
BugzzBunny
Well according to nvidia that is the right way to do it. I´m trying to use those textures with a geforce3, so it should work, as i said the demo works fine.

The demo:
http://developer.nvidia.com/view.asp?IO=d3dshadowmap

About hardware shadowmaps:

http://developer.nvidia.com/view.asp?IO=hwshadowmap_paper

a little bit from the that paper:

•render the scene from the light’s point of view,
•use the light’s depth buffer as a texture (shadow map),
•projectively texture the shadow map onto the scene, and
•use “texture color” (comparison result) in fragment shading.

we are stuck at point 2 there.

more from that paper:
Once shadow map support has been determined, you can create the shadow map
using the following call:
pD3DDev->CreateTexture(texWidth, texHeight, 1,
D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24S8, D3DPOOL_DEFAULT,
&pTex);



Then the rest of the thing is as in those point over there is to determine which part is shaded and which is not. I thought that that texture would be somekind of grayscale image of the depth of that world(because in that paper there are a lot of screens with such an image), but maybe that´s the problem. I don´t know how I´m supposed to determine if there is any data in that surface or not (being a n00b). It seems that the zbuffer is working because the colorsurface texture is drawn correctly.

It would be nice if nvidia would put up an discussion board on their site and put some stuff for us who just do this for fun.

Well i guess it´s time for some copy/paste programming . Probably have to learn about vertex/pixel shaders then.....
S1CA
S1CA
Are you trying this on nVidia hardware ?

IHVs tend to write demos which show off things their hardware can do, and sometimes even do things which depend on specific knowledge about their driver.

I did notice one interesting thing in the nVidia code:
CShaderHardwareShadowMap::CheckResourceFormatSupport()

the use of that function seems to be to tell whether the hardware will support textures created with depth buffer formats (i.e. very likely GeForce3 specific feature).

also pay very careful attention to where the SetRenderTarget calls are in the nVidia code, especially in relation to the rest of the frame.


You can contact nVidia developer support directly if you want help on a feature exposed by their hardware (there should be an address on the site). I do have some addresses for individual devrel people, but I''m not sure whether they''d mind me posting on a public forum.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
BugzzBunny
BugzzBunny
Well I do check if the hardware supports it. The the card is a geforce3 with the latest drivers, so that check is not a must but i do it anyway. I have given up hope to get it to work in its current form. Now all I have to do is learn how vertex/pixel shaders work and make a more direct copy of that program, and see if that solves anything. Any good sites about vertex/pixelshaders? The dx8 sdk documentation has some code about them but a guide for beginners would be nice...

The goal of this whole thing is to make somekind of nice little demo using a lot of the nice stuff that the geforce3 can do. Just for fun, allways fun to learn something new. I intended do use normal texturestages, but now it seems I´ll have to use those shaders instead. Well might be a good thing, looks like you can do a lot of nice thing with them anyway....

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.