CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.74k stars 3.45k forks source link

Polylines (and other geometry?) created in 2D no longer cull correctly in 3D #8653

Open mramato opened 4 years ago

mramato commented 4 years ago
  1. Run the materials demo: http://localhost:8080/Apps/Sandcastle/index.html?src=Materials.html&label=All
  2. Switch to 2D.
  3. Select Polyline Arrow from the bottom combo box.
  4. Switch to 3D
  5. The polyline will be drawn even when it is behind the ellipsoid (it does disappear at some point when it's completely on the other side of the center of the earth)

image

TJKoury commented 4 years ago

This is not just an issue with ground polygons, I'm seeing this in 3D with points (and polylines).

IanLilleyT commented 4 years ago

The problem is depth test is being permanently turned off for the primitive after creating it in 2D. Depth test should be turned back on when going back to 3D, but it's not.

Left is when creating the polyline in 2D, Right is when creating it in 3D first:

Screen Shot 2020-05-17 at 1 22 24 AM

Looking deeper, the OIT derived translucent command creates its render state from the derived log depth command, and so if the polyline was created in 2D mode, it forever inherits the depth test off property. https://github.com/CesiumGS/cesium/blob/d07271e21e6f407b6159f44068113a231499d11a/Source/Scene/OIT.js#L563-L566 and https://github.com/CesiumGS/cesium/blob/d07271e21e6f407b6159f44068113a231499d11a/Source/Scene/OIT.js#L584 are the culprits.

In subsequent renders, it copies the log depth command render state in the first code block but reverts it back to its original state in the second.

Not sure where to go from here though as I'm not very familiar with these systems.