Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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: 10 additions & 6 deletions packages/engine/Source/Shaders/BillboardCollectionFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ uniform vec4 u_highlightColor;
in vec2 v_textureCoordinates;
in vec4 v_pickColor;
in vec4 v_color;
in float v_splitDirection;
in vec2 v_splitDirectionAndEllipsoidDepthEC;

#ifdef SDF
in vec4 v_outlineColor;
Expand Down Expand Up @@ -164,17 +164,21 @@ void doDepthTest() {
float globeDepth = getGlobeDepthAtCoords(fragSt);
if (globeDepth == 0.0) return; // Not on globe

float distanceToEllipsoidCenter = -length(czm_viewerPositionWC); // depth is negative by convention
float testDistance = (eyeDepth > -u_coarseDepthTestDistance) ? globeDepth : distanceToEllipsoidCenter;
if (eyeDepth < testDistance) {
float distanceToEllipsoid = -v_splitDirectionAndEllipsoidDepthEC.y;
bool useGlobeDepth = eyeDepth > -u_coarseDepthTestDistance;
float testDistance = useGlobeDepth ? globeDepth : distanceToEllipsoid;
float testDelta = eyeDepth - testDistance;

float depthsilon = useGlobeDepth ? u_threePointDepthTestDistance : u_coarseDepthTestDistance;
if (testDelta < -depthsilon) {
discard;
}
}

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

vec4 color = texture(u_atlas, v_textureCoordinates);
Expand Down
16 changes: 14 additions & 2 deletions packages/engine/Source/Shaders/BillboardCollectionVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ out vec4 v_compressed; // x: eyeDepth, y: applyT

out vec4 v_pickColor;
out vec4 v_color;
out float v_splitDirection;
out vec2 v_splitDirectionAndEllipsoidDepthEC; // x: splitDirection, y: ellipsoid depth in eye coordinates
#ifdef SDF
out vec4 v_outlineColor;
out float v_outlineWidth;
Expand Down Expand Up @@ -322,6 +322,18 @@ void main()
}
#endif

v_splitDirectionAndEllipsoidDepthEC.y = czm_infinity;
vec3 ellipsoidCenter = czm_view[3].xyz;
vec3 rayDirection = normalize(positionEC.xyz);
czm_ray ray = czm_ray(vec3(0.0), rayDirection);
vec3 ellipsoid_inverseRadii = czm_ellipsoidInverseRadii;
czm_raySegment intersection = czm_rayEllipsoidIntersectionInterval(ray, ellipsoidCenter, ellipsoid_inverseRadii);

if (!czm_isEmpty(intersection))
{
v_splitDirectionAndEllipsoidDepthEC.y = intersection.start;
}

v_compressed.y = enableDepthCheck;

#ifdef VS_THREE_POINT_DEPTH_CHECK
Expand Down Expand Up @@ -441,5 +453,5 @@ if (lengthSq < (u_threePointDepthTestDistance * u_threePointDepthTestDistance) &

v_color = color;
v_color.a *= translucency;
v_splitDirection = splitDirection;
v_splitDirectionAndEllipsoidDepthEC.x = splitDirection;
}
6 changes: 0 additions & 6 deletions packages/sandcastle/gallery/mars/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ try {
scaleByDistance: new Cesium.NearFarScalar(1.5e2, 1.0, 1.5e7, 0.5),
translucencyByDistance: new Cesium.NearFarScalar(2.5e7, 1.0, 4.0e7, 0.0),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance: new Cesium.CallbackProperty(() => {
return Cesium.Cartesian3.magnitude(scene.camera.positionWC);
}, false),
});

entity.point = new Cesium.PointGraphics({
Expand All @@ -213,9 +210,6 @@ try {
outlineWidth: 2,
scaleByDistance: new Cesium.NearFarScalar(1.5e3, 1.0, 4.0e7, 0.1),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance: new Cesium.CallbackProperty(() => {
return Cesium.Cartesian3.magnitude(scene.camera.positionWC);
}, false),
});

entity.name = entity.properties.text.getValue();
Expand Down
6 changes: 0 additions & 6 deletions packages/sandcastle/gallery/moon/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ for (const poi of pointsOfInterest) {
scaleByDistance: new Cesium.NearFarScalar(1.5e2, 1.0, 1.5e7, 0.5),
translucencyByDistance: new Cesium.NearFarScalar(2.5e7, 1.0, 4.0e7, 0.0),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance: new Cesium.CallbackProperty(() => {
return Cesium.Cartesian3.magnitude(scene.camera.positionWC);
}, false),
},
point: {
pixelSize: 10,
Expand All @@ -98,9 +95,6 @@ for (const poi of pointsOfInterest) {
outlineWidth: 2,
scaleByDistance: new Cesium.NearFarScalar(1.5e3, 1.0, 4.0e7, 0.1),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance: new Cesium.CallbackProperty(() => {
return Cesium.Cartesian3.magnitude(scene.camera.positionWC);
}, false),
},
});
}
Expand Down