diff --git a/src/render/cesium/iconSetPrimitive.js b/src/render/cesium/iconSetPrimitive.js index c7e1534d1..158b9089d 100644 --- a/src/render/cesium/iconSetPrimitive.js +++ b/src/render/cesium/iconSetPrimitive.js @@ -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, }), diff --git a/src/render/cesium/setBlend.js b/src/render/cesium/setBlend.js index 0df57cbc0..32d0f11ac 100644 --- a/src/render/cesium/setBlend.js +++ b/src/render/cesium/setBlend.js @@ -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); diff --git a/src/render/cesium/setBlend.test.mjs b/src/render/cesium/setBlend.test.mjs index 433cf13cd..14c37b23f 100644 --- a/src/render/cesium/setBlend.test.mjs +++ b/src/render/cesium/setBlend.test.mjs @@ -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); +});