fix(render): translucent icons stack in order, as Cesium's translucent billboards

Cesium draws BlendOption.TRANSLUCENT billboards in the opaque pass,
blended, LESS_OR_EQUAL with depth written, so overlapping ones stack in
their order, the last on top; in the translucent pass the scene's
order-independent blend averages them. A translucent GPU icon set now
draws its one pass there too, with the depth function Cesium names
LESS_OR_EQUAL (LEQUAL is not one of its names, and fell back to LESS: the
first row won). A set's blend no longer moves the commands of a
collection built translucent into the translucent pass.
This commit is contained in:
Sameh Khamis committed 2026-11-12 12:29:59 -08:00
1 parent 01788c1b10
commit 44c9ed6d5c
3 files changed
+33 -10

No files matched your search

+9 -8
View File
@@ -327,10 +327,9 @@ const EARTH_BOUNDS = new Cesium.BoundingSphere(
* a newly loaded image, for a layer that does not render continuously.
* `cull` says whether rows past the ellipsoid's horizon are hidden (by
* default always). `translucent` says whether every row is drawn in one
* alpha-blended pass, as Cesium's `BlendOption.TRANSLUCENT` billboards
* are, in place of an opaque pass and a translucent one (by default
* never); under order-independent translucency, overlapping rows blend
* together, as those billboards do. `pickObject` builds a row's pick object around the
* alpha-blended pass in the opaque pass, in row order, the last on top, as
* Cesium's `BlendOption.TRANSLUCENT` billboards are, in place of an opaque
* pass and a translucent one (by default never). `pickObject` builds a row's pick object around the
* `primitive` drill picks hide it by (by default `{ id, iconSet, meta,
* primitive }`).
*/
@@ -796,13 +795,15 @@ export class IconSetPrimitive {
}),
),
];
// Every row in one blended pass, equal depths passing and depth written
// in place of sorting, as Cesium's translucent billboards are drawn.
// Every row in one blended pass, in row order, equal depths passing and
// depth written in place of sorting: in the opaque pass, as Cesium's
// translucent billboards are drawn, out of the translucent pass's
// order-independent blend.
this._singleCommand = command(
Cesium.Pass.TRANSLUCENT,
Cesium.Pass.OPAQUE,
this._programs.single,
Cesium.RenderState.fromCache({
depthTest: { enabled: true, func: Cesium.DepthFunction.LEQUAL },
depthTest: { enabled: true, func: Cesium.DepthFunction.LESS_OR_EQUAL },
depthMask: true,
blending: Cesium.BlendingState.ALPHA_BLEND,
}),
+9 -2
View File
@@ -129,9 +129,16 @@ export function blendHost(host, blendOf) {
const start = list.length;
const result = update.call(this, frameState);
if (!frameState.passes?.render) return result;
// A host that draws this blend itself keeps its commands as made.
// A host that draws this blend itself keeps its commands as made: a
// collection built translucent draws in the opaque pass, blended in its
// order, which the translucent pass's order-independent blend would
// average away.
const asked = blendOf();
const blend = this.drawsBlend?.(asked) ? undefined : asked;
const ownBlend =
this.drawsBlend?.(asked) ||
(asked === 'translucent' &&
this.blendOption === Cesium.BlendOption.TRANSLUCENT);
const blend = ownBlend ? undefined : asked;
if (blend === undefined && !turnedAny) return result;
if (blend !== undefined) turnedAny = true;
blendCommands(list, start, blend);
+15
View File
@@ -200,3 +200,18 @@ test('a host that draws the blend itself keeps its commands as made, and others
drawsIt = false;
assert.equal(frame().renderState, given.renderState, 'still as made');
});
test('a collection built translucent keeps its commands where it draws them', () => {
const [mine] = commands();
const host = blendHost(
{
blendOption: Cesium.BlendOption.TRANSLUCENT,
update: (fs) => fs.commandList.push(mine),
},
() => 'translucent',
);
const frameState = { commandList: [], passes: { render: true } };
host.update(frameState);
assert.equal(frameState.commandList[0].pass, Pass.OPAQUE, 'blended in order');
assert.equal(frameState.commandList[0].renderState, opaqueState);
});