You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,8 @@ When optimizing a mesh, to maximize rendering efficiency you should typically fe
42
42
3. (optional) Overdraw optimization
43
43
4. Vertex fetch optimization
44
44
5. Vertex quantization
45
-
6. (optional) Shadow indexing
45
+
6. Index filtering
46
+
7. (optional) Shadow indexing
46
47
47
48
### Indexing
48
49
@@ -145,6 +146,18 @@ unsigned short pz = meshopt_quantizeHalf(v.z);
145
146
146
147
Since quantized vertex attributes often need to remain in their compact representations for efficient transfer and storage, they are usually dequantized during vertex processing by configuring the GPU vertex input correctly to expect normalized integers or half precision floats, which often needs no or minimal changes to the shader code. When CPU dequantization is required instead, `meshopt_dequantizeHalf` can be used to convert half precision values back to single precision; for normalized integer formats, the dequantization just requires dividing by 2^N-1 for unorm and 2^(N-1)-1 for snorm variants. For example, manually reversing `meshopt_quantizeUnorm(v, 10)` can be done by dividing by 1023.
147
148
149
+
### Index filtering
150
+
151
+
Some meshes may contain triangles that are processed during rendering but do not contribute to the rendered result. If any two vertices of a triangle result in the same position after vertex shader, the triangle is degenerate and will be skipped by the rasterizer. Some triangles may also be duplicates of an earlier triangle with the same post-transform positions and winding, in which case only one of the triangles will be visible depending on depth testing settings (assuming blending is disabled). In either case, such triangles require extra processing and removing them may improve rasterization or ray tracing performance; this library provides an algorithm that removes such triangles from the index buffer:
Note that the example above assumes only positions are relevant for transforming the vertices, but for deformable meshes skinning data may need to be added to the vertex portion used as a key; `meshopt_filterIndexBufferMulti` can be useful for these cases if the relevant data is not contiguous.
158
+
159
+
Filtering after quantization is convenient because quantization may increase the number of redundant triangles if triangles had similar but not identical vertex positions before quantization. However, filtering can be done at any point in the pipeline as soon as the index buffer becomes available; you could also run vertex fetch optimization after filtering, since it will naturally filter out any vertices that may become unused after redundant triangles are eliminated, potentially saving extra memory.
160
+
148
161
### Shadow indexing
149
162
150
163
Many rendering pipelines require meshes to be rendered to depth-only targets, such as shadow maps or during a depth pre-pass, in addition to color/G-buffer targets. While using the same geometry data for both cases is possible, reducing the number of unique vertices for depth-only rendering can be beneficial, especially when the source geometry has many attribute seams due to faceted shading or lightmap texture seams.
@@ -923,6 +936,7 @@ Currently, the following APIs are experimental:
* Experimental: Filter out redundant triangles from the index buffer and return the number of remaining indices
108
+
* Triangles are considered redundant if they are degenerate (two vertices have the same vertex key) or duplicate (matching triangle was present earlier).
109
+
* First vertex_size bytes of every vertex are compared for equality; typically vertex_size should be set to the size of the position attribute.
110
+
* Note that duplicate triangles with opposite windings are preserved, as they may be needed for double-sided rendering.
111
+
*
112
+
* destination must contain enough space for the resulting index buffer (index_count elements)
* Experimental: Filter out redundant triangles from the index buffer and return the number of remaining indices
118
+
* Triangles are considered redundant if they are degenerate (two vertices have the same vertex key) or duplicate (matching triangle was present earlier).
119
+
* All bytes in specified streams are compared for equality; streams should include attributes relevant for position transform (e.g. bone influences).
120
+
* Note that duplicate triangles with opposite windings are preserved, as they may be needed for double-sided rendering.
121
+
*
122
+
* destination must contain enough space for the resulting index buffer (index_count elements)
0 commit comments