cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Simplify voxel shaders

Open jjhembd opened this issue 2 years ago • 0 comments

Description

This PR simplifies the voxel shaders with two main changes:

  1. Isolate longitude intersection functions in the new IntersectLongitude.glsl, so they can be re-used for both Ellipsoid and Cylinder shapes
  2. Consolidate the shader defines used to handle different ranges of shape bounds

The existing code handled different ranges of shape and render bounds by re-compiling with different defines. For example,

    #if defined(CYLINDER_HAS_SHAPE_BOUNDS_RADIUS_FLAT)
        float radius = 1.0;
    #else
        float radius = length(positionLocal.xy); // [0,1]
        #if defined(CYLINDER_HAS_SHAPE_BOUNDS_RADIUS)
            radius = radius * u_cylinderUvToShapeUvRadius.x + u_cylinderUvToShapeUvRadius.y; // x = scale, y = offset
        #endif
    #endif

The case with RADIUS_FLAT is where the user is not viewing a volume, but a thin shell with constant radius.

With this PR, when the user selects a single radius, the value of the scale and offset in u_cylinderUvToShapeUvRadius is adjusted on the CPU side to return 1.0, so that the same shader path can be used. This approach helps by:

  1. Simplifying both the JS and shader code
  2. Reducing jank caused by shader recompilation when the user adjusts render bounds

While this approach may add some render cost, I believe the added cost is justifiable because:

  • The added cost is minimal (one multiply + add).
  • The added costs appear in the simpler view. The more expensive volumetric view is not affected.
  • The new approach avoids shader recompilation, which is the most significant cost

Testing plan

  1. Verify that the Voxel???Shape specs run successfully
  2. Load the development/Voxels Sandcastle and test different bounds and clipping in the Voxel Inspector

Author checklist

  • [x] I have submitted a Contributor License Agreement
  • [x] I have added my name to CONTRIBUTORS.md
  • [ ] I have updated CHANGES.md with a short summary of my change
  • [ ] I have added or updated unit tests to ensure consistent code coverage
  • [x] I have update the inline documentation, and included code examples where relevant
  • [x] I have performed a self-review of my code

jjhembd avatar Feb 16 '24 23:02 jjhembd