# Possibility of controlling the rendering order of primitives that "ignore" the depth buffer

**URL:** <https://community.cesium.com/t/possibility-of-controlling-the-rendering-order-of-primitives-that-ignore-the-depth-buffer/40563>\
**Category:** CesiumJS\
**Created:** [May 12, 2025, 12:57pm UTC](https://community.cesium.com/t/possibility-of-controlling-the-rendering-order-of-primitives-that-ignore-the-depth-buffer/40563 "2025-05-12T12:57:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![david-hodgetts](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/david-hodgetts/32/24587_2.png) [@david-hodgetts](https://community.cesium.com/u/david-hodgetts)\
**Post date:** [May 12, 2025, 12:57pm UTC](https://community.cesium.com/t/possibility-of-controlling-the-rendering-order-of-primitives-that-ignore-the-depth-buffer/40563/1 "2025-05-12T12:57:17Z")

</div>

We are in the process of writing a collection of drawing tools on top of Cesium.

In that context, we define a set of visual aids/widgets to help the user interact with the drawings.  
Notably, we use **PointGraphics** to represent vertices that can be interacted with.

Ideally, these control vertices should be drawn on top of the final rendered frame (they should ignore the depth-buffer and be rendered last).

We can ensure that the vertices ignore the depth buffer (via the **disableDepthTestDistance** property). However, some of our drawing shapes define a **depthTestFailMaterial** , which we use to make them visible when they intersect with their environment (3D tilesets). In this case, when the drawing renders its “depth test failed” part, it seems to be drawn last, after the vertices, i.e. on top of the vertices.

Is there a way to control the rendering order in that situation?

I guess we could render the vertex control dots on top of Cesium’s canvas, either with dom elements or another canvas, but I wanted to make sure I was not missing something before going that route.

The following [sandcastle](https://sandcastle.cesium.com/#c=rVbbbuM2EP0VIk8K4KVF3Ui5SdDUyW4NZB0jmy5QNEVAS0xMVBZdksqlRf69Q1GyY8dpUKBPFsmZM3NmzpAuVG0sepDiUWh0jGrxiMbCyGaJv7d7wc1B0a7HqrZc1kLfHBz+cFPf1MMhul5Igwyvy4IbWwkkq6oxVnMrDOJIi7oUWtb3SGn4QH82wlipatz6Tix6VE1VorlAJUTQfA4IVrl1/+kRkF0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2b1wr1T7Nl3BjVPzZmS3IyYXfxBgfDWG539MqVc253kH+Bw) illustrates the situation.

---

<div class="post-metadata">

**Author:** ![jjhembd](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jjhembd/32/10144_2.png) [@jjhembd](https://community.cesium.com/u/jjhembd)\
**Post date:** [May 19, 2025, 11:05pm UTC](https://community.cesium.com/t/possibility-of-controlling-the-rendering-order-of-primitives-that-ignore-the-depth-buffer/40563/2 "2025-05-19T23:05:36Z")

</div>

Hi @david-hodgetts, have you considered using a [BillboardCollection](https://cesium.com/learn/cesiumjs/ref-doc/BillboardCollection.html) instead of `PointGraphics`? This would give you the option of setting `eyeOffset`. Note that there are [some issues with this approach](https://github.com/CesiumGS/cesium/issues/4108). But it might be more efficient than layering another canvas.

---

<div class="post-metadata">

**Author:** ![david-hodgetts](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/david-hodgetts/32/24587_2.png) [@david-hodgetts](https://community.cesium.com/u/david-hodgetts)\
**Post date:** [May 20, 2025, 9:31am UTC](https://community.cesium.com/t/possibility-of-controlling-the-rendering-order-of-primitives-that-ignore-the-depth-buffer/40563/3 "2025-05-20T09:31:23Z")

</div>

Hi @jjhembd,

Thanks for getting back to me.

I did try the `BillboardCollection` approach (with an `eyeOffset`). Unless I am doing something wrong, this leads to the same visual result. See following [sandcastle](https://sandcastle.cesium.com/#c=rVbbbuM2EP0Vwk9y4aV1p+RN0madZGsgaxtJdoGiLgJaoi1iJdKlqCRukX/vUBdfkmyDAn0wLA5nztwOh0ykKDV64OyRKXSKBHtEY1byqsDfapm16CX1eiyFplwwtej1Py7EQgyH6C7jJSqpSBNa6pwhnudVqRXVrEQUKSZSprhYI6ngA/1ZsVJzKXBtO9HoUVZ5ipYMpeBB0SUgaGnW3WeDgHTG0EZyodFa0U3GkxJJAfsbJFc1llEYy01OBVVzmW/XsG09gmKGMmpCSdlGZ1eU5+ebDaOKioT1sUkiqdNPaMEUncuSm/iOyzCmCtLhVHi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IEGzQj6dnk/mV5NpvuDiBDbstlqBVfx6AeT165L+MGxd+Rvq9Ab9E5Kvc3ZWYf1Cy82UmlUQe4YDzUrYIABznBZJd8ZMKUsm7cJQifDQ9OTlD8gnp6+8fJDSU7LEnZWVZ7f8r/Yond2MgT9V6a5rF8yMxjIOd0atcw5u26EGOOTISzfttRS5kuqXiD/Aw) for reference.

I did start to look at writing a fully custom primitive, thereby hoping to be able to use a custom `DrawCommand` to specify the primitive as being drawn in the `OVERLAY` pass. But I have not been able to give this idea sufficient time to obtain a successful result. I am also a bit weary about this approach since it involves using Cesium’s internal apis.

Best regards,

---

<div class="post-metadata">

**Author:** ![jjhembd](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jjhembd/32/10144_2.png) [@jjhembd](https://community.cesium.com/u/jjhembd)\
**Post date:** [May 21, 2025, 10:01pm UTC](https://community.cesium.com/t/possibility-of-controlling-the-rendering-order-of-primitives-that-ignore-the-depth-buffer/40563/4 "2025-05-21T22:01:30Z")

</div>

Hi @david-hodgetts, that new Sandcastle does clarify things.

I think by setting a `depthFailAppearance` on the polygon, we are basically requesting to “render this polygon on top no matter what.” Once we make that request, we don’t really have a way to add an exception, i.e., “but not if there is a Point on top of it.”

This level of control is what a z-index is for. Perhaps you could add your use case to the [issue about z-ordering of entities](https://github.com/CesiumGS/cesium/issues/4108).

---

<div class="post-metadata">

**Author:** ![david-hodgetts](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/david-hodgetts/32/24587_2.png) [@david-hodgetts](https://community.cesium.com/u/david-hodgetts)\
**Post date:** [May 23, 2025, 6:23am UTC](https://community.cesium.com/t/possibility-of-controlling-the-rendering-order-of-primitives-that-ignore-the-depth-buffer/40563/5 "2025-05-23T06:23:56Z")

</div>

Hi @jjhembd, I came to same conclusion as you.  
I will do as you suggest, and add this case to the github issue you mention.  
Thanks for your time,  
Best regards,  
David
