Shadows in 3D games

Started by
6 comments, last by cignox1 18 years, 6 months ago
I have noticed a problem in some 3D games with shadows. However, I think in some games this problem is addressed. I dont remember which. In guild wars, the characters have "dynamic" shadows. The buildings and environment have statics shadows. The problem is when the characters' shadows overlap with the environment shadow. Instead of the character's shadow dissappearing into the environment shadws, what happens is that the shadow of the character further darkens the shadow of the environment. That is wrong, because both the character and the environment block the same source of light in respect for that shadow. Is it that difficult to achieve that the shadows will "dissappear" in each other?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
No.
Not difficult.
The last two titles I worked on did that.
Also all my current projects do that.
An easy solution is to handle all shadows as pure black, and apply a final ambient pass to the scene after all the shadows have been drawn. This technique works for all types of shadows.

If you use stencil volumes for both static and dynamic shadows, you can just calculate the combined volume of all shadows together, and perform the stenciling as usual. This way, you don't need a separate ambient pass as you can blend the "blackness" of the global shadow by using alpha blending.

It heavily depends on the rest of your engine, which is the best method to use. If you do post-processing anyway, the first method I suggested can be practically free. On the other hand, various tasks in creating stencil shadows can be accelerated by hardware.

Niko Suni

how do you want to make the shadows transparent as a post-processing effect? I mean if they are totally black how do you want to make the shadows less opaque so that you can see the original surface? You just have a black pixel and you don't know what is under it.

regards,
m4gnus
"There are 10 types of people in the world... those who understand binary and those who don't."
just additively blend the ambient pass
Quote:Original post by m4gnus
how do you want to make the shadows transparent as a post-processing effect? I mean if they are totally black how do you want to make the shadows less opaque so that you can see the original surface? You just have a black pixel and you don't know what is under it.

regards,
m4gnus


I was thinking about deferred shading, when I said post-processing [smile] That is, the shadows would be in their own "layer" already.

But yes, drawing ambient values additively after drawing the geometry and shadows is the simplest approach in my opinion. It only costs one extra drawing of the scene, with the simplest lighting equation possible.

Niko Suni

The problem usually is that lightmaps are created differently, with a more sophisticated method than the realtime shadows. They just dont easily mix. One solution is to "prepare" the lightmaps for shadowing. During the precalculation, do two versions: one with the main light (sun) and one without it. Calculate the modulation factor that translates the full version to the ambient version, store it in the alpha of the lightmap. Note, that this won't always be correct, but i found it to be "good enough" in most cases.

In realtime, when rendering the scene, there are two ways to use it:
1. With stencil shadows, first draw the scene normally, with the lightmaps. Note how the alpha of the lightmaps will get written to the framebuffer directly. Then do the stencil pass, and draw a quad with a blend setting of src*zero + dest*destalpha. It will dim the lightmaps to their ambient version.

2. If you're using shadowbuffers, and want "soft" edges, render them first, and then render the receiving light-mapped surface with a shader that lerps the lightmap alpha to one, using the shadowterm as the lerpfactor, and modulate the lightmap rgb with the result. (It's the same as with stencils, only this time it happens before the pixel is actually written)

These methods are not always feasible, but if you're cpu/fill limited enough, and dont want to do multiple passes, it can be a good compromise.
Don't be so shocked by that, as a similar error appears even in blockbuster movies, when cg characters shadows overlaps real shadows...

This topic is closed to new replies.

Advertisement