Skip to content

Use log sized bins for depth test OpenGL#751

Open
magnesj wants to merge 2 commits intodevfrom
improve-clip-planes
Open

Use log sized bins for depth test OpenGL#751
magnesj wants to merge 2 commits intodevfrom
improve-clip-planes

Conversation

@magnesj
Copy link
Owner

@magnesj magnesj commented Mar 13, 2026

  • Implement logarithmic depth buffer across all 3D shaders to reduce most z-fighting issues
    • 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

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.
@qodo-code-review
Copy link

Review Summary by Qodo

Implement logarithmic depth buffer and improve clipping plane calculation

✨ Enhancement 🐞 Bug fix

Grey Divider

Walkthroughs

Description
• 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
Diagram
flowchart 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
Loading

Grey Divider

File Changes

1. Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl ✨ Enhancement +14/-0

New vertex shader component for logarithmic depth

Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl


2. Fwk/VizFwk/LibRender/glsl/fs_logDepth.glsl ✨ Enhancement +31/-0

New fragment shader component for log-depth and polygon offset

Fwk/VizFwk/LibRender/glsl/fs_logDepth.glsl


3. Fwk/AppFwk/cafViewer/cafViewer.cpp ✨ Enhancement +64/-20

Add log-depth uniform and improve clipping plane calculation

Fwk/AppFwk/cafViewer/cafViewer.cpp


View more (28)
4. Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp ✨ Enhancement +34/-3

Auto-inject log-depth shader components into all programs

Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp


5. Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.h ✨ Enhancement +2/-0

Add setInjectLogDepth method and m_injectLogDepth flag

Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.h


6. Fwk/VizFwk/LibRender/cvfShaderSourceRepository.cpp ✨ Enhancement +8/-0

Register new vs_logDepth and fs_logDepth shader identifiers

Fwk/VizFwk/LibRender/cvfShaderSourceRepository.cpp


7. Fwk/VizFwk/LibRender/cvfShaderSourceRepository.h ✨ Enhancement +4/-0

Add vs_logDepth and fs_logDepth to shader source enumeration

Fwk/VizFwk/LibRender/cvfShaderSourceRepository.h


8. Fwk/VizFwk/LibRender/cvfShaderSourceStrings.h ✨ Enhancement +117/-0

Add log-depth shader source strings and update all fragment shaders

Fwk/VizFwk/LibRender/cvfShaderSourceStrings.h


9. Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp ✨ Enhancement +40/-12

Add applyPolygonOffset helper and update effect generators

Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp


10. Fwk/AppFwk/CommonCode/cafEffectGenerator.h ✨ Enhancement +4/-0

Declare new applyPolygonOffset static method

Fwk/AppFwk/CommonCode/cafEffectGenerator.h


11. Fwk/AppFwk/cafVizExtensions/cafTransparentWBRenderConfiguration.cpp ✨ Enhancement +1/-6

Use unified applyPolygonOffset method for transparency effects

Fwk/AppFwk/cafVizExtensions/cafTransparentWBRenderConfiguration.cpp


12. ApplicationLibCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp ✨ Enhancement +2/-7

Replace manual polygon offset with applyPolygonOffset call

ApplicationLibCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp


13. ApplicationLibCode/ModelVisualization/RivTernaryScalarMapperEffectGenerator.cpp ✨ Enhancement +1/-5

Use unified applyPolygonOffset method for scalar mapper

ApplicationLibCode/ModelVisualization/RivTernaryScalarMapperEffectGenerator.cpp


14. ApplicationLibCode/ModelVisualization/Intersections/RivExtrudedCurveIntersectionPartMgr.cpp ✨ Enhancement +12/-6

Add polygon offset uniforms to annotation and curve parts

ApplicationLibCode/ModelVisualization/Intersections/RivExtrudedCurveIntersectionPartMgr.cpp


15. ApplicationLibCode/ModelVisualization/Seismic/RivSeismicSectionPartMgr.cpp ✨ Enhancement +7/-3

Add polygon offset uniforms to seismic surface intersection lines

