Adding a depth bias to primitives

A while ago I shared a monkey patch which disabled depth testing for primitives and polylines. However, this solution isn’t entirely ideal. In my scenario I have 3D tiles and various types of primitive geometry. The geometry must be positioned at the correct location in space and can’t just be offset to float above the 3D tiles. There are 3 possible cases:

  1. The geometry is positioned on the mesh, but not perfectly clamped. “On” is approximate.
  2. The geometry is above the mesh.
  3. The geometry is behind the mesh.
    The ideal result would render the geometry on top in cases 1 and 2, but occlude parts of the geometry that fit case 3. Using the default depth behavior, cases 2 and 3 of course behave properly, but small inaccuracies in the geometry data vs the 3D tiles result in bad clipping or z fighting for case 1. I can’t use the polyline draping feature as a single line may be clamped to the 3D tiles, then float up into space above the tile. Some more complex geometry rendered with PrimitiveType.TRIANGLES is also involved. What I really want to do is add a depth bias to the various geometry in the scene to ensure it draws on top on the 3D tiles in cases of small error/z fighting, while still occluding geometry that is certainly obstructed from view as in case 3. I have no issue with introducing custom shaders to achieve the desired effect. However, I’m not entirely sure what pitfalls I may encounter as I’ve only spent a small amount of time inside the Cesium source. Is this approach feasible? Any expertise regarding Cesium rendering under the hood would be much appreciated. I know various types of depth sorting control are frequently requested here on the cesium dev forums so if I come up with a good solution here I’ll be sure to share it.

Thanks in advance!