Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add splitDirection property for PointPrimitive #11982

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
947ba72
Add splitDirection to PointPrimitive
YunVlad May 13, 2024
ddea3b7
Add splitDirection to PointPrimitive
YunVlad May 13, 2024
2681891
Specs Update
YunVlad May 14, 2024
d141e93
Update CONTRIBUTORS.md
YunVlad May 14, 2024
90fba65
Update CHANGES.md
YunVlad May 14, 2024
2a6e949
Fixed formatting
YunVlad May 14, 2024
65431b3
Update CHANGES.md
YunVlad May 15, 2024
920cce1
Merge branch 'main' into splitDirection-for-PointPrimitive
YunVlad May 15, 2024
16f21fa
Add splitDirection to Billboard
YunVlad May 28, 2024
e6d4085
Merge branch 'CesiumGS:main' into splitDirection-for-Billboard
YunVlad May 30, 2024
293e3d3
Merge branch 'main' into splitDirection-for-PointPrimitive
YunVlad May 30, 2024
5fa741d
Add Sandcastle example
YunVlad May 30, 2024
fffcf2b
Changed the transmission of the splitDirection attribute
YunVlad May 30, 2024
76151a7
Merge branch 'CesiumGS:main' into splitDirection-for-PointPrimitive
YunVlad May 31, 2024
abe2e58
Merge branch 'CesiumGS:main' into splitDirection-for-Billboard
YunVlad Jun 3, 2024
c6e5ba3
Merge branch 'CesiumGS:main' into splitDirection-for-Billboard
YunVlad Jun 3, 2024
11fc71c
Merge branch 'CesiumGS:main' into splitDirection-for-Billboard
YunVlad Jun 4, 2024
8990124
Merge branch 'main' into splitDirection-for-PointPrimitive
YunVlad Jun 4, 2024
834a79f
Merge branch 'splitDirection-for-Billboard' into splitDirection-for-P…
YunVlad Jun 4, 2024
fe68fb3
Updated PointVisualizer and example
YunVlad Jun 4, 2024
505196a
Specs Update
YunVlad Jun 4, 2024
aa7fe89
Merge branch 'main' into splitDirection-for-PointPrimitive
YunVlad Jun 26, 2024
a12f124
Merge branch 'CesiumGS:main' into splitDirection-for-PointPrimitive
YunVlad Jul 3, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/engine/Source/DataSources/BillboardGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import createPropertyDescriptor from "./createPropertyDescriptor.js";
* @property {Property | BoundingRectangle} [imageSubRegion] A Property specifying a {@link BoundingRectangle} that defines a sub-region of the image to use for the billboard, rather than the entire image, measured in pixels from the bottom-left.
* @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this billboard will be displayed.
* @property {Property | number} [disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to.
* @property {Property | SplitDirection} [splitDirection] A Property specifying the {@link SplitDirection} of the billboard.
*/

/**
Expand Down Expand Up @@ -89,6 +90,8 @@ function BillboardGraphics(options) {
this._distanceDisplayConditionSubscription = undefined;
this._disableDepthTestDistance = undefined;
this._disableDepthTestDistanceSubscription = undefined;
this._splitDirection = undefined;
this._splitDirectionSubscription = undefined;

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
}
Expand Down Expand Up @@ -330,6 +333,14 @@ Object.defineProperties(BillboardGraphics.prototype, {
disableDepthTestDistance: createPropertyDescriptor(
"disableDepthTestDistance"
),

/**
* Gets or sets the Property specifying the {@link SplitDirection} of this billboard.
* @memberof BillboardGraphics.prototype
* @type {Property|undefined}
* @default SplitDirection.NONE
*/
splitDirection: createPropertyDescriptor("splitDirection"),
});

