14
\$\begingroup\$

I'm not sure if real life soft shadows (from close,large light sources) have a Gaussian or linear falloff, or something else.

I'm working on something where I can create the shadows by manipulating some kind of pre-rendered gradient texture so I am not having to rely on frame buffers and traditional shadowing techniques. I'm planning on baking the gradient into one channel of my mesh's texture and then manipulating the values based on how much shadow covers each quad. This is possible because I just have quads lined up like a zigzag where each peak can cast a shadow onto the next adjacent quad.

So a linear falloff would be easiest (just need to subtract some value from a linear gradient) but I have a hard time telling what actually looks realistic. Is there a simple math formula that could be applied to a linear gradient to pull out a Gaussian approximation?

\$\endgroup\$
  • 3
    \$\begingroup\$ In computer graphics "looks realistic" and "is accurate" are often two very different things! \$\endgroup\$ – Roman Reiner Jun 29 '14 at 14:16
34
\$\begingroup\$

Real-life soft shadows have a shape that depends on the shape of the light source as it appears from the point of view of the shadowed surface. This is because penumbras occur due to partial occlusion of the light source from the shadowed surface's point of view. The shape of the shadow is therefore something like the shape of the occluder convolved with the shape of the light source.

For example, the sun appears to us as a disc, so soft shadows due to the sun are effectively convolved with a disk filter. The resulting falloff is, in many cases, similar in appearance to that of a Gaussian, which may explain why Gaussians are popular for shadow filtering.

Gaussian falloff is also very similar in appearance to the smoothstep function, which is pretty inexpensive to evaluate and could be a good choice for your shader.

The dependence of shadow shape on light source shape is most dramatically demonstrated during a solar eclipse. This photo by Flickr user Cantavestrella, for instance, was taken during a partial eclipse a few years ago. The eclipse resulted in a crescent of visible sun surrounding the moon, and as a result, the shadows of a tree show a crescent shape where the leaves of the tree happen to form a pinhole.

Copyright © 2005 by Flickr user Cantavestrella; licensed under CC BY-SA 2.0

\$\endgroup\$
  • 5
    \$\begingroup\$ +1 for the really cool image. And, naturally, for smoothstep. \$\endgroup\$ – Nit Jun 28 '14 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.