A 3D model is said to be 2-manifold if 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. There are other, equivalent terms this is sometimes called: 3D mesh can be said to be watertight or closed.
For shadow volumes, the shadow caster must be 2-manifold. There are 3 ways how you can make it happen:
-
Make every shape of your scene a 2-manifold.
The term shape in Castle Game Engine means X3D Shape
node, which is equal to glTF primitive, which is generally equal to a subset of Blender object that has a single material.
This is the most efficient approach, it means that every shape is a potential shadow caster.
The engine detects this case automatically.
-
Or, forget about shapes, but at least make your whole scene a 2-manifold.
This is a common situation when you have a 2-manifold mesh in Blender, 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.
Again, the engine detects this case automatically.
-
Finally, if your scene is not detected as 2-manifold, but you want to force using it as a shadow caster for shadow volumes, accepting eventual rendering artifacts, then you can set TCastleRenderOptions.WholeSceneManifold
to true
. See the Bull model from examples/viewport_and_scenes/shadow_volumes_whole_scene_manifold for an example using it.
Note
|
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. So, there’s an extra "gain" you can have from making your mesh 2-manifold.
|
You can inspect whether your shapes are detected as a 2-manifold by Castle Model Viewer. From the editor, just double-click on a model to open it in Castle Model Viewer.
-
Use the menu item "Help → 2-Manifold Information (Shadow Volumes Casting)" to get a concise report like this:
-
To check how edges are detected use "View → Fill mode → Silhouette and Border Edges".
-
Manifold silhouette edges (that have 2 neighboring faces in the same shape) are displayed as yellow. Only a subset of them are displayed, forming a silhouette of the shape, from the point of view of current camera.
-
Edges that have 2 neighboring faces but in different shapes are displayed as white.
-
Finally, the "bad" border edges, that don’t have 2 neighboring faces, are displayed as blue. You want to get rid of them!
-
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.