Skip to content

Commit

Permalink
Day 17-ish: Final culling tweaks
Browse files Browse the repository at this point in the history
- I talked about this a little on stream in the lost 30 minutes, but due
  to top-left rasterization convention it is probably safe to slightly
  reduce the tested bbox. This reduces triangle count by an extra ~1.5%
  without visible holes

- Meshlet frustum culling was accidentally committed without the far
  plane check; it's conservative to do this but it feels reasonable to
  keep it.
  • Loading branch information
zeux committed Dec 24, 2022
1 parent 8923b10 commit e9f3a89
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/niagara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ int main(int argc, const char** argv)
double drawsPerSec = double(drawCount) / double(frameGpuAvg * 1e-3);

char title[256];
sprintf(title, "cpu: %.2f ms; gpu: %.2f ms (cull: %.2f ms, pyramid: %.2f ms, cull late: %.2f); triangles %.1fM; %.1fB tri/sec, %.1fM draws/sec; mesh shading %s, frustum culling %s, occlusion culling %s, level-of-detail %s",
sprintf(title, "cpu: %.2f ms; gpu: %.2f ms (cull: %.2f ms, pyramid: %.2f ms, cull late: %.2f); triangles %.2fM; %.1fB tri/sec, %.1fM draws/sec; mesh shading %s, frustum culling %s, occlusion culling %s, level-of-detail %s",
frameCpuAvg, frameGpuAvg, cullGpuTime, pyramidGpuTime, culllateGpuTime,
double(triangleCount) * 1e-6, trianglesPerSec * 1e-9, drawsPerSec * 1e-6,
meshShadingSupported && meshShadingEnabled ? "ON" : "OFF", cullingEnabled ? "ON" : "OFF", occlusionEnabled ? "ON" : "OFF", lodEnabled ? "ON" : "OFF");
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/meshlet.mesh.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void main()
float sbprec = 1.0 / 256.0; // note: this can be set to 1/2^subpixelPrecisionBits

// note: this is slightly imprecise (doesn't fully match hw behavior and is both too loose and too strict)
culled = culled || (round(bmin.x - sbprec) == round(bmax.x + sbprec) || round(bmin.y - sbprec) == round(bmax.y + sbprec));
culled = culled || (round(bmin.x - sbprec) == round(bmax.x) || round(bmin.y) == round(bmax.y + sbprec));

// the computations above are only valid if all vertices are in front of perspective plane
culled = culled && (vertexClip[a].z > 0 && vertexClip[b].z > 0 && vertexClip[c].z > 0);
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/meshlet.task.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void main()
visible = visible && center.z * globals.frustum[3] - abs(center.y) * globals.frustum[2] > -radius;
// the near/far plane culling uses camera space Z directly
// note: because we use an infinite projection matrix, this may cull meshlets that belong to a mesh that straddles the "far" plane; we could optionally remove the far check to be conservative
visible = visible && center.z + radius > globals.znear;// && center.z - radius < globals.zfar;
visible = visible && center.z + radius > globals.znear && center.z - radius < globals.zfar;

if (visible)
{
Expand Down

0 comments on commit e9f3a89

Please sign in to comment.