Clipping a Shadow Using the Stencil Buffer

Clipping a Shadow Using the Stencil Buffer

Post by Paul Stimpso » Sat, 04 Dec 1999 04:00:00



Can anybody give me some idea regarding the Stencil Buffer and why I cannot
get it to work. I have looked at all the stuff on the opengl web site,
including the Dinosaur example :)

I have a ball bouncing around in a closed room with glass walls, the shadow
is fine, I am really pleased with it. The trouble is the shadow passes out
beyond the glass walls.
(I only require the shadow on the floor within the room)

I have tried using the Stencil Buffer with no luck. Does the Stencil Buffer
require specific hardware? It would be nice to clip the shadow to the floor.

Is using the Stencil Buffer the right approach? I say this because I am
trying to eliminate drawing to an beyond a defined area, and this may not be
what the Stencil Buffer is for, trouble is I have seen nothing to say this
is the case.

I am using a shadow projection matrix to cast the shadow.

Any help greatly appreciated.

Regards

Paul S

 
 
 

Clipping a Shadow Using the Stencil Buffer

Post by Paul Mart » Sat, 04 Dec 1999 04:00:00


You should be able to use the stencil buffer to limit your shadow to the
floor.

Are you sure your device supports a stencil buffer? Did you ask for it when
you created your window / chose a pfd / selected a visual? Are you trying to
use more bits than your stencil buffer supports? Are you clearing your
stencil buffer each frame with glClear? Have you tried writing a small test
program to duplicate your problem?
--
   -Paul Martz
    Hewlett Packard Workstation Systems Lab
    Remove DONTSPAM to reply


Quote:> Can anybody give me some idea regarding the Stencil Buffer and why I
cannot
> get it to work. I have looked at all the stuff on the opengl web site,
> including the Dinosaur example :)

> I have a ball bouncing around in a closed room with glass walls, the
shadow
> is fine, I am really pleased with it. The trouble is the shadow passes out
> beyond the glass walls.
> (I only require the shadow on the floor within the room)

> I have tried using the Stencil Buffer with no luck. Does the Stencil
Buffer
> require specific hardware? It would be nice to clip the shadow to the
floor.

> Is using the Stencil Buffer the right approach? I say this because I am
> trying to eliminate drawing to an beyond a defined area, and this may not
be
> what the Stencil Buffer is for, trouble is I have seen nothing to say this
> is the case.

> I am using a shadow projection matrix to cast the shadow.

> Any help greatly appreciated.

> Regards

> Paul S


 
 
 

Clipping a Shadow Using the Stencil Buffer

Post by Paul Stimpso » Sat, 04 Dec 1999 04:00:00


Paul,


>You should be able to use the stencil buffer to limit your shadow to the
>floor.

I think so too but it's proving more difficult than I thought :)

Quote:>Are you sure your device supports a stencil buffer?

No, how can I find this out?

Did you ask for it when you created your window / chose a pfd / selected a
visual?

Well I have gone through example code on the opengl web site where the
Stencil buffer has been used and done all the same things as they have done.

Are you trying to use more bits than your stencil buffer supports?

Not sure about this. The stencil buffer bits were set to 8, I tried
increasing it to 32 but that did not work, how do I know if I am using more
bits than I have supported?
In one of the examples the Stencil Buffer bits were set to 0!! I cannot
verify the code since I am using MFC and VC++ 5.0 to develop my App and the
other examples were straight Win32.

Quote:>Are you clearing your stencil buffer each frame with glClear?

Yes

Quote:>Have you tried writing a small test program to duplicate your problem?

My application isn't that big so I would consider it a small test program
now  :)

Is there a clear and simple explanation of the Stencil Buffer? I am finding
it a bit confusing (no pun intended).

>--
>   -Paul Martz
>    Hewlett Packard Workstation Systems Lab
>    Remove DONTSPAM to reply



>> Can anybody give me some idea regarding the Stencil Buffer and why I
>cannot
>> get it to work. I have looked at all the stuff on the opengl web site,
>> including the Dinosaur example :)

>> I have a ball bouncing around in a closed room with glass walls, the
>shadow
>> is fine, I am really pleased with it. The trouble is the shadow passes
out
>> beyond the glass walls.
>> (I only require the shadow on the floor within the room)

