Jump to content
  • Advertisement
Sign in to follow this  
The C modest god

Shadows in 3D games

This topic is 4653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
No.
Not difficult.
The last two titles I worked on did that.
Also all my current projects do that.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Don't be so shocked by that, as a similar error appears even in blockbuster movies, when cg characters shadows overlaps real shadows...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!