/**
Expand Down Expand Up @@ -362,6 +373,7 @@ BillboardGraphics.prototype.clone = function (result) {
result.imageSubRegion = this._imageSubRegion;
result.distanceDisplayCondition = this._distanceDisplayCondition;
result.disableDepthTestDistance = this._disableDepthTestDistance;
result.splitDirection = this._splitDirection;
return result;
};

Expand Down Expand Up @@ -425,5 +437,9 @@ BillboardGraphics.prototype.merge = function (source) {
this._disableDepthTestDistance,
source.disableDepthTestDistance
);
this.splitDirection = defaultValue(
this.splitDirection,
source.splitDirection
);
};
export default BillboardGraphics;
7 changes: 7 additions & 0 deletions packages/engine/Source/DataSources/BillboardVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import HorizontalOrigin from "../Scene/HorizontalOrigin.js";
import VerticalOrigin from "../Scene/VerticalOrigin.js";
import BoundingSphereState from "./BoundingSphereState.js";
import Property from "./Property.js";
import SplitDirection from "../Scene/SplitDirection.js";

const defaultColor = Color.WHITE;
const defaultEyeOffset = Cartesian3.ZERO;
Expand All @@ -24,6 +25,7 @@ const defaultAlignedAxis = Cartesian3.ZERO;
const defaultHorizontalOrigin = HorizontalOrigin.CENTER;
const defaultVerticalOrigin = VerticalOrigin.CENTER;
const defaultSizeInMeters = false;
const defaultSplitDirection = SplitDirection.NONE;

const positionScratch = new Cartesian3();
const colorScratch = new Color();
Expand Down Expand Up @@ -219,6 +221,11 @@ BillboardVisualizer.prototype.update = function (time) {
billboardGraphics._disableDepthTestDistance,
time
);
billboard.splitDirection = Property.getValueOrDefault(
billboardGraphics._splitDirection,
time,
defaultSplitDirection
);

const subRegion = Property.getValueOrUndefined(
billboardGraphics._imageSubRegion,
Expand Down
31 changes: 29 additions & 2 deletions packages/engine/Source/Scene/Billboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import HorizontalOrigin from "./HorizontalOrigin.js";
import SceneMode from "./SceneMode.js";
import SceneTransforms from "./SceneTransforms.js";
import VerticalOrigin from "./VerticalOrigin.js";
import SplitDirection from "./SplitDirection.js";

/**
* @typedef {object} Billboard.ConstructorOptions
Expand Down Expand Up @@ -49,6 +50,7 @@ import VerticalOrigin from "./VerticalOrigin.js";
* @property {BoundingRectangle} [imageSubRegion] A {@link BoundingRectangle} Specifying the sub-region of the image to use for the billboard, rather than the entire image.
* @property {DistanceDisplayCondition} [distanceDisplayCondition] A {@link DistanceDisplayCondition} Specifying the distance from the camera at which this billboard will be displayed.
* @property {number} [disableDepthTestDistance] A number specifying the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.
* @property {SplitDirection} [splitDirection] A {@link SplitDirection} Specifying the split property of the billboard.
*/

/**
Expand Down Expand Up @@ -250,6 +252,11 @@ function Billboard(options, billboardCollection) {
this._outlineWidth = defaultValue(options.outlineWidth, 0.0);

this._updateClamping();

this._splitDirection = defaultValue(
options.splitDirection,
SplitDirection.NONE
);
}

const SHOW_INDEX = (Billboard.SHOW_INDEX = 0);
Expand All @@ -270,7 +277,8 @@ const DISTANCE_DISPLAY_CONDITION = (Billboard.DISTANCE_DISPLAY_CONDITION = 14);
const DISABLE_DEPTH_DISTANCE = (Billboard.DISABLE_DEPTH_DISTANCE = 15);
Billboard.TEXTURE_COORDINATE_BOUNDS = 16;
const SDF_INDEX = (Billboard.SDF_INDEX = 17);
Billboard.NUMBER_OF_PROPERTIES = 18;
const SPLIT_DIRECTION_INDEX = (Billboard.SPLIT_DIRECTION_INDEX = 18);
Billboard.NUMBER_OF_PROPERTIES = 19;

function makeDirty(billboard, propertyChanged) {
const billboardCollection = billboard._billboardCollection;
Expand Down Expand Up @@ -1072,6 +1080,24 @@ Object.defineProperties(Billboard.prototype, {
}
},
},

/**
* Gets or sets the {@link SplitDirection} of this billboard.
* @memberof Billboard.prototype
* @type {SplitDirection}
* @default {@link SplitDirection.NONE}
*/
splitDirection: {
get: function () {
return this._splitDirection;
},
set: function (value) {
if (this._splitDirection !== value) {
this._splitDirection = value;
makeDirty(this, SPLIT_DIRECTION_INDEX);
}
},
},
});

Billboard.prototype.getPickId = function (context) {
Expand Down Expand Up @@ -1565,7 +1591,8 @@ Billboard.prototype.equals = function (other) {
this._distanceDisplayCondition,
other._distanceDisplayCondition
) &&
this._disableDepthTestDistance === other._disableDepthTestDistance)
this._disableDepthTestDistance === other._disableDepthTestDistance &&
this._splitDirection === other._splitDirection)
);
};

Expand Down
49 changes: 49 additions & 0 deletions packages/engine/Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const DISTANCE_DISPLAY_CONDITION_INDEX = Billboard.DISTANCE_DISPLAY_CONDITION;
const DISABLE_DEPTH_DISTANCE = Billboard.DISABLE_DEPTH_DISTANCE;
const TEXTURE_COORDINATE_BOUNDS = Billboard.TEXTURE_COORDINATE_BOUNDS;
const SDF_INDEX = Billboard.SDF_INDEX;
const SPLIT_DIRECTION_INDEX = Billboard.SPLIT_DIRECTION_INDEX;
const NUMBER_OF_PROPERTIES = Billboard.NUMBER_OF_PROPERTIES;

