Enabling shadows

Beginner Getting started

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!

Could not find what you were looking for?

We are still working on more tutorials. If you need additional help with BBMOD, please have a look at the documentation or join our Discord community. Thank you for your patience.

Support the development

Support us in developing BBMOD, get priority assistance and more of our amazing tools as a reward!

Become Patron

Don't miss out on a thing!

Create an account, subscribe to newsletter and get notified on new releases, tutorials and special offers.

Register Log in