Enabling shadows
In About render passes you have learnt how render passes work in BBMOD and how important they are for various effects. In this tutorial we will have a look at how to enable dynamic shadows using the Shadows render pass.
Contents
Material configuration
First of all, for each material that you would like to cast shadows, you need to configure which shader the material uses during the Shadows
render pass. This can be done using the set_shader method. Since what the Shadows
render pass generates is a depth buffer rendered from the light's perspective, you need to use a shader that outputs depth. You can use shader BBMOD_SHADER_DEFAULT_DEPTH for this purpose.
material = BBMOD_MATERIAL_DEFAULT.clone();
material.set_shader(BBMOD_ERenderPass.Shadows, BBMOD_SHADER_DEFAULT_DEPTH);
Enable shadow casting from lights
After you have configured your materials for casting shadows, you will need to enable shadow casting for each created light separately. This is done by setting their CastShadows property to true
.
sun = new BBMOD_DirectionalLight();
sun.CastShadows = true;
bbmod_light_directional_set(sun);
Note: At the time of writing this tutorial only one shadow casting light is supported! Additionally only directional and spot lights can cast shadows, not point lights!
Directional lights also have a property ShadowmapArea, using which you can configure the size of the area captured by the shadow map, e.g.:
sun.ShadowmapArea = 1000;
The larger the area is the less detailed will the shadows be. This can be improved by increasing the ShadowmapResolution property:
sun.ShadowmapResolution = 2048;
Enable shadows in a renderer
Lastly, you will need to enable shadows in your renderer by setting its EnableShadows property to true
:
renderer = new BBMOD_DefaultRenderer();
renderer.EnableShadows = true;
And these are all steps required for enabling dynamic shadows in your BBMOD project!