depthFailMaterial for polygons?

Hi all,

I was hoping to use depthFailMaterial when displaying some polygon data, it works well for polylines but it seems not to be an option for polygons – is there a technical reason why that can’t work for polys too (and actually, all Entity types with a shading material)?

Or is there perhaps another way of disabling the depth test for specific entities?

Any suggestions appreciated.

Cheers,
AC.

Welcome to the Cesium community!

Looking at the original feature addition (https://github.com/CesiumGS/cesium/pull/5160) it looks like adding a depth fail material for other types of entities was considered, but put on the backburner until more use cases came up.

I think this is already possible for other geometry types, but just not exposed through the Entity API. You can see that the underlying primitive has a “depthFailAppearance”: https://cesium.com/docs/cesiumjs-ref-doc/Primitive.html?classFilter=Primiti

Are the polygons you’re trying to do this for clamped to the ground or not? If they are clamped to the ground, they’ll be using GroundPrimitive which looks like does not have the depthFailAppearance implemented yet: https://cesium.com/docs/cesiumjs-ref-doc/GroundPrimitive.html?classFilter=GroundPr

Hi Omar, just getting back to this now after some delay…

Can you give me any pointers for how I might be able to set the depthFailAppearance of the underlying Primitive?

I found an old thread with a monkey patch to turn off all primitive depth testing:
https://groups.google.com/g/cesium-dev/c/7dDrg0hhru0/m/Hivrk4JRDQAJ

…and that gives me the right result for my polygons, but I’m hoping for a way of doing that for some polygons that rest against other surfaces to enable them to be visible, rather than for all primitives in the scene.

This will be a very common issue for anyone drawing polygons on to photogrammetry (e.g. drone) 3DTile data, as there is always some noise and so the polygons will be badly rendered, intersecting the surface rather than on top.

Any suggestions would be greatly appreciated!

@Andrew_Chapman how is your polygon currently drawn? CesiumJS does now support clamping polygons to 3D Tiles, see: https://sandcastle.cesium.com/index.html?src=Classification%20Types.html.

So as long as you have the classification type set to “both” or “3d tiles” you shouldn’t get any of these clipping artifacts as shown in that image.

Thanks – that’s an interesting workaround if the case was limited to drawing polys on to to the ground, but in my case they need to be arbitrary, e.g. drawing on to the side of a building or steep slope, so classifying via vertical projection won’t work. Even if you could set a projection vector it wouldn’t work in all cases, e.g. a polygon on a convave curved surface, e.g. a sloping ground which gets steeper to become a vertical cliff, very common for coastal datasets

In any case, that feels like a very different kind of functionality, what I really want is a normal polygon Entity, but stop depth testing (or preferably, set a depthFailMaterial). Having control over depth testing has already been established as a very useful thing for billboards and polylines, and I think it is equally useful for polygons, and would then also ensure more consistency between geometry types.

In the meantime though, you hinted that it should be possible to access the underlying polygon primitive and set its depthFailAppearance? Is it possible to do that when the polygon is created as an Entity, or I would need to create them from the start as the lower-level Primitive type?

Cheers!

You are correct - this is indeed a problem we have an open issue for (https://github.com/CesiumGS/cesium/issues/7453). The goal is for this to be an easier way to color/highlight arbitrary surfaces in 3D Tiles, so I was curious if you’d already considered it or run into other issues.

To enable a depthFailMaterial on a polygon, you would need to create it as a primitive, since this property isn’t currently exposed at the Entity API level. Here’s a Sandcastle showing a polygon with a depth fail material.

I think the reason why this isn’t already exposed is that polygons that are clamped to ground use the GroundPrimitive, instead of Primitive. GroundPrimitive does not have a “depthFailAppearance” option yet. I have a GitHub issue here to consider supporting for clamped lines: https://github.com/CesiumGS/cesium/issues/8635