stencil volume shadows

hi,

Im trying to implement shadowvolume rendering for
multiple objects, but I dont really see the light yet.
Here's a picture of the result, the code is below.
The even and odd parts in the stencil seem to be
cancelling out but I fail to see how that is.
http://www.xs4all.nl/~vdspek/shadowvolumes.jpg
The lower bunch of spheres only show the volumes.
The volumes are capped on both sides and the quads
that make up their surfaces have ccw winding, seen from outside.

Im using the algorithm from shadowvol.c at the opengl site:
http://www.opengl.org/developers/code/glut_examples/advanced/advanced.html
which utilises the 'carmack method', see:
http://developer.nvidia.com/docs/IO/2585/ATT/CarmackOnShadowVolumes.txt
and also implemented the slightly different nvidia method,
with the same result. Could anyone shed some light on this ?
Im really in the dark here  :-D

thanks,

Jonathan

----------------------------------------------------------------------

    glClear( GL_COLOR_BUFFER_BIT | \
                 GL_DEPTH_BUFFER_BIT | \
                 GL_STENCIL_BUFFER_BIT );

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glEnable( GL_DEPTH_TEST );
    glColorMask(GL_FALSE, GL_FALSE, \
                         GL_FALSE, GL_FALSE);
    glDepthMask(GL_TRUE);

    // only depth
    DrawSpheres( );

    glEnable(GL_STENCIL_TEST);
    glDepthMask(GL_FALSE);

    glStencilFunc(GL_ALWAYS, 0, 0);
    glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
    glCullFace(GL_BACK);  // increment using front face of shadow volume

    DrawVolumes();

    // m�thode Carmaque: decrement for clipped faces
    glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
    glCullFace(GL_FRONT);  // decrement using back face of shadow volume

    DrawVolumes();

    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glCullFace(GL_BACK);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glStencilFunc(GL_EQUAL, 1, 1);  // draw shadowed part
    glDisable(GL_LIGHTING);

    DrawSpheres();

    glStencilFunc(GL_EQUAL, 0, 1);  // draw lit part //
    glEnable(GL_LIGHTING);

    DrawSpheres();


-------------------------------------------------------------
  please tear the sticker off my eddress before use
-------------------------------------------------------------


0
j
6/23/2003 6:05:20 PM
comp.graphics.api.opengl 7064 articles. 1 followers. Post Follow

2 Replies
583 Views

Similar Articles

[PageSpeed] 36
When you render concave object(s) OR multiple convex objects, you may have
multiple overlapping shadows for the same pixel, resulting in a stencil buffer
value greater than 1.

Then for correcting your problem, for the shadowing part you should not test
if STENCIL==1, you should test if STENCIL!=0 and that should do the trick.
That is, replace :
glStencilFunc(GL_EQUAL, 1, 1);  // draw shadowed part
with :
glStencilFunc(GL_NOTEQUAL, 0, (GLuint)(-1));  // draw shadowed part
and replace :
glStencilFunc(GL_EQUAL, 0, 1);  // draw lit part
with :
glStencilFunc(GL_EQUAL, 0, (GLuint)(-1));  // draw lit part

Just in case you don't know what (GLuint)(-1) is, it's a simple way of setting
all bits of the mask to 1, just like (GLuint)(0) would reset all bits of the
mask to 0.

Note that with this technique you're still limited to the number of bits in
the stencil buffer. For instance, with 8-bit stencil buffer the number of
overlapping shadows is limited to 255 per pixel (generally that limit is
enough hopefully).

Vincent


j wrote:

> hi,
>
> Im trying to implement shadowvolume rendering for
> multiple objects, but I dont really see the light yet.
> Here's a picture of the result, the code is below.
> The even and odd parts in the stencil seem to be
> cancelling out but I fail to see how that is.
> http://www.xs4all.nl/~vdspek/shadowvolumes.jpg
> The lower bunch of spheres only show the volumes.
> The volumes are capped on both sides and the quads
> that make up their surfaces have ccw winding, seen from outside.
>
> Im using the algorithm from shadowvol.c at the opengl site:
> http://www.opengl.org/developers/code/glut_examples/advanced/advanced.html
> which utilises the 'carmack method', see:
> http://developer.nvidia.com/docs/IO/2585/ATT/CarmackOnShadowVolumes.txt
> and also implemented the slightly different nvidia method,
> with the same result. Could anyone shed some light on this ?
> Im really in the dark here  :-D
>
> thanks,
>
> Jonathan
>
> ----------------------------------------------------------------------
>
>     glClear( GL_COLOR_BUFFER_BIT | \
>                  GL_DEPTH_BUFFER_BIT | \
>                  GL_STENCIL_BUFFER_BIT );
>
>     glEnable(GL_CULL_FACE);
>     glCullFace(GL_BACK);
>     glEnable( GL_DEPTH_TEST );
>     glColorMask(GL_FALSE, GL_FALSE, \
>                          GL_FALSE, GL_FALSE);
>     glDepthMask(GL_TRUE);
>
>     // only depth
>     DrawSpheres( );
>
>     glEnable(GL_STENCIL_TEST);
>     glDepthMask(GL_FALSE);
>
>     glStencilFunc(GL_ALWAYS, 0, 0);
>     glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
>     glCullFace(GL_BACK);  // increment using front face of shadow volume
>
>     DrawVolumes();
>
>     // m�thode Carmaque: decrement for clipped faces
>     glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
>     glCullFace(GL_FRONT);  // decrement using back face of shadow volume
>
>     DrawVolumes();
>
>     glDepthMask(GL_TRUE);
>     glDepthFunc(GL_LEQUAL);
>     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
>     glCullFace(GL_BACK);
>     glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
>     glStencilFunc(GL_EQUAL, 1, 1);  // draw shadowed part
>     glDisable(GL_LIGHTING);
>
>     DrawSpheres();
>
>     glStencilFunc(GL_EQUAL, 0, 1);  // draw lit part //
>     glEnable(GL_LIGHTING);
>
>     DrawSpheres();
>
> -------------------------------------------------------------
>   please tear the sticker off my eddress before use
> -------------------------------------------------------------

0
Vincent
6/24/2003 11:08:11 AM
thanks, that did it


--
-------------------------------------------------------------
  please tear the sticker off my eddress before use
-------------------------------------------------------------
"Vincent DAVID" <vincentdavid@c-s.fr> wrote in message
news:3EF8311B.DF5157F4@c-s.fr...
> When you render concave object(s) OR multiple convex objects, you may have
> multiple overlapping shadows for the same pixel, resulting in a stencil
buffer
> value greater than 1.
>
> Then for correcting your problem, for the shadowing part you should not
test
> if STENCIL==1, you should test if STENCIL!=0 and that should do the trick.
> That is, replace :
> glStencilFunc(GL_EQUAL, 1, 1);  // draw shadowed part
> with :
> glStencilFunc(GL_NOTEQUAL, 0, (GLuint)(-1));  // draw shadowed part
> and replace :
> glStencilFunc(GL_EQUAL, 0, 1);  // draw lit part
> with :
> glStencilFunc(GL_EQUAL, 0, (GLuint)(-1));  // draw lit part
>
> Just in case you don't know what (GLuint)(-1) is, it's a simple way of
setting
> all bits of the mask to 1, just like (GLuint)(0) would reset all bits of
the
> mask to 0.
>
> Note that with this technique you're still limited to the number of bits
in
> the stencil buffer. For instance, with 8-bit stencil buffer the number of
> overlapping shadows is limited to 255 per pixel (generally that limit is
> enough hopefully).
>
> Vincent
>
>
> j wrote:
>
> > hi,
> >
> > Im trying to implement shadowvolume rendering for
> > multiple objects, but I dont really see the light yet.
> > Here's a picture of the result, the code is below.
> > The even and odd parts in the stencil seem to be
> > cancelling out but I fail to see how that is.
> > http://www.xs4all.nl/~vdspek/shadowvolumes.jpg
> > The lower bunch of spheres only show the volumes.
> > The volumes are capped on both sides and the quads
> > that make up their surfaces have ccw winding, seen from outside.
> >
> > Im using the algorithm from shadowvol.c at the opengl site:
> >
http://www.opengl.org/developers/code/glut_examples/advanced/advanced.html
> > which utilises the 'carmack method', see:
> > http://developer.nvidia.com/docs/IO/2585/ATT/CarmackOnShadowVolumes.txt
> > and also implemented the slightly different nvidia method,
> > with the same result. Could anyone shed some light on this ?
> > Im really in the dark here  :-D
> >
> > thanks,
> >
> > Jonathan
> >
> > ----------------------------------------------------------------------
> >
> >     glClear( GL_COLOR_BUFFER_BIT | \
> >                  GL_DEPTH_BUFFER_BIT | \
> >                  GL_STENCIL_BUFFER_BIT );
> >
> >     glEnable(GL_CULL_FACE);
> >     glCullFace(GL_BACK);
> >     glEnable( GL_DEPTH_TEST );
> >     glColorMask(GL_FALSE, GL_FALSE, \
> >                          GL_FALSE, GL_FALSE);
> >     glDepthMask(GL_TRUE);
> >
> >     // only depth
> >     DrawSpheres( );
> >
> >     glEnable(GL_STENCIL_TEST);
> >     glDepthMask(GL_FALSE);
> >
> >     glStencilFunc(GL_ALWAYS, 0, 0);
> >     glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
> >     glCullFace(GL_BACK);  // increment using front face of shadow volume
> >
> >     DrawVolumes();
> >
> >     // m�thode Carmaque: decrement for clipped faces
> >     glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
> >     glCullFace(GL_FRONT);  // decrement using back face of shadow volume
> >
> >     DrawVolumes();
> >
> >     glDepthMask(GL_TRUE);
> >     glDepthFunc(GL_LEQUAL);
> >     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
> >     glCullFace(GL_BACK);
> >     glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
> >     glStencilFunc(GL_EQUAL, 1, 1);  // draw shadowed part
> >     glDisable(GL_LIGHTING);
> >
> >     DrawSpheres();
> >
> >     glStencilFunc(GL_EQUAL, 0, 1);  // draw lit part //
> >     glEnable(GL_LIGHTING);
> >
> >     DrawSpheres();
> >
> > -------------------------------------------------------------
> >   please tear the sticker off my eddress before use
> > -------------------------------------------------------------
>


0
j
6/24/2003 12:23:19 PM
Reply:
Similar Artilces:

visio stencils
Hello, I am looking for visio stencils for 7 and 15k passport. anyone know where I can get some??? ...

Volume Serial Label
This may be a touchie Techie (for me anyway). I have been experimenting with a hex sector reader (Iso Buster). Whilst I can find the multi burn dates, the burning tool and CD name I cant find where the Volume Serial Number is (i.e what LBA / Sector. I believe that the serial number is made up from Hex from the creation date but cant find where it is recorded on disc. Any offers... Karl wrote: > This may be a touchie Techie (for me anyway). I have been experimenting with > a hex sector reader (Iso Buster). Whilst I can find the multi burn dates, > the burning tool and C...

sun volume manager/rmserver and java
Hi There, I was requested to kill java and start it with another user than root, to make a machine SOX compliant, but a friend of mine advise me to not do it "The java processes are started by SUN volume management. Shut them off or change them from root to any other ID, and down go your disks. Rmserver is used to manage the fiber channels to the SANs. Likewise, shut that off and restart it under any other user, and no more SAN access." Is it true? I believe that only the GUI was java dependent... Any thoughts? Thanks Guto Guto wrote: > Hi There, > I was requested to k...

volume of a 3D voronoi cell
Hi, Can anybody know if there is a function to calculate the volume of a 3D voronoi cell? Many thanks ...

Help with stencil shadows?
I'm having a little trouble with stencil shadowing. Specifically my problem is with self-shadowing. I draw my object, then draw its shadow using the darkening method (copy object geometry and add degenerate quads along edges, draw with two-sided stencil, then draw an overlay poly to make the shadow). The problem is, the frontcap of the shadow z-fights with the object itself, resulting in a crawly, artifact-y self-shadow. I've tried a couple of things, like playing with z-bias, 'jittering' the shadow volume's verts in/out along their normals, etc, but nothing seems t...

Re: Another Year, Another Volume of the Digest #4
> [TELECOM Digest Editor's Note: But just as on January 4, if you were > born on January 1 you would not say "I am a year old" neither can > you claim to be 25 years old if that won't happen until August. In > other words, 1/4/2006 less 8/11/1981 results in a difference of 24 > years, 7 months and 1 week (more or less, I am too tired to calculate > it to the minute right now. We could tighten it up a bit closer if > we took the telecom-related messages which appeared in _Human Nets_ > during May through July, 1981 and the first two 'test ma...

dicom volume #3
I have some Dicom slices and I want to build the volume with those, any suggestion for matlab code ...

GS/OS Reference, Volume 1 Beta Draft, includes system loader APDA# K2S023
GS/OS Reference, Volume 1 Beta Draft, includes system loader APDA# K2S023. Manual only, no software 120805268687. E-mail me from eBay for any information or more photos. -- The only good spammer is a dead one!! Have you hunted one down today? (c) 2011 I Kill Spammers, Inc. A Rot in Hell Co. ...

Buzz on microphone input when on AC, low volume
I have a Toshiba L35-S2171, and I'm trying to record with a microphone. The volume isn't really high enough, even with every volume control I can find set at max, and mic boost turned on. But the big problem is that I get a loud buzz on this input when the computer is plugged into the power mains. When I go to battery only, the buzz goes away. The mic I'm using works ok on my desktop, but even there I have trouble getting enough volume. There is no buzz there. From past experience, it seems to me that the buzz on AC is a sign of poor design of the audio input circuit, o...

Stencil Shadow
Can i write fast animation with stencil shadows, or there is some better/faste way to make shadows? Maedowan schrieb: > Can i write fast animation with stencil shadows, or there is some better/faste way > to make shadows? If you want sharp shadows, stencil shadows are probably the fastest. Shadow maps require an additional texture, but easily expand to soft shadows. Philipp Maedowan wrote: > Can i write fast animation with stencil shadows Yes, that's how Doom 3 does shadows... -- <\___/> / O O \ \_____/ FTB. For email, remove my socks. Governments, like diaper...

3Delight shadow problem with moving camera
Hey all, I have a strange problem with 3delight. I have a scene with camera move in it. The scene has a standard light with a shadow map in it. The light/objects are stationary. When I render the scene using the same shadow file for shadows the shadows move with the camera. If I copy that same file and rename it so that there is a shadow map for every frame the shadows don't move ?!? So for now I just have a shadow file for every frame; it works, but eats up disk space. If anyone has any idea as to what is going on, let me know Thanks Adam Hi, This is a bug in 3Del...

Help with volume visualizations and patches
First of all let me say that I am a Matlab newbie. I have been working with data that describes power levels at different points within the brain. I am trying to plot this data in a way that enables its visualization. There are roughly 2400 'voxels'. Their locations in x,y,z space are known and I can assume they are cubes. The simplest way (or so it seems to me) to do this is to call the patch command for each voxel. That way I have only one 'faces' matrix. I am simply generating the 'vertex' matrix for each voxel. However this method does not seem to allow me...

Boot volume for utilities
I recently upgraded from an old G5 iMac to one of the new iMacs. I retrieved the HD from the old machine and have now mounted it in a new enclosure. The connection is USB 2. Today I upgraded my copy of Diskwarrior 4 to v 4.2 (and following Alsoft's instructions burned a dew DW disk) which should work with 10.6.2. I tried it,but the OS on my old DW disk was 10.4.5 and after about 30 minutes of a white screen and no noise from the disk drive I shut down and started to think about what I could do to improve things. My idea is to erase that older HD and install 10.6.2...

Free Stencil For SMD Soldering
sorry for spamming, but good to everybody: There's a way to get $200 laser-cut SMD soldering stencils for free! see http://www.ezpcb.com for details mik -- ezpcb.comwww.totallychips.com - VHDL, Verilog &amp; General Hardware Design discussion Foru ezpcb.com wrote: > > sorry for spamming, but good to everybody: > > There's a way to get $200 laser-cut SMD soldering stencils for free! > see http://www.ezpcb.com for details > > mike Yes, spamming this is indeed ... Just looked at ezpcbs.com to compare prices with www.pcbexpress.com, a company we have us...

stencil computation
Hi, I want to do a SOR (Successive over realaxation) like stencil computation. i.e given a 2D or 3D array, value of an element is computed as the function of it's neighbors, but with the most recent (just computed) values of the neighbors. Basically I want to do the following loop in an efficient manner, using a MATLAB library call. Is there such library procdure? do i = 1:n do j = 1:n v(i,j) = f(v(i-1,j),v(i+1,j), v(i-1,j), v(i+1,j)) end end (f is any function). I made a mistake in the code snippet. The correct one is: do i = 1:n do j = 1:n v(i,j) = f(...

Removing shadow plot3
Heys, I just loaded and plotted a finite element mesh in matlab. It shows the pressure in a blood vessel. But If I turn the blood vessel around, there is a shading. So it is pretty hard to see the pressure profile at the back side of my vessel. Thus anyone know how to remove this shadow? Thx! ...

how to draw volume of rotation
Hi, you know the picture of the volume of rotataion when a function f(x) is rotated around the x-axis, how do you make such a drawing. I've looked at pstricks but that I've found nothing for 3D drawing. I'd rather not do this by drawing ellipses and lines by hand. Any ideas? Gunnar G schrieb: > Hi, > you know the picture of the volume of rotataion when a function f(x) is > rotated around the x-axis, how do you make such a drawing. > I've looked at pstricks but that I've found nothing for 3D drawing. > > I'd rather not do this by drawing ellipses an...

FA: Shadow of the Beast, near mint
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=4128162288 ...

fileplace and striped logical volumes
Hi, We user Oracle databases on 64 GB striped LVs. STRIPE WIDTH = 8, STRIPE SIZE = 64K. The disks are on an EMC SAN. When I use fileplace -p on any file in any striped LV, it reports that the file is only on one disk, except for a few small fragments at the very beginning that are on another disk. This does not seem to make sense, especially in light of the fact that striping the DB filesystems gave noticeable performance improvement. Is fileplace able to accurately report disk usage for files on striped LVs? Thanks, Ross ...

Stencil buffer #2 284352
I'm trying to figure out the stencil buffer so I can draw things at the proper depth. I understand that glStencilFunc compares the 'ref' param to the value already in the stencil buffer (i.e. 0 in my case) however I don't understand how to handle it when you have more then 2 objects. Here's what I understand: Clearing the stencil buffer with 0 will write 0's to the entire stencil buffer. I can now enable the stencil test. If the 'func' in glStencilFunc is GL_ALWAYS it will always pass the test. This is where I start losing it. Does glStencil Func write t...

slicing a mask from a volume
I'm trying to extract a mask from a 3D shape defined by a series of ROI's that I've grouped into an IDLanROIgroup object. I'm trying to use the compute mask function to make a mask by defining a plane that cuts through the 3D shape except it only gives me a blank mask. I've had success with it before but it only works when the plane matches a plane of an exisiting ROI in the group. Can the IDLanROIgroup object extract a mask given a plane that cuts through the 3D shape at an arbitrary angle? I would like to avoid having to create a volume and making slices from that si...

stencil buffer 338895
given 2 areas represented as a series of points, How can i use the stencil buffer to achieve an "AND" with the 2 areas. In other words, opengl will only draw to space which is inside both area1 and area2. Im pretty sure this can be done with the stencil. But im not very experienced with it. Thanks for your help It might be easier to work out the intersection of your two areas first. Then use the stencil buffer on that. "Chris Miller" <chrismiller@cinci.rr.com> wrote in message news:dmDQa.16012$zE.9025@fe1.columbus.rr.com... > given 2 areas represented as a se...

Stencil or stamp?
Hi all, I have much experience in making printed circuit boards using photoetching techniques. Recently I got 10 Kgs of epoxy glass copper clad boards, double sided, from a friend that quitted his electronics activity. My past experiences with photoetching have been a great success if I used already-photoresist-coated boards, and a total failure when I tried to apply photoresist via a spray on non photoresist-coated boards (like those 10 Kg of epoxy glass I recently got). So I wanted to use a different system for these uncoated epoxy glass copper boards. So far I'm imagining two possi...

List of every volumes mounted on your machine !
While researching an AFP problem, I stumbled onto this... ~/Library/Preferences/com.apple.finder.plist contains a list of what appears to be every volume ever mounted in the key : FXDesktopVolumePositions and as the name implies, it remembers where on the dessktop the volume,s icon had been displayed last. You can use PLIST Editor to clean the list out. (quit finder before doing it, restart it after you've saved the pl;ist). It is interesting that the PLIST editor does not have a "find" function. You need to dump the contents, select all, then copy/pas...

Maximum size of volume set
Hi, ALL I want to add another 70G disk to existing volume set contains single 70G disk. Do you aware of any limitation of total volume set size ? Thank in advance, Oleg. I believe there is a limit of 255 volumes in a volume set. I don't recall the limit on the size of an individual volume. But you should be fine. Usually when adding an untested disk, I add it as a separate volume set. Test it. VSCLOSE it. SCRATCHVOL it and then add it to the production volume set. Let me know if you need additional help. Mark Ranft Pro 3K ...