CesiumGS / cesium

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

Standardize how hidden geometry gets clipped in the vertex shader #8547

Open lilleyse opened 4 years ago

lilleyse commented 4 years ago

There are several systems that batch features together into a single draw call and hide individual features in the vertex shader by accessing their show property in the batch table and forcing them to be clipped. All these systems have a slightly different way of doing this.

The gl_Position.w *= show approach is probably the easiest to use everywhere and is the easiest one to implement as a built-in function. Another thing to look at is how log depth affects all this, especially anything in DerivedCommand.createLogDepthCommand.

lilleyse commented 3 years ago

Another option is setting one of the coordinates to a NaN value. See

From @loshjawrence

ptrgags commented 2 years ago

I wish I had seen this sooner, for ModelExperimental we've been doing yet a different way: positionMC *= 0.0 (see CPUStylingStageVS.glsl). This makes an assumption that WebGL won't render zero-area triangles as a single pixel. We'd have to refactor the shader a bit. If we just switched to gl_Position, the value is likely to get clobbered by later shader stages.

But also, in this forum thread I saw a use case where a user wanted to hide a specific building in a vertex shader so something else could be rendered in its place. We'd need another variable in custom shaders to hide a vertex, as positionMC doesn't have a w component.