mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(render): translucent icon sets on the GPU blend as Cesium's translucent billboards
A GPU icon set whose blend is translucent draws every row in one alpha-blended pass in row order (LEQUAL, depth written), as BlendOption.TRANSLUCENT billboards do, in place of the opaque and translucent passes the set's blend only re-blended: overlapping icons kept the first row's fill and lost the outlines of those over it. The vessels, shipwrecks and FIRMS sets ask for that blend again, as their billboard collections did.
This commit is contained in:
1 parent
aa58886e40
commit
06516819da
6 files changed
+60
-7
No files matched your search
@@ -466,6 +466,8 @@ export function createRendering({
|
|||||||
if (!layerState._viewer || layerState._icons) return;
|
if (!layerState._viewer || layerState._icons) return;
|
||||||
const set = drawOf(layerState._viewer).icons({
|
const set = drawOf(layerState._viewer).icons({
|
||||||
id: `firms:${++iconSets}:icons`,
|
id: `firms:${++iconSets}:icons`,
|
||||||
|
// Blended in one pass, in order, as the detections overlap.
|
||||||
|
blend: 'translucent',
|
||||||
horizonCull: true,
|
horizonCull: true,
|
||||||
show: layerState._enabled && !(layerState._handoffHeat >= 1),
|
show: layerState._enabled && !(layerState._handoffHeat >= 1),
|
||||||
drawOrder: spriteDrawOrder?.('firms') ?? 0,
|
drawOrder: spriteDrawOrder?.('firms') ?? 0,
|
||||||
|
|||||||
@@ -380,6 +380,9 @@ export function createShipwrecksLayer({
|
|||||||
// sprite layers (`SPRITE_LAYER_ORDER`).
|
// sprite layers (`SPRITE_LAYER_ORDER`).
|
||||||
_markers = drawOf(viewer).icons({
|
_markers = drawOf(viewer).icons({
|
||||||
id: 'shipwrecks:markers',
|
id: 'shipwrecks:markers',
|
||||||
|
// Blended in one pass, in order: the wrecks added last (the
|
||||||
|
// largest) on top.
|
||||||
|
blend: 'translucent',
|
||||||
drawOrder: spriteDrawOrder(SHIPWRECKS_LAYER_ID),
|
drawOrder: spriteDrawOrder(SHIPWRECKS_LAYER_ID),
|
||||||
show: false,
|
show: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -145,6 +145,9 @@ export function createRendering({
|
|||||||
if (!viewer || state.icons) return;
|
if (!viewer || state.icons) return;
|
||||||
const set = drawOf(viewer).icons({
|
const set = drawOf(viewer).icons({
|
||||||
id: `ais-vessels:${++instances}`,
|
id: `ais-vessels:${++instances}`,
|
||||||
|
// Blended in one pass, in order, each chevron keeping its outline
|
||||||
|
// over the ones under it.
|
||||||
|
blend: 'translucent',
|
||||||
horizonCull: true,
|
horizonCull: true,
|
||||||
drawOrder: spriteDrawOrder?.('ais') ?? 0,
|
drawOrder: spriteDrawOrder?.('ais') ?? 0,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ export function createGpuIcons({
|
|||||||
clockTime(frameState, new Cesium.JulianDate()),
|
clockTime(frameState, new Cesium.JulianDate()),
|
||||||
requestRender: () => requestRender(`icons:${spec.id}`),
|
requestRender: () => requestRender(`icons:${spec.id}`),
|
||||||
cull: () => spec.horizonCull === true,
|
cull: () => spec.horizonCull === true,
|
||||||
|
translucent: () => spec.blend === 'translucent',
|
||||||
// Picked as the draw port's other items are: `{set, id, meta}` as
|
// Picked as the draw port's other items are: `{set, id, meta}` as
|
||||||
// the item now is, hidden row by row for drill picks.
|
// the item now is, hidden row by row for drill picks.
|
||||||
pickObject: (id, _set, primitive) => ({
|
pickObject: (id, _set, primitive) => ({
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ void main() {
|
|||||||
if (color.a < 0.005) discard;
|
if (color.a < 0.005) discard;
|
||||||
#ifdef OPAQUE
|
#ifdef OPAQUE
|
||||||
if (color.a < 0.995) discard;
|
if (color.a < 0.995) discard;
|
||||||
#else
|
#elif defined(TRANSLUCENT)
|
||||||
if (color.a >= 0.995) discard;
|
if (color.a >= 0.995) discard;
|
||||||
#endif
|
#endif
|
||||||
out_FragColor = color;
|
out_FragColor = color;
|
||||||
@@ -320,20 +320,32 @@ const EARTH_BOUNDS = new Cesium.BoundingSphere(
|
|||||||
/**
|
/**
|
||||||
* @param {{ set: object, renderTime: (frameState: object) => Cesium.JulianDate,
|
* @param {{ set: object, renderTime: (frameState: object) => Cesium.JulianDate,
|
||||||
* requestRender?: () => void, cull?: () => boolean,
|
* requestRender?: () => void, cull?: () => boolean,
|
||||||
|
* translucent?: () => boolean,
|
||||||
* pickObject?: (id: string, set: object, primitive: object) => object }} options
|
* pickObject?: (id: string, set: object, primitive: object) => object }} options
|
||||||
* `renderTime` gives the instant to draw at (the layer's delayed clock), from
|
* `renderTime` gives the instant to draw at (the layer's delayed clock), from
|
||||||
* the frame being drawn. `requestRender` asks for a frame when the atlas packs
|
* the frame being drawn. `requestRender` asks for a frame when the atlas packs
|
||||||
* a newly loaded image, for a layer that does not render continuously.
|
* a newly loaded image, for a layer that does not render continuously.
|
||||||
* `cull` says whether rows past the ellipsoid's horizon are hidden (by
|
* `cull` says whether rows past the ellipsoid's horizon are hidden (by
|
||||||
* default always). `pickObject` builds a row's pick object around the
|
* default always). `translucent` says whether every row is drawn in one
|
||||||
|
* alpha-blended pass, in row order, the last on top (Cesium's
|
||||||
|
* `BlendOption.TRANSLUCENT`), 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` drill picks hide it by (by default `{ id, iconSet, meta,
|
||||||
* primitive }`).
|
* primitive }`).
|
||||||
*/
|
*/
|
||||||
export class IconSetPrimitive {
|
export class IconSetPrimitive {
|
||||||
constructor({ set, renderTime, requestRender, cull, pickObject }) {
|
constructor({
|
||||||
|
set,
|
||||||
|
renderTime,
|
||||||
|
requestRender,
|
||||||
|
cull,
|
||||||
|
translucent,
|
||||||
|
pickObject,
|
||||||
|
}) {
|
||||||
this.set = set;
|
this.set = set;
|
||||||
this.renderTime = renderTime;
|
this.renderTime = renderTime;
|
||||||
this._cull = cull ?? (() => true);
|
this._cull = cull ?? (() => true);
|
||||||
|
this._translucent = translucent ?? (() => false);
|
||||||
this._pickObject = pickObject ?? null;
|
this._pickObject = pickObject ?? null;
|
||||||
this._pickPass = 0;
|
this._pickPass = 0;
|
||||||
this._stopAtlasListener = requestRender
|
this._stopAtlasListener = requestRender
|
||||||
@@ -418,12 +430,23 @@ export class IconSetPrimitive {
|
|||||||
`[iconSetPrimitive] This context addresses ${this._slotCount} icon images; the atlas holds ${iconAtlas.size}, and rows drawing the rest draw nothing`,
|
`[iconSetPrimitive] This context addresses ${this._slotCount} icon images; the atlas holds ${iconAtlas.size}, and rows drawing the rest draw nothing`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (const command of this._commands) {
|
const commands = this._translucent()
|
||||||
|
? [this._singleCommand]
|
||||||
|
: this._commands;
|
||||||
|
for (const command of commands) {
|
||||||
command.instanceCount = set.count;
|
command.instanceCount = set.count;
|
||||||
frameState.commandList.push(command);
|
frameState.commandList.push(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this host draws `blend` itself, so the set's blend leaves its
|
||||||
|
* commands as they are (`setBlend.js`).
|
||||||
|
*/
|
||||||
|
drawsBlend(blend) {
|
||||||
|
return blend === 'translucent' && this._translucent();
|
||||||
|
}
|
||||||
|
|
||||||
_syncAtlas(context) {
|
_syncAtlas(context) {
|
||||||
if (iconAtlas.version === this._atlasVersion || !iconAtlas.canvas) return;
|
if (iconAtlas.version === this._atlasVersion || !iconAtlas.canvas) return;
|
||||||
this._atlasVersion = iconAtlas.version;
|
this._atlasVersion = iconAtlas.version;
|
||||||
@@ -546,7 +569,7 @@ export class IconSetPrimitive {
|
|||||||
this._generation = set.generation;
|
this._generation = set.generation;
|
||||||
for (const rows of Object.values(set.dirty)) rows.markAll();
|
for (const rows of Object.values(set.dirty)) rows.markAll();
|
||||||
if (this._commands)
|
if (this._commands)
|
||||||
for (const command of this._commands)
|
for (const command of [...this._commands, this._singleCommand])
|
||||||
command.vertexArray = this._vertexArray;
|
command.vertexArray = this._vertexArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,7 +749,12 @@ export class IconSetPrimitive {
|
|||||||
sources: [VERTEX_SHADER],
|
sources: [VERTEX_SHADER],
|
||||||
}),
|
}),
|
||||||
fragmentShaderSource: new Cesium.ShaderSource({
|
fragmentShaderSource: new Cesium.ShaderSource({
|
||||||
defines: pass === 'opaque' ? ['OPAQUE'] : ['TRANSLUCENT'],
|
defines:
|
||||||
|
pass === 'opaque'
|
||||||
|
? ['OPAQUE']
|
||||||
|
: pass === 'translucent'
|
||||||
|
? ['TRANSLUCENT']
|
||||||
|
: [],
|
||||||
sources: [FRAGMENT_SHADER],
|
sources: [FRAGMENT_SHADER],
|
||||||
}),
|
}),
|
||||||
attributeLocations: ATTRIBUTE_LOCATIONS,
|
attributeLocations: ATTRIBUTE_LOCATIONS,
|
||||||
@@ -734,6 +762,7 @@ export class IconSetPrimitive {
|
|||||||
this._programs = {
|
this._programs = {
|
||||||
opaque: programFor('opaque'),
|
opaque: programFor('opaque'),
|
||||||
translucent: programFor('translucent'),
|
translucent: programFor('translucent'),
|
||||||
|
single: programFor('single'),
|
||||||
};
|
};
|
||||||
const depthTest = { enabled: true, func: Cesium.DepthFunction.LESS };
|
const depthTest = { enabled: true, func: Cesium.DepthFunction.LESS };
|
||||||
const command = (pass, program, renderState) =>
|
const command = (pass, program, renderState) =>
|
||||||
@@ -766,6 +795,18 @@ export class IconSetPrimitive {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
// Every row in one pass, blended in row order: equal depths pass, and
|
||||||
|
// depth is written in place of sorting, as Cesium's translucent
|
||||||
|
// billboards do.
|
||||||
|
this._singleCommand = command(
|
||||||
|
Cesium.Pass.TRANSLUCENT,
|
||||||
|
this._programs.single,
|
||||||
|
Cesium.RenderState.fromCache({
|
||||||
|
depthTest: { enabled: true, func: Cesium.DepthFunction.LEQUAL },
|
||||||
|
depthMask: true,
|
||||||
|
blending: Cesium.BlendingState.ALPHA_BLEND,
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_destroyBuffers() {
|
_destroyBuffers() {
|
||||||
@@ -785,6 +826,7 @@ export class IconSetPrimitive {
|
|||||||
this._destroyBuffers();
|
this._destroyBuffers();
|
||||||
this._programs?.opaque.destroy();
|
this._programs?.opaque.destroy();
|
||||||
this._programs?.translucent.destroy();
|
this._programs?.translucent.destroy();
|
||||||
|
this._programs?.single.destroy();
|
||||||
this._texture?.destroy();
|
this._texture?.destroy();
|
||||||
// The set outlives its renderer: release only the pick ids this one made.
|
// The set outlives its renderer: release only the pick ids this one made.
|
||||||
const set = this.set;
|
const set = this.set;
|
||||||
|
|||||||
@@ -129,7 +129,9 @@ export function blendHost(host, blendOf) {
|
|||||||
const start = list.length;
|
const start = list.length;
|
||||||
const result = update.call(this, frameState);
|
const result = update.call(this, frameState);
|
||||||
if (!frameState.passes?.render) return result;
|
if (!frameState.passes?.render) return result;
|
||||||
const blend = blendOf();
|
// A host that draws this blend itself keeps its commands as made.
|
||||||
|
const asked = blendOf();
|
||||||
|
const blend = this.drawsBlend?.(asked) ? undefined : asked;
|
||||||
if (blend === undefined && !turnedAny) return result;
|
if (blend === undefined && !turnedAny) return result;
|
||||||
if (blend !== undefined) turnedAny = true;
|
if (blend !== undefined) turnedAny = true;
|
||||||
blendCommands(list, start, blend);
|
blendCommands(list, start, blend);
|
||||||
|
|||||||
Reference in new issue
Block a user