ApplicationLibCode/ModelVisualization/Seismic/RivSeismicSectionPartMgr.cpp


16. Fwk/VizFwk/LibViewing/cvfSingleQuadRenderingGenerator.cpp ✨ Enhancement +2/-1

Disable log-depth injection for screen-space quad rendering

Fwk/VizFwk/LibViewing/cvfSingleQuadRenderingGenerator.cpp


17. Fwk/VizFwk/LibRender/glsl/vs_Standard.glsl ✨ Enhancement +4/-0

Add log-depth hook to standard vertex shader

Fwk/VizFwk/LibRender/glsl/vs_Standard.glsl


18. Fwk/VizFwk/LibRender/glsl/vs_Minimal.glsl ✨ Enhancement +4/-0

Add log-depth hook to minimal vertex shader

Fwk/VizFwk/LibRender/glsl/vs_Minimal.glsl


19. Fwk/VizFwk/LibRender/glsl/vs_MinimalTexture.glsl ✨ Enhancement +4/-0

Add log-depth hook to minimal texture vertex shader

Fwk/VizFwk/LibRender/glsl/vs_MinimalTexture.glsl


20. Fwk/VizFwk/LibRender/glsl/vs_EnvironmentMapping.glsl ✨ Enhancement +4/-0

Add log-depth hook to environment mapping vertex shader

Fwk/VizFwk/LibRender/glsl/vs_EnvironmentMapping.glsl


21. Fwk/VizFwk/LibRender/glsl/vs_VectorDrawer.glsl ✨ Enhancement +4/-0

Add log-depth hook to vector drawer vertex shader

Fwk/VizFwk/LibRender/glsl/vs_VectorDrawer.glsl


22. Fwk/VizFwk/LibRender/glsl/vs_DistanceScaledPoints.glsl ✨ Enhancement +4/-0

Add log-depth hook to distance scaled points vertex shader

Fwk/VizFwk/LibRender/glsl/vs_DistanceScaledPoints.glsl


23. Fwk/VizFwk/LibRender/glsl/vs_ParticleTraceComets.glsl ✨ Enhancement +4/-0

Add log-depth hook to particle trace comets vertex shader

Fwk/VizFwk/LibRender/glsl/vs_ParticleTraceComets.glsl


24. Fwk/VizFwk/LibRender/glsl/fs_Standard.glsl ✨ Enhancement +4/-0

Add log-depth hook to standard fragment shader

Fwk/VizFwk/LibRender/glsl/fs_Standard.glsl


25. Fwk/VizFwk/LibRender/glsl/fs_Unlit.glsl ✨ Enhancement +4/-0

Add log-depth hook to unlit fragment shader

Fwk/VizFwk/LibRender/glsl/fs_Unlit.glsl


26. Fwk/VizFwk/LibRender/glsl/fs_Text.glsl ✨ Enhancement +4/-0

Add log-depth hook to text fragment shader

Fwk/VizFwk/LibRender/glsl/fs_Text.glsl


27. Fwk/VizFwk/LibRender/glsl/fs_VectorDrawer.glsl ✨ Enhancement +4/-0

Add log-depth hook to vector drawer fragment shader

Fwk/VizFwk/LibRender/glsl/fs_VectorDrawer.glsl


28. Fwk/VizFwk/LibRender/glsl/fs_CenterLitSpherePoints.glsl ✨ Enhancement +4/-0

Add log-depth hook to center lit sphere points fragment shader

Fwk/VizFwk/LibRender/glsl/fs_CenterLitSpherePoints.glsl


29. Fwk/VizFwk/LibRender/glsl/fs_FixedColorMagenta.glsl ✨ Enhancement +4/-0

Add log-depth hook to fixed color magenta fragment shader

Fwk/VizFwk/LibRender/glsl/fs_FixedColorMagenta.glsl


30. Fwk/VizFwk/LibRender/glsl/fs_HighlightStencilDraw.glsl ✨ Enhancement +4/-0

Add log-depth hook to highlight stencil draw fragment shader

