By default, for shadow volumes, all shapes that cast shadows must be 2-manifold. This means that every edge has exactly 2 (not more, not less) neighbor faces, so the whole shape is a closed volume. Also, faces must be oriented consistently (e.g. CCW outside). This requirement is often quite naturally satisfied for natural objects.
Note that satisfying the above requirements (2-manifold, consistent ordering) means that you can also use backface culling which improves rendering performance. You typically turn on backface culling in your 3D authoring software (e.g. check it in Blender material settings) which will export it to the glTF or X3D file. Our engine will automatically follow this information.
You can inspect whether your shapes are detected as a 2-manifold by Castle Model Viewer: see menu item "Help → Manifold Edges Information". To check which edges are actually detected as "border edges" use "View → Fill mode → Silhouette and Border Edges", manifold silhouette edges are displayed yellow and border edges (you want to get rid of them!) are blue.
You can also check manifold edges in Blender: you can easily detect why the mesh is not manifold by "Select → Select All By Trait → Non Manifold" command (press F3 to find this command in edit mode). Also, remember that faces must be ordered consistently CCW — in some cases "Recalculate normals outside" (this actually changes vertex order in Blender) may be needed to reorder them properly.
The shape is a smallest unbreakable unit that we pass to GPU when rendering. It corresponds exactly to glTF primitive and X3D TShapeNode
. When working with Blender, each Blender object corresponds to as many shapes as you use materials in that Blender object (so, usually just one).
Putting the requirement to be 2-manifold on shape, not on scene, has advantages and disadvantages:
-
Advantage: We prepare and render shadow volumes per-shape, so we work efficiently with dynamic models. Transforming a shape (move, rotate…), or changing the active shapes has zero cost, no data needs to be recalculated.
-
Advantage: We can avoid rendering per-shape. We can reject shadow volume rendering for shape if we know shape’s shadow will never be visible from the current camera view.
-
Advantage: Not the whole scene needs to be 2-manifold. If a shape is 2-manifold, it casts shadow. If your scene has both 2-manifold and non-2-manifold shapes, it will work OK, just only a subset of shapes (the 2-manifold ones) will cast shadows.
-
Disadvantage: The whole shape must be 2-manifold. You cannot create 2-manifold scenes by summing multiple non-2-manifold shapes.
4.1. Optional: Treat whole scene as 2-manifold
This is useful when your model is composed from multiple shapes that together are 2-manifold. For example, if your mesh in Blender is 2-manifold but it uses multiple materials. In such case, exporting it to glTF or X3D splits each mesh into multiple shapes. Each shape is not 2-manifold but whole scene is.
Note that when MyScene.RenderOptions.WholeSceneManifold
is true
, right now we assume that your whole scene is 2-manifold. We do not check it! You have to make sure it is true (e.g. check in Blender using "Select → Select All By Trait → Non Manifold" mentioned above). If the scene is not actually 2-manifold, rendering artifacts will appear.