The shadow thread.
Moderator: InsideQC Admins
11 posts
• Page 1 of 1
The shadow thread.
Until recently, I was pretty content with some quick, cheap shadows that simulated volumes.
I then decided it was time to upgrade my shadow rendering code. First I tried shadowmaps, and found that while ok for a single scene, not really that practical for a game situation. Yes, I know Xreal uses shadowmaps, but I don't care for the jaggy shadows.
Next I decided to use stencil volumes. These work quite well, and was able to make them quite fast by using two sided stencil so that they can be done in one pass instead of two(if the card has OGL 2.0 or better). Now that I have this done on meshes, I am working on the rest of the world.
But, I do have a question, and maybe some more in the future.
Question 1: how to fade out the shadows with respect to distance from the occluder? I've seen this in a few engines but cannot figure what is being done to achieve the effect.
I then decided it was time to upgrade my shadow rendering code. First I tried shadowmaps, and found that while ok for a single scene, not really that practical for a game situation. Yes, I know Xreal uses shadowmaps, but I don't care for the jaggy shadows.
Next I decided to use stencil volumes. These work quite well, and was able to make them quite fast by using two sided stencil so that they can be done in one pass instead of two(if the card has OGL 2.0 or better). Now that I have this done on meshes, I am working on the rest of the world.
But, I do have a question, and maybe some more in the future.
Question 1: how to fade out the shadows with respect to distance from the occluder? I've seen this in a few engines but cannot figure what is being done to achieve the effect.
http://red.planetarena.org - Alien Arena and the CRX engine
- Irritant
- Posts: 250
- Joined: Mon May 19, 2008 2:54 pm
- Location: Maryland
Might have answered my own question....
I'm going to venture a guess and say that it's the use of glDepthFunc, which then brings the algorithm into the realm of Carmack's Reverse, and the Creative Lab's(patented) methods?
I suppose I could do what DP does and reverse the algorithm to avoid patent issues. Yeesh, how retarded is patenting code? Not that I think they'd bother with little ole me, but I'd like to avoid trouble anyway.
I'm going to venture a guess and say that it's the use of glDepthFunc, which then brings the algorithm into the realm of Carmack's Reverse, and the Creative Lab's(patented) methods?
I suppose I could do what DP does and reverse the algorithm to avoid patent issues. Yeesh, how retarded is patenting code? Not that I think they'd bother with little ole me, but I'd like to avoid trouble anyway.
http://red.planetarena.org - Alien Arena and the CRX engine
- Irritant
- Posts: 250
- Joined: Mon May 19, 2008 2:54 pm
- Location: Maryland
Ok, I'm just a complete loss. There seems to be very little information on the web or game dev sites. I can't make sense of the DP code that does it...
All I wanna know is how to fade out shadows as they are further from their caster...anyone? Bueller?
All I wanna know is how to fade out shadows as they are further from their caster...anyone? Bueller?
http://red.planetarena.org - Alien Arena and the CRX engine
- Irritant
- Posts: 250
- Joined: Mon May 19, 2008 2:54 pm
- Location: Maryland
I assume the lights frustum has a farplane that is the lights radius?
If so it should just be a matter of using the depth buffer as a multiplier against the shadow result.
If so it should just be a matter of using the depth buffer as a multiplier against the shadow result.
Benjamin Darling
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
- Electro
- Posts: 312
- Joined: Wed Dec 29, 2004 11:25 pm
- Location: Brisbane, Australia
Electro wrote:I assume the lights frustum has a farplane that is the lights radius?
If so it should just be a matter of using the depth buffer as a multiplier against the shadow result.
I thought so too, but I cannot find it being done in DP or Berzerker, two engines that fade shadows.
Yeah basically, shadow attenuation by radial distance is what I am talking about.
http://red.planetarena.org - Alien Arena and the CRX engine
- Irritant
- Posts: 250
- Joined: Mon May 19, 2008 2:54 pm
- Location: Maryland
Are you sure it's actually fading? As far as I know, DP just does stencil shadows and does not draw in areas that are obscured from a light source. Could it be that there's just another light back there, and the attenuation makes it look like a fade?
-

Entar - Posts: 439
- Joined: Fri Nov 05, 2004 7:27 pm
- Location: At my computer
There's definite fading; I've seen it myself in the start map (e4 entry, at the light under the steps up to the pool).
Some thoughts - the shadow colour can be set via standard OpenGL colour ops, either a glColor4f or a glColorPointer, depending on your engine's architecture. So make the alpha component of the colour dependent on distance from the light source.
An alternative method might be to - rather than disabling texturing when drawing stencil shadows - use an attenuation map texture going from black to white. Modulate this with your base diffuse and clamp the texcoords to your shadow volume and it should do it (note though that this is theoretical and OTOH; I've written attenuation map based lighting engines before but never used them for shadowing).
Some thoughts - the shadow colour can be set via standard OpenGL colour ops, either a glColor4f or a glColorPointer, depending on your engine's architecture. So make the alpha component of the colour dependent on distance from the light source.
An alternative method might be to - rather than disabling texturing when drawing stencil shadows - use an attenuation map texture going from black to white. Modulate this with your base diffuse and clamp the texcoords to your shadow volume and it should do it (note though that this is theoretical and OTOH; I've written attenuation map based lighting engines before but never used them for shadowing).
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
MH, I think you are onto it. It looks like in both Berzerker and DP there is some type of blending with an attenuation cube map. I still can't really figure out how to apply it to my own engine. I have stencil volumes working fine though. Both of these engines are so radically altered in the way they do things that it's very foreign looking to me.
http://red.planetarena.org - Alien Arena and the CRX engine
- Irritant
- Posts: 250
- Joined: Mon May 19, 2008 2:54 pm
- Location: Maryland
I assume DP attenuates lighting based on a texture lookup. With a texture matrix set to give the scale and offset for the radius and center of the light.
Multiple passes on cards with less texture units is probably done by using the alpha buffer for temporary storage.
If it uses a cubemap the same way that I used one, its in order to pass vertex normals via texture coords.
You can't use a cubemap for attenuation, as any texture coord is clamped to an edge of the cube.
or something. dunno, didn't really read the full thread.
erm
Question 1: how to fade out the shadows with respect to distance from the occluder? I've seen this in a few engines but cannot figure what is being done to achieve the effect.
fade the lighting, not the shadows. shadows are merely the absence of light.
Multiple passes on cards with less texture units is probably done by using the alpha buffer for temporary storage.
If it uses a cubemap the same way that I used one, its in order to pass vertex normals via texture coords.
You can't use a cubemap for attenuation, as any texture coord is clamped to an edge of the cube.
or something. dunno, didn't really read the full thread.
erm
Question 1: how to fade out the shadows with respect to distance from the occluder? I've seen this in a few engines but cannot figure what is being done to achieve the effect.
fade the lighting, not the shadows. shadows are merely the absence of light.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
You'd use a combination of a 1D and a 2D texture to simulate it and then scale the texture matrix by the extent of the shadow volume. Add in translation and you're there. It's easy enough to do for light and the principle is the very same except you would be modulating with the base diffuse colour rather than adding to black. Linear filtering will give you per-pixel accuracy, and the textures can be 128 size.
I had a Q1 build that used attenuation maps instead of lightmaps for lighting some years back, but in the end it proved to be not practical as there are so many Q1 light sources that some surfaces ended up getting 50 or so passes over them (incredibly slow). It looked beautiful though.
An alternative for shadowing (and potentially lighting too), since an attenuation map can be generated from a known formula, is to generate it via a procedural texture in a shader. That I would guess is the most efficient method as I'm thinking it should be able to allow you to collapse everything to a single pass. You could probably get the same effect from the 1D/2D textures but generating texcoords in the shader. In combination with the stencil buffer it would give you a unified real time lighting and shadowing engine.
Again, all theoretical.
I had a Q1 build that used attenuation maps instead of lightmaps for lighting some years back, but in the end it proved to be not practical as there are so many Q1 light sources that some surfaces ended up getting 50 or so passes over them (incredibly slow). It looked beautiful though.
An alternative for shadowing (and potentially lighting too), since an attenuation map can be generated from a known formula, is to generate it via a procedural texture in a shader. That I would guess is the most efficient method as I'm thinking it should be able to allow you to collapse everything to a single pass. You could probably get the same effect from the 1D/2D textures but generating texcoords in the shader. In combination with the stencil buffer it would give you a unified real time lighting and shadowing engine.
Again, all theoretical.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
11 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
