Friday, August 7, 2009

Extract on shadows

For everyone,

Some information on shadows, that I started writing for Holly, but think it would be of interest to everyone, not too in-depth but enough to get you started.


How you blur your shadow depends on the type of shadow, and the software. Both ways have their pro's and con's. [here's the science bit]


Shadow map shadows work by first of all producing a depth map texture (the shadow map itself) as if looking through the light then the software interprets by projecting this map back through the light to produce the shadow. Ordinarily this doesn't take into consideration transparent objects, but 'Deep shadows' do (I think this is called detailed shadows in Mental ray), sometimes it is an additional setting on the shadow map. Beware these textures have much bigger file sizes compared with ordinary shadow maps, although you can make the resolution smaller to compensate, so only use them if you need to see shadows with fine transparency detail such as when using fur.


The first pro is that they are quick, as a depth pass is a relatively simple calculation. Normally they are created first (sometimes in a pre-pass), temporarily stored, and then used in the render. You can also save out and re-use your maps. This is useful when you have a static scene with a moving camera, as you only have to do the shadow calculation once (sometimes know as once per job shadow maps). If you have a static set but a moving character, you might want to light the scene with one key light, and two shadow maps, one that is used once per job (and therefore is being reused) for the set, and a much smaller map for the character, which you will have to create for every rendered frame. In most software you can now specify a shadow camera, to use instead of the light, simply for the purpose of producing your shadow maps. This means that you can reduce the size of your shadow maps, and have more efficient renders, by focusing in on the thing that is casting the shadow, rather than the entire stage. Also you can adjust the angle/position of your shadow, without changing the lighting, a useful trick for faking lighting.


http://en.wikipedia.org/wiki/Shadow_mapping

http://graphics.stanford.edu/papers/deepshadows/


I prefer to use shadow maps, as it gives me the control I want with fast results. Some software producers have incorportated extra efficiencies, especially those that do not rely heavily on raytracing. Renderman shadow maps are written out as .tex files which is a type of mipmap. This is very efficient when rendering the frame as it will use the most appropriate texture size for the shot taking into consideration the distance of the objects from camera. It's too much to explain here but look it up if your interested. http://en.wikipedia.org/wiki/Mipmap

The Con's are that they can be tricky to work with, especially if your talking big, complex maps. The software calculations can get things a tiny bit out, and self shadow objects that should be in full light. The bias setting is there to compensate for this small amount of understandable error, so you can put the projection of the shadow map back, or bring it forward to correct the results. Bias tends to be very small numbers, but is also normally dependent on the size of object in your scene so it might take a bit of experimenting to see the results. I have seen people brush off using shadow maps because it darkens their lighting, they don't realise they have self shadowing objects (or perhaps they trying to use one small map for too big an area) and that adjusting the bias will fix it. I believe can only make an informed decision when you understand some of the technical aspects behind lighting.


The accuracy of the shadow map is limited by its resolution, and to blur the map you can use the filter size setting (in maya) or the softness in Mental ray, although the softer you make your shadows the more samples you will need, otherwise you will quickly lose quality. Samples and Resolution sizes are normally set at numbers like... 2,4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096. They are to the power of two. It is way more efficient to use these numbers (I think for memory accessing reasons), so stick to the rule. If your not sure where to start when using these settings, start low, and work your way up until you see the quality/time balance that will work for your project. If your using a small shadow map, say 64 pixels square, on a PAL render of a character, the shadows might give the impression that they are soft. But watch out, you may only have the appearance that they are soft because the map is too small, there is a good chance that it will flicker frame by frame, due to there not being enough detail in the map, you are better off turning up the resolution to 512, and increasing the filter size/ softness. Another con is that many pieces of software do not yet have a shadow blur falloff inbuilt to work with shadow maps, so you might have to write one yourself or find a workaround if that is something you need. When it is implemented it does substantially slow down the render but it might be worth it to get the realism.


Raytracing is a type of shadow rendering where the path of individual light rays are caluculated from their source (the light) to their destination (the camera) [from the manual]. Professionals can see bad raytraced shadows a mile off, so if your going to use them, make sure you get your settings right. Light Radius values control the softness of the shadows, and is dependent upon the scene size. Shadow Rays controls the graininess of the edges of a softer shadow. Increasing the number of rays increases the quality and the render times "so set it to the lowest value that produces acceptable results" [from the manual]. Basically the more soft you make your shadow, the more rays you will need to clean up the graininess.

Only touch ray depth limit if you have lots of reflection/refractions of light going on, i.e. glass, behind glass and you need it to cast shadows, as in Nigel's project, but beware of render times. If you use the area light in mental ray, shadows blur and become lighter (falloff) as they increase in distance from the object, again at cost to you in time. Raytraced shadows are much slower because of the complex calculations, and because there is no way to get around doing them on a frame by frame basis, but it is relatively easy to get them set up and working.


[extract over. Hopefully having as much information as possible will give you the confidence to use shadows in a creative way]


No comments:

Post a Comment