Conversation
Iterate per-model bounding boxes and skip models outside the camera frustum to prevent distant off-screen objects from inflating the far plane. This improves depth buffer precision and reduces z-fighting. Enforce a maximum far/near ratio of 3000.0 by pushing the near plane forward if necessary. Additionally, refine the near plane adjustment when zooming into a point of interest to prevent geometry clipping.
Review Summary by QodoImplement logarithmic depth buffer and improve clipping plane calculation
WalkthroughsDescription• Implement logarithmic depth buffer across all 3D shaders to eliminate z-fighting - Add vs_logDepth.glsl and fs_logDepth.glsl components with automatic injection - Update all 3D vertex/fragment shaders with log-depth hooks - Expose u_logDepthFC uniform computed from far plane each frame • Improve near/far clipping plane calculation by iterating per-model bounding boxes - Skip models outside camera frustum to prevent distant objects inflating far plane - Enforce maximum far/near ratio of 3000.0 to preserve depth buffer precision - Refine near plane adjustment when zooming into point of interest • Fix polygon offset for logarithmic depth buffer rendering - Implement manual polygon offset in fragment shader using derivatives - Add applyPolygonOffset() helper to set both GL state and shader uniforms - Update all effect generators to use new unified polygon offset method Diagramflowchart LR
A["Per-model frustum culling"] --> B["Improved near/far planes"]
B --> C["Max far/near ratio 3000"]
D["Log-depth vertex shader"] --> E["Log-depth fragment shader"]
E --> F["Manual polygon offset"]
G["ShaderProgramGenerator"] --> H["Auto-inject log-depth components"]
H --> I["All 3D shaders enabled"]
B --> J["Update u_logDepthFC uniform"]
J --> I
File Changes1. Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl
|
Code Review by Qodo
1.
|
| // Update the logarithmic depth buffer constant: FC = 2 / log2(far + 1). | ||
| // Shaders use this to compute gl_FragDepth = log2(v_logz) * FC * 0.5. | ||
| float logDepthFC = static_cast<float>( 2.0 / std::log2( farPlaneDist + 1.0 ) ); | ||
| m_globalUniformSet->setLogDepthFarConstant( logDepthFC ); |
There was a problem hiding this comment.
4. Comparison uses wrong fc 🐞 Bug ✓ Correctness
Viewer uses one global uniform set for both main and comparison renderings, but updates u_logDepthFC only after computing the main camera near/far. The comparison camera can be assigned different near/far immediately afterwards without updating u_logDepthFC, making its log-depth mapping incorrect.
Agent Prompt
### Issue description
`u_logDepthFC` is shared across two renderings but only updated for the main camera, so the comparison pass can render with mismatched log-depth parameters.
### Issue Context
Both renderings are configured to share `m_globalUniformSet`.
### Fix Focus Areas
- Fwk/AppFwk/cafViewer/cafViewer.cpp[205-219]
- Fwk/AppFwk/cafViewer/cafViewer.cpp[460-513]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| cvf::Frustum viewFrustum = rendering->camera()->frustum(); | ||
| const cvf::Scene* scene = rendering->scene(); | ||
| bool anyModelContributed = false; | ||
|
|
||
| if ( scene ) | ||
| { | ||
| for ( cvf::uint mIdx = 0; mIdx < scene->modelCount(); ++mIdx ) | ||
| { | ||
| maxDistEyeToCornerAlongViewDir = distEyeBoxCornerAlongViewDir; | ||
| const cvf::Model* model = scene->model( mIdx ); | ||
| cvf::BoundingBox modelBB = model->boundingBox(); | ||
|
|
||
| if ( !modelBB.isValid() ) continue; | ||
| if ( viewFrustum.isOutside( modelBB ) ) continue; | ||
|
|
There was a problem hiding this comment.
5. Far plane cannot expand 🐞 Bug ✓ Correctness
calculateNearFarPlanes filters models using rendering->camera()->frustum(), which includes the current far plane; models beyond the current far plane are excluded from the near/far computation whenever at least one model contributes. This can prevent farPlaneDist from expanding to include newly visible distant geometry.
Agent Prompt
### Issue description
Using the current camera frustum (which includes the current far plane) to cull models can prevent farPlaneDist from increasing when it should.
### Issue Context
Fallback to the scene-wide bbox only triggers when no model contributes, which doesn’t help when some near models are inside but farther models are clipped by the current far plane.
### Fix Focus Areas
- Fwk/AppFwk/cafViewer/cafViewer.cpp[528-575]
- Fwk/VizFwk/LibGeometry/cvfFrustum.cpp[201-226]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Implements the Outerra logarithmic depth buffer method to fix z-fighting caused by poor depth precision when the far/near plane ratio is large. - Add vs_logDepth.glsl / fs_logDepth.glsl components; ShaderProgramGenerator auto-injects them into all 3D shader programs (screen-space programs opt out via setInjectLogDepth(false)) - All 3D vertex shaders call calcLogDepth(gl_Position) to store v_logz; all 3D fragment shaders call applyLogDepth() to write gl_FragDepth - In orthographic mode u_useLogDepth=0 causes applyLogDepth() to fall back to gl_FragCoord.z so depth works correctly without perspective w_clip - glPolygonOffset is bypassed when gl_FragDepth is written explicitly; replace with manual GLSL implementation using dFdx/dFdy slope derivatives and u_polygonOffsetFactor/Units uniforms mirroring the GL state - GlobalViewerDynUniformSet provides u_logDepthFC and u_useLogDepth as per-frame globals; shader programs get zero polygon offset defaults so the uniforms are always satisfied even without explicit polygon offset - Fix vs_CellFace.glsl and vs_2dTextureCellFace.glsl which were missing the calcLogDepth hook, causing undefined v_logz and incorrect depth writes that hid side faces and broke mesh line visibility
67cf10f to
f943519
Compare
Uh oh!
There was an error while loading. Please reload this page.