>> I have tried using the Stencil Buffer with no luck. Does the Stencil
>Buffer
>> require specific hardware? It would be nice to clip the shadow to the
>floor.

>> Is using the Stencil Buffer the right approach? I say this because I am
>> trying to eliminate drawing to an beyond a defined area, and this may not
>be
>> what the Stencil Buffer is for, trouble is I have seen nothing to say
this
>> is the case.

>> I am using a shadow projection matrix to cast the shadow.

>> Any help greatly appreciated.

>> Regards

>> Paul S

 
 
 

Clipping a Shadow Using the Stencil Buffer

Post by Paul Mart » Sat, 04 Dec 1999 04:00:00



Quote:> >Are you sure your device supports a stencil buffer?

> No, how can I find this out?

You can ask for a pixel format or visual, using wglChoosePixelFormat or
glxChooseVisual, and if NULL comes back, you're out of luck.

Quote:> > Are you trying to use more bits than your stencil buffer supports?

> Not sure about this. The stencil buffer bits were set to 8, I tried
> increasing it to 32 but that did not work, how do I know if I am using
more
> bits than I have supported?

There's a glGet for this, I think it's GL_STENCIL_BITS, look in gl.h or
check the blue book. I don't know of an OpenGL implementation that provides
more than 8 bit deep stencil buffers. You should certainly be able to do
what you want with a single bit; set it to 1 for the floor pixels and leave
it 0 for all the other pixels in your scene. Then simply draw your shadow
where the stencil values are 1.

Quote:> >Have you tried writing a small test program to duplicate your problem?

> My application isn't that big so I would consider it a small test program
> now  :)

I can envision something even smaller: use an orthographic projection and
draw a triangle with stencil set up to draw 1 bits into the stencil buffer.
Then draw a second overlapping triangle, depth test disabled, with stencil
test set to only draw where the stencil buffer is 1. This is a
straightforward program which should tell you whether your device has some
defect or missing functionality, or your larger program is simply doing
something wrong.

Quote:> Is there a clear and simple explanation of the Stencil Buffer? I am
finding
> it a bit confusing (no pun intended).

:-) Just think of the stencil buffer as providing per-pixel clipping. Once
values are set in the stencil buffer, you can set the stencil function to
either draw or not draw into certain pixels based on their stencil buffer
values.

A quick read of the gStencil*() funcstions in the blue book should provide
sufficient information. The red book provuides some example code and
extended info. The GLUT distribution comes with lots of examples which use
the stencil buffer.
--
   -Paul Martz
    Hewlett Packard Workstation Systems Lab
    Remove DONTSPAM to reply

 
 
 

1. Stencil Buffer Shadow Volume Clipping Problem

I just incorporated the DX8 stencil buffer shadow volume technique into my
code, and all is working fine except for one snag.

I'm using geometry that does not completely fill the entire viewing volume,
so the far-plane clipped shadow volumes are visible as "floating"
alpha-blended areas.

I've tried playing with the stencil and zbuffer render state settings to see
if I could get the renderer to drop out those stencil pixels set with a z
value equivalent to the far plane, but I haven't had any success.

I haven't found any way to handle this via a Google search either. I've been
through the articles on Gamasutra and nVidia's site but neither got into
specifics regarding my particular situation. A post for help at GameDev.net
has also yielded no results.

I'm hoping someone with a better understanding of the stencil and zbuffer
state settings will have some ideas for me to try, other than to throw in
some large quad to "hide" these unwanted areas (like the sample code does
with its terrain.) It just seems that there should be a way to do it through
the state settings and I'm too dense to see it.

Thanks.

Darrell L

2. FS:Graphics Workhorse G3/266DT & HP 4MV

3. problem using stencil buffer for shadow volume

4. different PCX formats? problems with PBMplus? (help? anyone?)

5. Looking for: Shadow Methods using common Hardware features - An alternative to Stencil Buffer Method

6. More info: 20,000X faster rendering

7. JOB 3D Artist in Moscow/RUSSIA

8. Using Stencil buffer + Clipping plane

9. Shadow Volumes & Stencil Buffer

10. shadows without the stencil buffer?

11. Stencil buffer for shadow

12. Shadow volumes without a stencil buffer