Castle Game Engine internals

(Outdated) Overview of the Castle Game Engine and VRML 1.0

Michalis Kamburelis

You can redistribute and/or modify this document under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.


Table of Contents

Goals
1. Overview of VRML
1.1. First example
1.2. Fields
1.2.1. Field types
1.2.2. Placing fields within nodes
1.2.3. Examples
1.3. Children nodes
1.3.1. Group node examples
1.3.2. The Transform node
1.3.3. Other grouping nodes
1.4. DEF / USE mechanism
1.4.1. VRML file as a graph
1.5. VRML 1.0 state
1.5.1. Why VRML 2.0 is better
1.6. Other important VRML features
1.6.1. Inline nodes
1.6.2. Texture transformation
1.6.3. Navigation
1.6.4. IndexedFaceSet features
1.6.5. Prototypes
1.6.6. X3D features
1.6.7. Events mechanism
1.6.8. Scripting
1.6.9. More features
2. Scene Manager
2.1. Scene manager, and basic example of using our engine
2.2. Manage your own scene manager
2.3. 2D controls manager
2.4. Custom viewports
3. Reading, writing, processing VRML scene graph
3.1. TVRMLNode class basics
3.2. The sum of VRML 1.0 and 2.0
3.3. Reading VRML files
3.4. Writing VRML files
3.4.1. DEF / USE mechanism when writing
3.4.2. VRML graph preserving
3.5. Constructing and processing VRML graph by code
3.6. Traversing VRML graph
3.7. Geometry nodes features
3.7.1. Bounding boxes
3.7.2. Triangulating
3.8. WWWBasePath property
3.9. Defining your own VRML nodes
3.10. VRML scene
3.10.1. VRML shape
3.10.2. Simple tree of shapes
3.10.3. Events
3.10.4. Various comfortable routines
3.10.5. Caching
3.10.6. Events and ChangedField notifications
4. Octrees
4.1. Collision detection
4.2. How octree works
4.2.1. Checking for collisions using the octree
4.2.2. Constructing octree
4.3. Octrees for dynamic worlds
4.3.1. Transforming between world and local coordinates
4.3.2. The future — dynamic irregular octrees
4.4. Similar data structures
5. Ray-tracer rendering
5.1. Using octree
5.2. Classic deterministic ray-tracer
5.3. Path-tracer
5.4. RGBE format
5.5. Generating light maps
6. OpenGL rendering
6.1. VRML lights rendering
6.1.1. Lighting model
6.1.2. Rendering lights
6.2. Geometry arrays
6.2.1. Rendering using geometry arrays and VBO
6.2.2. Caching of shapes arrays and VBOs
6.3. Basic OpenGL rendering
6.3.1. OpenGL resource cache
6.3.2. Specialized OpenGL rendering routines vs Triangulate approach
6.4. VRML scene class for OpenGL
6.4.1. Material transparency using OpenGL alpha blending
6.4.2. Material transparency using polygon stipple
6.4.3. Shape granularity
7. Animation
7.1. Interactive (glTF, X3D, VRML, Spine...)
7.1.1. 3D formats support
7.2. Non-interactive precalculated animation
7.2.1. 3D formats support
7.2.2. Structural equality
7.2.3. Generating intermediate scenes
7.2.4. Storing precalculated animations in castle-anim-frames files
8. Shadow Volumes
8.1. Quick overview how to use shadow volumes in our engine
8.2. Inspecting models manifold edges
8.3. Ghost shadows
8.4. Problems with BorderEdges (models not 2-manifold)
8.4.1. Lack of shadows (analogous to ghost shadows)
8.4.2. Not closed silhouettes due to BorderEdges
8.4.3. Invalid capping for z-fail method
9. Links
9.1. VRML / X3D specifications
9.2. Author's resources

List of Figures

1.1. VRML 1.0 sphere example
1.2. VRML 2.0 sphere example
1.3. Cylinder example, rendered in wireframe mode (because it's unlit, non-wireframe rendering would look confusing)
1.4. VRML points example: yellow point at the bottom, blue point at the top
1.5. A cube and a sphere in VRML 1.0
1.6. An unlit box and a sphere in VRML 2.0
1.7. A box and a translated sphere
1.8. A box, a translated sphere, and a translated and scaled sphere
1.9. Two cones with different materials
1.10. A box and a translated sphere using the same texture
1.11. Three columns of three spheres
1.12. Faces, lines and point sets rendered using the same Coordinate node
1.13. Spheres with various material in VRML 1.0
1.14. An example how properties leak out from various grouping nodes in VRML 1.0
1.15. Our earlier example of reusing cone inlined a couple of times, each time with a slight translation and rotation
1.16. Textured cube with various texture transformations
1.17. Viewpoint defined for our previous example with multiplied cones
1.18. Three towers with various creaseAngle settings
2.1. Three 3D objects are rendered here: precalculated dinosaur animation, scripted (could be interactive) fountain animation, and static tower.
2.2. Simple scene, viewed from various viewports simultaneously.
2.3. Interactive scene, with shadows and mirors, viewed from various viewports.
4.1. A sample octree constructed for a scene with two boxes and a sphere
4.2. A nasty case when a box is considered to be colliding with a frustum, but in fact it's outside of the frustum
5.1. lets_take_a_walk scene, side view
5.2. lets_take_a_walk scene, top view
5.3. Generated ground texture
5.4. lets_take_a_walk scene, with ground texture. Side view
5.5. lets_take_a_walk scene, with ground texture. Top view.
6.1. All the trees visible on this screenshot are actually the same tree model, only moved and rotated differently.
6.2. The correct rendering of the trees with volumetric fog
6.3. The wrong rendering of the trees with volumetric fog, if we would use the same arrays/VBO (containing fog coordinate for each vertex) for both trees.
6.4. Rendering without the fog (camera frustum culling is used)
6.5. Rendering with the fog (only objects within the fog visibility range need to be rendered)
6.6. The ghost creature on this screenshot is actually very close to the player. But it's transparent and is rendered incorrectly: gets covered by the ground and trees.
6.7. The transparent ghost rendered correctly: you can see that it's floating right before the player.
6.8. Material transparency with random stipples
6.9. Material transparency with regular stipples
8.1. Fountain level, no shadows
8.2. Fountain level, shadows turned on
8.3. Fountain level, edges marked
8.4. Fountain level, only edges
8.5. Ghost shadows
8.6. Lack of shadows, problem analogous to ghost shadows
8.7. A cylinder capped at the top, open at the bottom
8.8. Cylinder open at the bottom with shadow quads
8.9. Cylinder open at the bottom with shadow edges
8.10. Good shadow from a single triangle
8.11. Good shadow from a single triangle, with shadow volumes drawn
8.12. Bad shadow from a single triangle