aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
committer3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
commitbd57f345ed9dbed1d81683e48199626de2ea9044 (patch)
tree4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /README.md
parent9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff)
Restructure projectHEADmain
Diffstat (limited to 'README.md')
-rw-r--r--README.md144
1 files changed, 144 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f0b103d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,144 @@
1# GFX - 3D Rendering Library
2
3A portable 3D rendering library with minimal dependencies written for
4educational purposes.
5
6## Guiding Principles
7
8- Provide enough functionality for graphics applications and indie games.
9- Provide a minimal interface, physically hide the implementation. Make bindings
10 easy.
11- Establish a clean separation from the render backend and the rest of the
12 library to allow for additional rendering backends (e.g. Vulkan).
13- Strive for a minimal set of dependencies, all of which should ship and compile
14 with the graphics library for ease of use.
15- Rely on dynamic allocation as little as possible. Isolate dynamic allocation
16 to where it is strictly needed.
17
18## Design
19
20### Gfx
21
22The `Gfx` object represents the graphics subsystem and is at the center of the
23library's high-level API. The `Gfx` object exposes a `Render` backend and a
24`Renderer` and allows the caller to create `Scene`s.
25
26### Render Backend
27
28The `Render` backend is a thin abstraction layer over low-level graphics APIs
29like OpenGL or Vulkan. It holds GPU resources such as geometry, textures,
30shaders, etc, and exposes functions to manipulate them.
31
32Currently there is only one implementation of the `Render` backend based on
33OpenGL.
34
35#### Ownership
36
37The `Render` backend owns all rendering resources: buffers, geometries,
38textures, shaders, etc. Even resources that point to other resources do not own
39those other resources (geometries pointing to buffers).
40
41There is no ownership tracking in the render backend. It is up to the client to
42manage resource lifetime.
43
44### Scene
45
46A `Scene` encapsulates a scene graph. A scene graph contains the elements that
47make up a scene: nodes, cameras, lights, objects, etc. The current scene graph
48implementation includes:
49
50- Camera
51- Light
52- Material
53- Mesh
54- Node
55- Object
56- Scene
57
58#### Hierarchy and Parenting
59
60Scene graphs typically expose functions on nodes to add/remove objects, cameras,
61lights, etc. This implementation forces the hierarchy to be a strict tree and
62not a more general DAG. Given this, and to avoid confusion, we instead expose
63functions to set the parent node of an object/camera/light. If we exposed the
64former, the API could create the illusion that the hierarchy can be a DAG.
65
66The strict tree hierarchy should not be that restrictive in practice. Even the
67glTF 2.0 spec [enforces this](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#nodes-and-hierarchy):
68
69> *For Version 2.0 conformance, the glTF node hierarchy is not a directed
70> acyclic graph (DAG) or scene graph, but a disjoint union of strict trees. That
71> is, no node may be a direct descendant of more than one node. This restriction
72> is meant to simplify implementation and facilitate conformance.*
73
74#### Instancing
75
76Two use cases for instancing seem to be:
77
781. Creating N identical clones, but each with a unique transform. (Ex: N
79animated characters animated in unison but located in different locations.)
802. Creating N copies of a sub-tree, each now being their own unique tree. (Ex:
81The same N animated characters, but each of them now being animated separately.)
82
83Some scene graphs
84([Panda3D](https://docs.panda3d.org/1.10/python/programming/scene-graph/instancing))
85allow two or more nodes to point to the same child, or, in other words, a node
86to have multiple parents. This turns the scene graph into a DAG and adds a
87number of complications for us:
88
891. Shared ownership of children. We would now need some sort of ref counting or
90deferred GC to delete nodes and their subtrees.
912. Nodes no longer have a unique parent.
923. Given a node, we can no longer determine its location (which parent link do
93you follow?), or any attribute that is derived from its parent(s).
94
95In our case, we stick to strict tree hierarchies.
96
97Use case (1), N identical clones with unique transforms, is not a problem for
98us. This is because the bulk of the data -- geometry buffers, etc. -- is stored
99in the render backend anyway. So creating a full copy of the node does not
100present a significant overhead since we need a unique transform for each of the
101clones anyway.
102
103Use case (2) does present a bit more overhead and we currently do not handle it.
104This could be handled in the future by special-casing a node such as
105`InstanceNode` that has one child subtree and N transforms (or other
106attributes), one for each unique instance of that child subtree.
107
108Therefore, to visit the use cases again:
109
1101. N character clones animated in unison in different locations -> future
111 `InstanceNode`.
1122. N unique character copies animated on their own -> copy the character subtree
113 (N unique skeletons; shared mesh data and textures stored in the render
114 backend.)
115
116#### Reading
117
118[Panda3D Scene Graph](https://docs.panda3d.org/1.10/python/programming/scene-graph/index)
119
120[Pixar's USD](https://graphics.pixar.com/usd/release/intro.html)
121
122### Renderer
123
124The `Renderer` takes a `Render` backend and a `Scene` and renders the scene.
125Currently, only a forward renderer is provided, but additional renderers can be
126implemented in the future.
127
128### Util
129
130Code under `util/` provides functionality that need not be in the core part
131of the library (Gfx, render backend, scene or renderer). This includes functions
132to compute irradiance maps, create procedural geometry, etc.
133
134## Ideas for Future Work
135
136- Render graphs to allow for custom multi-pass rendering algorithms.
137
138## Build (Ubuntu)
139
140```
141sudo apt install libbsd-dev libgl-dev libglfw3-dev zlib1g-dev
142```
143
144TODO: Add these libraries to `contrib/`.