Skip to content

cloud_sky: near clouds over far ones, far clouds drawn by VolSliceNode - #1096

Merged
transfix merged 5 commits into
masterfrom
fix/cloud-near-over-far
Nov 10, 2026
Merged

transfix merged 5 commits into
masterfrom
fix/cloud-near-over-far

Conversation

@transfix

@transfix transfix commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Joe reported two things in terrain_lab: "the near clouds appear to render behind the far clouds", and "the lower resolution fuzzy clouds should be rendering like volslice, viewplane aligned slices".

Near clouds behind far ones

There were two causes.

  • Wrong copies. The deck's cloud pattern repeats out to far_reach (4 km), but a near volume drew the copy of its cloud nearest the ground's centre. With the camera at the ground's edge or past it, which is where it is for most views of the whole world, the clouds right in front of it were copies no volume drew. The coarse far deck drew them, fuzzy, over crisp volumes further away. The near volumes now take the copies nearest the camera. Clouds out of view (the diagonal half-angle plus about 15 degrees) rank 4x farther, so the volumes go to clouds on screen rather than to ones beside or behind the camera.
  • Draw order. The near volumes drew in whatever order they joined the renderer, so a farther near cloud could paint over a nearer one. orderDeck now keeps the order as: the far deck, then the near volumes farthest first. It reorders only when two clouds' distances differ by more than 5%, and it runs after the near clouds are placed each frame.

Far clouds drawn by VolSliceNode

The far deck is now a VolSliceNode. Its volume is the deck's coarse opacity, and the clouds' lighting is its sample shader. VolSliceNode gains what that needs, all opt-in, with defaults unchanged:

  • Distance slicing (setDistanceSlicing). Planes face the camera at distances from its eye that grow by a fixed fraction, instead of the even sweep. Here: from 0.1 cloud half-widths out to the deck's far corner, each at least 6% farther than the last, at most 64.
    • The planes go through VolSlice's own plane/box clip. A new cvc::volslice::compute_slices_at runs it at the caller's distances.
    • Each plane stands for the slab behind it, and is cut to the box grown by 1.5x that slab's depth. Without that padding, seen from above, rays crossed the thin deck between two planes and left horizontal gaps.
  • A caller's sample shader (setSampleShader) in place of the volume-then-colour-table lookup. It sees the fragment's local position (volsliceMC), the camera (volsliceEye, volsliceView) and the slices' growth (volsliceGrowth). The clouds' shader marches the part of each slab inside the deck, with about four samples per deck depth (at most six), plus the sunlight march, the near cut-outs and the distance fade.
  • Volume texture wrap (setVolumeWrap): the deck's pattern repeats.
  • Far-plane clamp (setClampToFarPlane): the deck reaches past the scene's bounds, so vertices beyond the far plane are drawn on it.
  • Draw order left alone in the volume layer. A node drawn with the volumes leaves the renderer's order-independent translucency on. Before, every VolSliceNode switched it off for the whole scene.
  • Python. setDistanceSlicing is left out of pycvc (a std::optional of a nested struct). SWIG generates both modules cleanly with the rest.

Master's horizontal shells showed as streaks and stripes seen edge-on from inside or near the deck. Those are gone.

Checked

  • Native arigl snapshots of terrain_lab, before (master f5c2e1b) and after, from five views: low inside the deck at two headings, in the deck, side, and above. They are in the session's shared notes, under cloud-near-over-far/.
    • Low views: master's streaks are gone, and the crisp near clouds sit over the far ones.
    • In-deck: master's hard edge where the far deck was cut out is gone.
    • Above: same tone as master.
  • The VolSliceNode version against this PR's earlier own-mesh far deck: native snapshots match from all five views.
  • New tests:
    • Slicer.SlicesAtDistancesFaceTheViewInTheGivenOrder.
    • cvcgl_volslice_node, distance slicing and sample shader:
      • the planes face the camera at 4 x 1.1^k, far to near;
      • a shader colouring by volsliceMC.x paints red left of centre and green right of it;
      • volsliceEye, volsliceView and volsliceGrowth reach the shader;
      • empty strings restore the default lookup;
      • in the volume layer the renderer keeps its order-independent translucency.
    • cvcgl_ariadne_realize checks four things:
      • every far triangle faces the camera, and they come far to near (level and from above);
      • the near clouds draw after the far deck, far to near, with the camera beside each near cloud;
      • a camera 3 km past the ground gets the near clouds beside it (2 within 334 m; master's would be about 3 km away);
      • the draw order there too.
  • Local Windows Release: 1,186 tests in the cvcGL / Ariadne / Lsys / World / volslice / nav-sim-world subset pass. clang-format 18 was run on the changed lines.

Not checked

The browser (WebGL2) build. The shader stays GLSL ES 3.0: constant loop bounds with break, highp samplers (VolSliceNode's), no new extensions.

Also in this PR

Master's macOS CI fails NavSimWorldAgents.EachPolicyDrivesItsOwnAgents (from #1077). On macOS, one agent's random start leaves it where neither policy moves it. This PR merges master and makes the same one-line change as #1097: compare every agent's position.

Near clouds showed behind far ones for two reasons. A near volume drew
the copy of its cloud nearest the ground's centre, but the deck's
pattern repeats out to far_reach, so with the camera at the ground's
edge or past it the clouds in front of it were drawn by the coarse far
deck, fuzzy, over crisp volumes further off. The near volumes now take
the copies nearest the camera, ranking clouds out of view last. And the
near volumes drew in whatever order they joined the renderer; they now
draw after the far deck, farthest first.

The far deck is drawn as VolSlice draws a volume: planes facing the
camera, cut to the deck's box by cvc::volslice (new compute_slices_at,
the same plane/box clip at the caller's distances) and blended back to
front, spaced wider with distance, at most 64. Each slice marches the
slab behind it, within the deck, so seen edge-on the far clouds no
longer break into horizontal streaks.
…acOS)

The test asserted that agent 2 ends somewhere different under the two
policies, but scatter_free's draw differs between standard libraries,
and on macOS that agent starts where neither policy moves it: both
runs leave it at the same point and the check fails. Compare every
agent's position instead. The same change as #1097.
The far clouds were their own mesh of view-aligned slices that only
borrowed cvc::volslice's plane clip. They are now a VolSliceNode, given
the deck's coarse opacity as its volume, which gains what they need:

- distance slicing (setDistanceSlicing): planes facing the camera at
  distances growing by a fixed fraction, from compute_slices_at, each
  cut to the box grown by a share of its slab's depth;
- a sample shader of the caller's (setSampleShader) in place of the
  volume-then-LUT lookup, seeing the fragment's local position and the
  camera's eye, view direction and the slices' growth;
- repeat wrap on the volume texture (setVolumeWrap) and vertices past
  the far plane drawn on it (setClampToFarPlane);
- a node drawn with the volumes leaves the renderer's order-independent
  translucency on.

The clouds' lighting march is the sample shader. Native snapshots match
the previous mesh's from all five views. setDistanceSlicing is left out
of pycvc (std::optional of a nested struct).
@transfix transfix changed the title cloud_sky: near clouds over far ones, far clouds as view-aligned slices cloud_sky: near clouds over far ones, far clouds drawn by VolSliceNode Nov 9, 2026
@transfix
transfix merged commit 013f6ea into master Nov 10, 2026
30 checks passed
@transfix
transfix deleted the fix/cloud-near-over-far branch November 10, 2026 00:12
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