Skip to content

Commit 95863b8

Browse files
committed
Add just backface culling as a test (still a little slower than doing nothing)
1 parent bd04e6e commit 95863b8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define TASK_CULL 1
1212

1313
// Should we do triangle frustum and backface culling in mesh shader?
14-
#define MESH_CULL 0
14+
#define MESH_CULL 1
1515

1616
// Maximum number of vertices and triangles in a meshlet
1717
#define MESH_MAXVTX 64

src/shaders/meshlet.mesh.glsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ layout (constant_id = 1) const bool TASK = false;
1919

2020
#define DEBUG 0
2121
#define CULL MESH_CULL
22+
#define FASTCULL 1
2223

2324
layout(local_size_x = MESH_WGSIZE, local_size_y = 1, local_size_z = 1) in;
2425
layout(triangles, max_vertices = MESH_MAXVTX, max_primitives = MESH_MAXTRI) out;
@@ -186,8 +187,12 @@ void main()
186187
}
187188

188189
#if CULL
190+
#if NV_MESH
191+
subgroupMemoryBarrier();
192+
#else
189193
barrier();
190194
#endif
195+
#endif
191196

192197
#if CULL && NV_MESH
193198
uint toff = 0;
@@ -209,6 +214,9 @@ void main()
209214
#if CULL
210215
bool culled = false;
211216

217+
#if NV_MESH && FASTCULL
218+
culled = determinant(mat3(gl_MeshVerticesNV[a].gl_Position.xyw, gl_MeshVerticesNV[b].gl_Position.xyw, gl_MeshVerticesNV[c].gl_Position.xyw)) <= 0;
219+
#else
212220
#if NV_MESH
213221
vec3 ca = gl_MeshVerticesNV[a].gl_Position.xyw;
214222
vec3 cb = gl_MeshVerticesNV[b].gl_Position.xyw;
@@ -244,6 +252,7 @@ void main()
244252

245253
// the computations above are only valid if all vertices are in front of perspective plane
246254
culled = culled && (ca.z > 0 && cb.z > 0 && cc.z > 0);
255+
#endif
247256

248257
#if NV_MESH
249258
uvec4 cballot = subgroupBallot(!culled);

0 commit comments

Comments
 (0)