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