Previewing Shadowmaps

July 6th, 2008 by Stefano Jannuzzo - Viewed 9565 times -

It is sometimes desirable to be able to check the shadow maps look.

Since XSI does not allow for shadow maps paths, this is how you can do (a ray3 standalone license is required).

After setting up a shadow mapped light, export a single frame archive (mi2) ascii file.

Edit the file with a text editor, and look for the light options section. There you find the shadowmap settings.

To have the map written, just add a line with the “shadowmap file” statement, followed by the path for the file (.zt format mandatory).

light "Spot_Root/Spot/Light" = "Spot_Root/Spot/Light/soft_light"
origin 0 0 0
direction 0 0 -1
spread 0.866025
shadowmap on
shadowmap resolution 500
shadowmap softness 0.002
shadowmap samples 20
#the following line added
shadowmap file "C:\temp\sm.zt"
energy 7500 7500.01 7500
end light

Save the file and render it with ray3.

To just render the shadow map and not the image, you can use the handy “-shadowmap only” option. In my case, being the archive file named C:\temp\out.mi2, I run

ray3 C:\temp\out.mi2 -shadowmap only -verbose on

Once finished, you should find the map on disk (C:\temp\sm.zt in my case), and view it by

imf_disp C:\temp\sm.zt

This is a simple sphere over a grid

Shadow Maped Sphere

The grid does not show up, not being a shadow caster itself.

So you can now check the shadow map extent, which is particularly interesting for infinite lights, being determined by the extent of the parts of the scene that cast shadows (for spot light sources, only the cone spread parameter matters).

Also, by left clicking on the image, you can read the z value for each pixel, and finally (maybe) understand the obscure bias option ;).

5 Responses to “Previewing Shadowmaps”

  1. Nice tip Stefano !

    On the same idea, do you think it could be possible to use an already rendered shadow map in a new render ? It is very useful for hair rendering for example and I don’t know if mental ray can do it ?

  2. Stefano says:

    Sure. If the statement is there, the file is found, and ray3 is told to reuse the shadow map (-shadowmap reuse), the map is used, regardless of the current geometry standing between the light and the shadow receivers. keep in mind that a shadow map only stores the distance from the light to the shadow casters, at the time it was built. When it’s read, this distance is compared with the distance from the light to the lit object, that’s it, no memory is kept about the first phase. So you can do all sort of crazy things, at your own risk of course.

  3. Thanks for the info Stefano. Saving deep shadows map is something very useful when ligths are already set and that you just need to tweak the surface shaders without re-render the shadow maps.
    I never tried this using Mental Ray as most of the time I don’t use shadow maps with this renderer. But Softimage could add this feature in XSI to avoid the .mi file generation.

  4. harry bardak says:

    Actually the function exist in the GUI but it doesn’t work.
    XSI will always ask MR to rebuild your shadow map even if you uncheck rebuild shadow map option.

    It looks like nobody really tested it !

  5. Stefano says:

    Yes, it’s broken (used to work in 5).
    However, that option allowed you to keep the maps animation wise, but not to reuse them somewhere else, nor was the map written to disk, if I well remember.
    I think Maya instead allows for per-light path.