-
Notifications
You must be signed in to change notification settings - Fork 0
Scene Structure
facade
models GLTF very closely, using a similar scene and node hierarchy. This page describes the various components involved in a scene and its render.
Much like how GLTF data references other data via indices, facade
models that in a strongly typed manner via Id<Type>
, which is just a glorified std::size_t
. In most cases this represents a direct index into an array (std::vector
) stored within a Scene
, and as a result, scenes do not support removal of individual resources.
Models a GTLF Node, representing node data and a tree of nodes.
Represents the node's local 3D transformation. Its global transformation is computed by recursively multiplying all parent transforms with its own. The 4x4 matrix is cached and only updated when the Transform
is "dirty".
This is a facade
feature that exploits Vulkan's instanced rendering: if Node::instances
is not empty, each transform in that vector is treated as an individual instance during a draw call.
Each node can have zero or more "components" attached: these can be any T
, stored uniquely (one T
instance attachable per Node
). The scene owning the nodes attaches Id<Mesh>
and Id<Camera>
to nodes which have them, which can be queried and mutated by user code. Any other (moveable) types can be attached to any node as well.
Each node owns all its child nodes:
Parent Node
---------|---------
| | |
Node Node Node
Models a GLTF Asset, aka a list of GLTF Scenes and all the data referenced by them. Most assets have zero or one scenes, a facade
scene stores the data for all GLTF scenes but keeps only one's node hierarchy active at any time.
All GLTF scenes within a facade
scene reference into the same shared data, which is modelled by Scene::Storage
.
Contains perspective or orthographic projection parameters. The view matrix is built off the transform of the owning node (per the GLTF spec).
Describes how to sample textures in shaders. The scene will add a default sampler if none exist in a loaded GLTF asset.
Describes the render parameters for a PBR (Physically Based Rendering) workflow, including Id
s of referenced textures.
Owns geometry (vertex and index buffers) uploaded to the GPU, can be used in a draw call.
Decompressed bytestream for 4-channel (RGBA) image data.
Owns a Vulkan image and image view uploaded to the GPU, can be bound to descriptor sets from a pipeline.
Models a GLTF Mesh: an ordered vector of primitives.
Contains an Id<StaticMesh>
and an optional Id<Material>
, describes the geometry and shader parameters for a draw call.
Models a GLTF scene: an ordered vector of all its root nodes.
Models a GLTF node in a GLTF scene; the owning scene attaches mesh and camera Id
s as read from the GLTF source data. Id<Node>
s are monotonically increasing, assigned by the scene, unlike the others which are straight indices. A node can be searched for using its Id
: the scene will perform a depth first search into the tree. Users should NOT store pointers to nodes as they are not address stable; store the Id
instead and retrieve the node when desired.
The Id
of the Mesh attached to a node, if any.
The Id
of the Camera attached to a node, if any.
- Write global uniform / storage buffers (view and lights)
- Call recursive function for each root node, passing identity as the parent transform
- Compute node's model matrix (parent * node)
- If node has a mesh attached, for each primitive:
- Obtain material, get or build pipeline
- Bind globals to set 0
- Have material update its sets;
LitMaterial
:- Update textures to set 1
- Write data to set 2
- Obtain static mesh
- Write instance matrices to scratch vertex buffer
- Bind geometry and instance vertex buffers
- Perform instanced draw