You can now activate shadows by shadow volumes by toggling a trivial boolean property Shadows at the light source to
true! This works (also) in editor at design-time.
This makes the shadow volumes we have documented here easily available, finally. No more messing around with X3D lights nodes.
A simple demo is in examples/viewport_and_scenes/shadows.
We also publish
TCastleTransform.CastShadows property to control if some object casts shadows.
This is just the beginning of “really easy shadows”. I enjoy how simple API we have (just a checkbox really!) and how great it is to play with shadows in the editor. But we can improve the functionality underneath now 🙂
The most important TODO here is that we plan to expose shadow maps in the same way. Actually shadow maps should be in the future the default algorithm activated by
Shadows(and toggling between shadow maps and shadow volumes should be done using an independent property like
ShadowMode = smShadowMaps, smShadowVolumes).
Shadow maps have a number of advantages — they do not require the shadow caster to be 2-manifold, they already work on both desktop and mobile (OpenGLES), they can be applied on multiple light sources independently with correct result.
While we had shadow maps implemented for years, with some impressive demos (see features section) but they do not work (yet!) across scenes, which means that the light that casts shadow must be in the same glTF/X3D file as the shadow receiver. This makes them not suitable to use shadow maps on our light nodes.
The plan is to, well, remove this limitation (#284). Shadow maps should work cross-scene, they should not transform the X3D graph (whole work done by
CastleInternalShadowMapsshould be removed) and the renderer should just take and use at rendering a shadow map information attached to any light (and the renderer should add using that shadow map to particular shape).
Shadow volumes for now carry a few limitations:
The unfixable limitation is that shadow caster has to be 2-manifold, i.e. every edge must have exactly 2 neighboring faces, so the whole shape is a closed volume. Both CGE and 3D authoring tools like Blender help you modeling such shapes — see Make 3D models of shadow casters geometry to be 2-manifold.
The current limitation of shadow volumes in CGE is that we allow them from only one light (so set
trueonly on a single light!)
We could improve that, though note that it will increase the number of rendering passes, in general you need to do
2^shadow_volumes_lightspasses. So this technique is really not feasible for multiple lights. (Shadow maps scale much better.)
A temporary limitation is that shadow volumes do not render properly on mobile (OpenGLES), we have a PR in progress to address that.