|
![](/i/fill.gif) |
> Basically, I want to apply a screen-space shader but only to parts of the
> scene occluded by a model which is in turn partially occluded by other
> parts of the scene.
>
> So imagine say a magnifying glass. It makes what's behind it bigger (which
> is easy to do with a second pass over the screen data), but it doesn't
> make what's in front of it bigger.
You could do something like this (as Warp said, the stencil buffer is useful
for stuff like this). You need to be careful to not switch the depth buffer
in steps 1 and 5 (don't know if that's possible or not in your API,
otherwise it might get complicated to make sure the ghost geomtry renders
correctly in step 8). It is a little bit complex because you do not have
access to the depth/stencil buffer when that is also the render target.
1. Set render target to temporary one
2. Render scene without ghost normally, but set stencil writes to always 0
3. Render ghost geometry without writes to RGBA, but stencil write of always
1
4. Switch the render target to the actual back buffer
5. Render a full-screen quad to simply copy over the entire temp buffer RGBA
contents
5. Set your special effect pixel shader
6. Set stencil pass function to equal 1
7. Render a full-screen quad at the depth of the ghost (this will avoid
affecting anything infront of the ghost)
8. Render the ghost normally
> The APIs I'm using definitely expose the depth buffer. One of the tutorial
> programs I have renders the scene into a depth buffer from the POV of the
> light source, then uses that to figure out if a pixel is lit or shadowed
> from the POV of the camera.
Sure, if you write depth on purpose to a special render target, what is not
normally available is the "internal" depth/stencil buffer that the GPU uses
to do depth and stencil tests during normal rendering. So you're usually
having to duplicate the depth buffer if you want to use it in a non-standard
way.
Post a reply to this message
|
![](/i/fill.gif) |