Fwk/VizFwk/LibRender/glsl/fs_HighlightStencilDraw.glsl


31. Fwk/VizFwk/LibRender/glsl/fs_ParticleTraceComets.glsl ✨ Enhancement +4/-0

Add log-depth hook to particle trace comets fragment shader

Fwk/VizFwk/LibRender/glsl/fs_ParticleTraceComets.glsl


Grey Divider

Qodo Logo

@qodo-code-review
Copy link

qodo-code-review bot commented Mar 13, 2026

Code Review by Qodo

🐞 Bugs (5) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. GLSL330 shader compile failure🐞 Bug ✓ Correctness
Description
ShaderProgramGenerator now injects vs_logDepth/fs_logDepth by default, but those injected sources
use GLSL 1.20-era "varying"; when a program includes any #version 330 shader (e.g. fs_Shadow_v33),
the combined shader version becomes 330 and compilation fails.
Code

Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[R188-197]

+    if (m_injectLogDepth)
+    {
+        // Prepend the log-depth components so that the CVF_LOG_DEPTH_IMPL #define
+        // is visible to all vertex/fragment shaders that have the corresponding hooks.
+        // Screen-space shaders should call setInjectLogDepth(false) to skip this.
+        vertexCodes.push_back(m_sourceProvider->getSourceFromRepository(ShaderSourceRepository::vs_logDepth));
+        vertexNames.push_back("vs_logDepth");
+        fragmentCodes.push_back(m_sourceProvider->getSourceFromRepository(ShaderSourceRepository::fs_logDepth));
+        fragmentNames.push_back("fs_logDepth");
+    }
Evidence
The generator prepends vs_logDepth/fs_logDepth when m_injectLogDepth is true (default). The injected
log-depth shaders declare "varying", while GLSL 330 shaders use in/out with "#version 330";
combining them yields a GLSL 330 program containing illegal "varying" declarations. The repo has a
concrete program construction that combines ShaderProgramGenerator with fs_Shadow_v33 and does not
disable injection.

Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[59-65]
Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[179-231]
Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl[1-5]
Fwk/VizFwk/LibRender/glsl/fs_logDepth.glsl[1-3]
Fwk/VizFwk/LibRender/glsl/fs_Shadow_v33.glsl[1-8]
Fwk/VizFwk/Tests/SnippetsBasis/snipShadows.cpp[236-251]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
ShaderProgramGenerator prepends GLSL120-style log-depth snippets (using `varying`) into programs that may otherwise target GLSL330 (e.g. `fs_Shadow_v33`). This creates invalid combined shaders.
### Issue Context
`ShaderSourceCombiner` can emit `#version 330` when any source contains it; injected snippets must therefore be compatible with that version or not injected.
### Fix Focus Areas
- Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[59-65]
- Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[179-231]
- Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl[1-14]
- Fwk/VizFwk/LibRender/glsl/fs_logDepth.glsl[1-31]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Ortho depth becomes constant🐞 Bug ✓ Correctness
Description
The injected log-depth path computes v_logz from clipPos.w, but cvfCamera’s orthographic projection
matrix keeps clipPos.w constant (w=1). This makes gl_FragDepth constant for orthographic rendering,
breaking depth testing/order for 3D ortho views.
Code

Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl[R11-14]

+void calcLogDepth(vec4 clipPos)
+{
+    v_logz = 1.0 + clipPos.w;
+}
Evidence
The ortho projection matrix sets the last row to (0,0,0,1), so clipPos.w is constant 1 for all
vertices; calcLogDepth stores 1+clipPos.w, so v_logz is constant. applyLogDepth then writes
gl_FragDepth derived only from v_logz, making depth constant regardless of actual clip-space z.

Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl[11-14]
Fwk/VizFwk/LibRender/cvfCamera.cpp[984-1007]
Fwk/VizFwk/LibRender/glsl/fs_logDepth.glsl[21-31]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
In orthographic projection, `clipPos.w` is constant, so the current log-depth computation produces constant `gl_FragDepth` and breaks depth ordering.
### Issue Context
The current log-depth technique relies on perspective-style `w` behavior.
### Fix Focus Areas
- Fwk/VizFwk/LibRender/glsl/vs_logDepth.glsl[1-14]
- Fwk/VizFwk/LibRender/glsl/fs_logDepth.glsl[1-31]
- Fwk/AppFwk/cafViewer/cafViewer.cpp[460-482]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Overlay writes gl_FragDepth🐞 Bug ✓ Correctness
Description
OverlayImage’s shader program generation does not disable log-depth injection, and fs_Unlit now
calls applyLogDepth whenever CVF_LOG_DEPTH_IMPL is defined. This causes overlay rendering to
overwrite gl_FragDepth and depend on u_logDepthFC even though OverlayImage never sets it.
Code

