View previous topic :: View next topic |
Author |
Message |
Irritant
Joined: 19 May 2008 Posts: 115 Location: Maryland
|
Posted: Mon Jul 27, 2009 5:05 pm Post subject: 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. _________________ http://red.planetarena.org - Alien Arena |
|
Back to top |
|
 |
Irritant
Joined: 19 May 2008 Posts: 115 Location: Maryland
|
Posted: Tue Jul 28, 2009 5:29 am Post subject: |
|
|
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. _________________ http://red.planetarena.org - Alien Arena |
|
Back to top |
|
 |
Irritant
Joined: 19 May 2008 Posts: 115 Location: Maryland
|
Posted: Thu Aug 06, 2009 2:48 am Post subject: |
|
|
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? _________________ http://red.planetarena.org - Alien Arena |
|
Back to top |
|
 |
Urre

Joined: 05 Nov 2004 Posts: 1073 Location: Sweden
|
Posted: Thu Aug 06, 2009 4:21 am Post subject: |
|
|
I don't know the answer, but just to clarify, you mean a simple gradient fadeout? _________________ Look out for Twigboy |
|
Back to top |
|
 |
Electro
Joined: 29 Dec 2004 Posts: 241 Location: Brisbane, Australia
|
Posted: Thu Aug 06, 2009 6:47 am Post subject: |
|
|
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. _________________ Unit reporting!
http://www.bendarling.net/ |
|
Back to top |
|
 |
Irritant
Joined: 19 May 2008 Posts: 115 Location: Maryland
|
Posted: Thu Aug 06, 2009 5:10 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
Entar

Joined: 05 Nov 2004 Posts: 422 Location: At my computer
|
Posted: Thu Aug 06, 2009 7:05 pm Post subject: |
|
|
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? _________________ woh... feelin woozy... too much cider...
http://entar.quakedev.com
games fascination - My Game Development Blog/Journal
 |
|
Back to top |
|
 |
mh

Joined: 12 Jan 2008 Posts: 909
|
Posted: Thu Aug 06, 2009 7:52 pm Post subject: |
|
|
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). _________________ DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines |
|
Back to top |
|
 |
Irritant
Joined: 19 May 2008 Posts: 115 Location: Maryland
|
Posted: Thu Aug 06, 2009 8:14 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Thu Aug 06, 2009 10:39 pm Post subject: |
|
|
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. _________________ What's a signature? |
|
Back to top |
|
 |
mh

Joined: 12 Jan 2008 Posts: 909
|
Posted: Fri Aug 07, 2009 12:09 am Post subject: |
|
|
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. _________________ DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines |
|
Back to top |
|
 |
|