let attributeLocations;
Expand All @@ -71,6 +72,7 @@ const attributeLocationsBatched = {
textureCoordinateBoundsOrLabelTranslate: 9,
a_batchId: 10,
sdf: 11,
splitDirection: 12,
};

const attributeLocationsInstanced = {
Expand All @@ -87,6 +89,7 @@ const attributeLocationsInstanced = {
textureCoordinateBoundsOrLabelTranslate: 10,
a_batchId: 11,
sdf: 12,
splitDirection: 13,
};

/**
Expand Down Expand Up @@ -311,6 +314,7 @@ function BillboardCollection(options) {
BufferUsage.STATIC_DRAW, // PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX
BufferUsage.STATIC_DRAW, // DISTANCE_DISPLAY_CONDITION_INDEX
BufferUsage.STATIC_DRAW, // TEXTURE_COORDINATE_BOUNDS
BufferUsage.STATIC_DRAW, // SPLIT_DIRECTION_INDEX
];

this._highlightColor = Color.clone(Color.WHITE); // Only used by Vector3DTilePoints
Expand Down Expand Up @@ -777,6 +781,12 @@ function createVAF(
componentDatatype: ComponentDatatype.FLOAT,
usage: buffersUsage[TEXTURE_COORDINATE_BOUNDS],
},
{
index: attributeLocations.splitDirection,
componentsPerAttribute: 1,
componentDatatype: ComponentDatatype.FLOAT,
usage: buffersUsage[SPLIT_DIRECTION_INDEX],
},
];

// Instancing requires one non-instanced attribute.
Expand Down Expand Up @@ -1586,6 +1596,34 @@ function writeSDF(
}
}

function writeSplitDirection(
billboardCollection,
frameState,
textureAtlasCoordinates,
vafWriters,
billboard
) {
const writer = vafWriters[attributeLocations.splitDirection];
let direction = 0.0;

const split = billboard.splitDirection;
if (defined(split)) {
direction = split;
}

let i;
if (billboardCollection._instanced) {
i = billboard._index;
writer(i, direction);
} else {
i = billboard._index * 4;
writer(i + 0, direction);
writer(i + 1, direction);
writer(i + 2, direction);
writer(i + 3, direction);
}
}

function writeBillboard(
billboardCollection,
frameState,
Expand Down Expand Up @@ -1670,6 +1708,13 @@ function writeBillboard(
vafWriters,
billboard
);
writeSplitDirection(
billboardCollection,
frameState,
textureAtlasCoordinates,
vafWriters,
billboard
);
}

function recomputeActualPositions(
Expand Down Expand Up @@ -1981,6 +2026,10 @@ BillboardCollection.prototype.update = function (frameState) {
writers.push(writeSDF);
}

if (properties[SPLIT_DIRECTION_INDEX]) {
writers.push(writeSplitDirection);
}

const numWriters = writers.length;
vafWriters = this._vaf.writers;

Expand Down
4 changes: 4 additions & 0 deletions packages/engine/Source/Shaders/BillboardCollectionFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ uniform vec4 u_highlightColor;
in vec2 v_textureCoordinates;
in vec4 v_pickColor;
in vec4 v_color;
in float v_splitDirection;

#ifdef SDF
in vec4 v_outlineColor;
Expand Down Expand Up @@ -86,6 +87,9 @@ vec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smo

void main()
{
if (v_splitDirection < 0.0 && gl_FragCoord.x > czm_splitPosition) discard;
if (v_splitDirection > 0.0 && gl_FragCoord.x < czm_splitPosition) discard;

vec4 color = texture(u_atlas, v_textureCoordinates);

#ifdef SDF
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/Source/Shaders/BillboardCollectionVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ in vec4 scaleByDistance; // near, nearScale, far, far
in vec4 pixelOffsetScaleByDistance; // near, nearScale, far, farScale
in vec4 compressedAttribute3; // distance display condition near, far, disableDepthTestDistance, dimensions
in vec2 sdf; // sdf outline color (rgb) and width (w)
in float splitDirection; // splitDirection
#if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)
in vec4 textureCoordinateBoundsOrLabelTranslate; // the min and max x and y values for the texture coordinates
#endif
Expand All @@ -28,6 +29,7 @@ out mat2 v_rotationMatrix;

out vec4 v_pickColor;
out vec4 v_color;
out float v_splitDirection;
#ifdef SDF
out vec4 v_outlineColor;
out float v_outlineWidth;
Expand Down Expand Up @@ -430,5 +432,5 @@ if (lengthSq < disableDepthTestDistance) {

v_color = color;
v_color.a *= translucency;

v_splitDirection = splitDirection;
}