Fwk/VizFwk/LibRender/glsl/fs_Unlit.glsl[R15-19]

  gl_FragColor = color;
+
+#ifdef CVF_LOG_DEPTH_IMPL
+	applyLogDepth();
+#endif
Evidence
OverlayImage builds a shader with vs_MinimalTexture + fs_Unlit using ShaderProgramGenerator, but
does not call setInjectLogDepth(false). Since ShaderProgramGenerator injects fs_logDepth by default
(defining CVF_LOG_DEPTH_IMPL), fs_Unlit will always call applyLogDepth, which reads u_logDepthFC;
OverlayImage only applies fixed uniforms (matrices) and does not set u_logDepthFC.

Fwk/VizFwk/LibRender/cvfOverlayImage.cpp[217-233]
Fwk/VizFwk/LibRender/cvfOverlayImage.cpp[240-245]
Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[59-65]
Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[188-197]
Fwk/VizFwk/LibRender/glsl/fs_Unlit.glsl[15-20]
Fwk/VizFwk/LibRender/glsl/fs_logDepth.glsl[4-6]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Overlay/image shaders are screen-space and should not write logarithmic depth or depend on `u_logDepthFC`, but injection makes `fs_Unlit` call `applyLogDepth()`.
### Issue Context
The PR already disables injection for `SingleQuadRenderingGenerator`, but other screen-space generators (e.g. OverlayImage) were not updated.
### Fix Focus Areas
- Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[59-65]
- Fwk/VizFwk/LibRender/cvfShaderProgramGenerator.cpp[179-203]
- Fwk/VizFwk/LibRender/cvfOverlayImage.cpp[217-233]
- Fwk/VizFwk/LibRender/glsl/fs_Unlit.glsl[15-20]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (2)
4. Comparison uses wrong FC 🐞 Bug ✓ Correctness
Description
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.
Code

Fwk/AppFwk/cafViewer/cafViewer.cpp[R478-481]

+        // 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 );
Evidence
Both renderings share m_globalUniformSet. optimizeClippingPlanes updates u_logDepthFC based on the
main farPlaneDist, then later (in the comparison branch) recomputes near/far and sets the comparison
camera projection, but does not update u_logDepthFC again.

Fwk/AppFwk/cafViewer/cafViewer.cpp[217-218]
Fwk/AppFwk/cafViewer/cafViewer.cpp[468-482]
Fwk/AppFwk/cafViewer/cafViewer.cpp[499-511]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


5. Far plane cannot expand 🐞 Bug ✓ Correctness
Description
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.
Code

Fwk/AppFwk/cafViewer/cafViewer.cpp[R536-549]

+    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;
+
Evidence
The algorithm builds viewFrustum from the current camera projection (includes far plane) and uses
Frustum::isOutside(BoundingBox), which tests all six planes. When anyModelContributed is true, the
fallback to scene bbox is skipped, so excluded models beyond the current far plane cannot influence
farPlaneDist.

Fwk/AppFwk/cafViewer/cafViewer.cpp[536-563]
Fwk/VizFwk/LibGeometry/cvfFrustum.cpp[201-226]
Fwk/VizFwk/LibRender/cvfCamera.cpp[824-832]
Fwk/VizFwk/LibRender/cvfCamera.cpp[855-873]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment on lines +478 to +481
// 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 );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Comment on lines +536 to +549
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant