Lightsource Shadowmaps

From Realsoft3D Wiki

First it is useful to notice that there are two kinds of shadow maps:

  • A shadow map for a light source. It is mapped to the light source and affects all geometry objects illuminated by the light.
  • A shadow map for geometric surfaces, created for example using the UVImage tool. It controls only only those target geometries to which the material is mapped.

Here is an explanation how to create a shadow map for a light source.

  1. Illuminate your scene using spot lights. Point lights suit badly manual shadow mapping (=laborious to set up).
  2. Select a spot light and set its shadow properties to 'mapped'. Render some test images to find a light source size and shadow map resolution which give a good looking shadow.
  3. Turn off shadows for the spot light.
  4. Drag and drop the spot light to a view window. View gets the same orientation as the spot light. Make sure the view also has perspective projection enabled. If you do not see the outer rim of the spot light, zoom out the view.
  5. Activate the Camera creation tool and select Accept from the view popup without entering any points. This creates a camera object which has exactly the same orientation as the spot light.
  6. Open the property window. Adjust camera object's view angle and image aspect ratio (aspect should probably be 1.0) so that camera's frame matches the spot light's rim (=is slightly larger). Match does not have to be accurate, but a tight fit uses shadow map pixels more efficiently.
  7. Go to the Output Objects tab of the select window. Create a new object of type 'Realsoft 3D' - it is RS3D's own deep image format. Open the property window and rename the object for example as 'shadowmap'.
  8. On the property window, select Distance from the Available Objects list and click Add button to include it into shadow map channels. Then select Transparency channel and add it, too. The new shadow map file format definition is now ready. You can customize the channel data types if you like (e.g. distance to 32 bit integer instead fo default float datatype)
  9. Make sure that the spotlight-matching camera is 'Current' and other possible cameras are not.
  10. Select a render settings object, for example 'speed over quality'. Customize it as follows, using the property window: Recursion depth can be minimal 1 and antialiasing turned off (level 0). Shadows etc. can be turned off as well - we need only distance and transparency information. Set undersampling to 1*1. This kind of render settings render the map image very quickly.
  11. Open the file render window. Set resolution to the same values which you already tried in the step 2. Remove all existing output targets and add only the new 'shadowmap' format. Define a suitable output file name. Select 'Speed over quality' to the render settings field and remove post effects if there was some selected. Finally hit 'Render Image' button to compute the shadow map.
  12. Go to the materials tab and create a new material called 'SpotShadows'.Its structure is the following:
        Light properties shader
            Light:Illumination*=ShadowMap(map coords)
    Select the rendered map image to the file name of the shadow map VSL object.
  13. Make sure that the view window still shows the view trough the spotlight and the camera matched to it. Zoom out a bit so that you can see the whole rectangular front frame of the camera.
  14. Select the spot light object. Make sure that SpotShadows material is still selected and activate Map/Pyramid from the popup menu of the materials tab of the select window. Clik first in the top left corner of the camera frame, then second time on the bottom right corner.
  15. Go back to the geometry tab of the select window. First drag&drop the camera object to view window to restore the exact zoom and position of the camera. Then select the pyramid map object. From the View's popup menu, select Camera/View to object. This stores the view's orientation to the pyramid mapping, matching the map with the camera.

Spot light now has mapped shadows set. Render a test image on the view window to verify this. Adjust the 'Smooth' property of the shadow map VSL object, if necessary.