Back to Content

Realtime Shadow Rendering


CopperCube supports realtime shadows, also known as shadow mapping, which looks especially nice when used in combination with terrain:




To enable shadow mapping, just click the checkbox "Realtime Shadows" in the property window, when the root node of your scene is selected:




A lot of settings for the shadows will become visibile then, which are explained below. You probably need to tweak these a bit to make the shadows look nicely for your scene. For easily testing the shadows, you can use an empty scene and simply insert a terrain into it: click "Edit -> Insert Terrain -> OK".


Dynamic shadows basics

CopperCube supports realtime shadows from one single directional light. This means it works nicely for outdoor scenes, where the light source is the sun. Of course, you can still use point lights everywhere, and they will lit the objects nicely as well, but they won't cast any shadows. The shadows won't be visible when there is no directional light in the scene.



A red point light in a scene with realtime shadows.
The point light doesn't cast shadows, but still lits the scene.



Objects will only receive shadows, when they have the lighting setting "dynamic" set in its material tab. By default, most objects have the lighting type "none" set, so you need to change this to "dynamic". In the image below, you can see three blocks. The one on the bottom left has set its lighting mode to 'none', so it will not be lit and not receive any shadows:


Different lighting modes.


You can also choose any mesh not to block the light, if you wish to. For this, unselect the "OccludesLight" checkbox in its property window.


How to adjust realtime shadows

The whole scene will be rendered with dynamic shadows when the "realtime shadows" mode is enabled. The system uses two cascaded shadow maps for this, one for near objects so that you get detailed shadows there, and one for objects farther away, with not that detailed shadows. You can adjust how big the area will be for detailed shadows. The smaller the area, the more detailed will the shadows near to the camera. The property value "Shadow Detail Factor" will influence this, and specify which part of the scene will be drawn detailed (where 0.2 means 20% of the world).


Different shadow detail factors.


The transparency of the shadows can be adjusted with the "Shadow Opacity" value:


Different shadow opacity factors.


Additionally, there are three other values available which can be used to tweak how the shadows appear in the scene. Depending on the types of objects and the size of your scene, you may want to adjust them to make the shadows look more realistically:


Switching shadows on and off dynamically

Rendering realtime shadows demands fast 3D hardware, so you might want to dynamically switch shadows on and off, depending on the preference of your users. So that for example your users can disable shadows if they are running your game on slower hardware. You can do this easily with a few lines of JavaScript:

var root = ccbGetRootSceneNode();
var shadowAreEnabled = ccbGetSceneNodeProperty(root, "Realtime Shadows");
ccbSetSceneNodeProperty(root, "Realtime Shadows", !shadowAreEnabled);
This will switch on Shadows if they are off, and switch then off again if they are on.




Mixing static lighting and realtime shadows

Since CopperCube also supports static lighting (light mapping), it is possible to use both lighting techniques in the same scene:


Light mapping and shadow mapping in the same scene.

You only need to specify the "lightmapping" lighting method in their material for objects which should be statically lighted, and "dynamic" for objects which should be lit using shadow maps. Note that it is currently not possible to have shadow maps appear on objects which have light maps on them, and the other way round.



Technical limitations

There are a few technical limitations for realtime shadow rendering: