Skip to main content
gamedev.net
🔒 Locked

Stencilbuffer...

Started by cannonicus 2 replies 1.2k views
Original Post
cannonicus
cannonicus
Hi I have a few questions about stencil/depth buffers. When i change my rendertarget (colorbuffer), the stencilbuffer remains the same, right? What happens if i change the rendertarget to a smaller sized buffer? Its ok according to the docs, but it doesnt specify the behavior of the stencilbuffer. Will the new rendertarget (smaller than the stencilbuffer) use the whole stencilbuffer or will it use a rect, the size of the colorbuffer, of the stencilbuffer? In the latter case, can you somehow offset this rect to specific coordinates in the stencilbuffer? //Emil
Emil Jonssonvild
sirob
sirob
The Frame Buffer (color) and Depth/Stencil buffer match 1:1. Each pixel in the Frame Buffer needs a corresponding value in the Depth/Stencil buffer. If the Frame Buffer is smaller than the Depth/Stencil buffer, some of the stencil buffer will not be used. I'm not aware of any way you can "select" which part of the Depth/Stencil buffer would be used in this case. The Viewport settings should apply to the Depth/Stencil buffer as well.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
Namethatnobodyelsetook
Namethatnobodyelsetook
While the docs (and debug messages, when you've used too small a depth buffer) say that you can't have a depth buffer smaller than the render target, nothing is clear about your card should behave when using a small render target with a large depth buffer. One this is clear from experience though... don't do it. Always use the same size render target and depth buffer.

Lets say you have a 256x256 render target and a 512x512 depth buffer. Should your card use the first memory available (ie: 512x128 worth) from the depth buffer, or should it use a subrect of the depth buffer? Well, on the XBox you can see the depth buffer, and if I remember correctly, upon clearing it uses the first n bytes (ie: clears the first 512x128), but drawing treats it as a subrect (upper left 256x256)). This is annoying as it forces you to have extra shadowmap depth textures, instead of just using part of an existing larger one.

I seem to remember having troubles with such a technique on a PC too. Just don't do it. It's not properly documented or handled by drivers and cards. Don't mismatch your color/depth sizes, even if the SDK and debug spew mislead you into thinking it will be okay.
cannonicus
cannonicus
Thanks for the replies.

Since using a subset of the stencilbuffer doesnt appear possible, i guess ill have to implement that functionality in some other way.

My first thought was to simply use UpdateSurface to copy data from the big stencilbuffer to smaller, that i would use together with my smaller rendertargets. This isnt possible according to the docs about UpdateSurface:

Quote:
The surface format cannot be a depth stencil format.
...

Any ideas how to go around this?

Also, i guess i could provide direct3d with a stencilbuffer of my own, do my rendering to the full sized buffer, change rendertarget to the smaller one and input my ex-stencilbuffer to a pixelshader using multitextureing and set the output alpha component to 0 for pixels i want stenciled away. Ugly and unnessecarily expensive imo.

Why o why isnt there simply a IDirect3dSurface9::Blt() function :-(

All thoughts and ideas on how to copy a portion of a stencilbuffer to another are welcome.

//Emil
Emil Jonssonvild

Topic Locked

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

Sign in to reply to this topic.