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

Enable improved depth testing for all billboards #6802

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
64 changes: 23 additions & 41 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ define([
this._shaderDisableDepthDistance = false;
this._compiledShaderDisableDepthDistance = false;

this._shaderClampToGround = false;
this._compiledShaderClampToGround = false;

this._propertiesChanged = new Uint32Array(NUMBER_OF_PROPERTIES);

this._maxSize = 0.0;
Expand Down Expand Up @@ -1194,8 +1191,8 @@ define([
}

var disableDepthTestDistance = billboard.disableDepthTestDistance;
if (billboard.heightReference === HeightReference.CLAMP_TO_GROUND && disableDepthTestDistance === 0.0 && billboardCollection._scene.context.depthTexture) {
disableDepthTestDistance = 2000.0;
if (disableDepthTestDistance === 0.0 && context.depthTexture) {
disableDepthTestDistance = 4000.0;
}

disableDepthTestDistance *= disableDepthTestDistance;
Expand Down Expand Up @@ -1252,9 +1249,6 @@ define([
}

function writeTextureCoordinateBoundsOrLabelTranslate(billboardCollection, context, textureAtlasCoordinates, vafWriters, billboard) {
if (billboard.heightReference === HeightReference.CLAMP_TO_GROUND) {
billboardCollection._shaderClampToGround = billboardCollection._scene.context.depthTexture;
}
var i;
var writer = vafWriters[attributeLocations.textureCoordinateBoundsOrLabelTranslate];

Expand Down Expand Up @@ -1665,8 +1659,7 @@ define([
(this._shaderTranslucencyByDistance !== this._compiledShaderTranslucencyByDistance) ||
(this._shaderPixelOffsetScaleByDistance !== this._compiledShaderPixelOffsetScaleByDistance) ||
(this._shaderDistanceDisplayCondition !== this._compiledShaderDistanceDisplayCondition) ||
(this._shaderDisableDepthDistance !== this._compiledShaderDisableDepthDistance) ||
(this._shaderClampToGround !== this._compiledShaderClampToGround)) {
(this._shaderDisableDepthDistance !== this._compiledShaderDisableDepthDistance)) {

vsSource = BillboardCollectionVS;
fsSource = BillboardCollectionFS;
Expand Down Expand Up @@ -1706,12 +1699,10 @@ define([
if (this._shaderDisableDepthDistance) {
vs.defines.push('DISABLE_DEPTH_DISTANCE');
}
if (this._shaderClampToGround) {
if (supportVSTextureReads) {
vs.defines.push('VERTEX_DEPTH_CHECK');
} else {
vs.defines.push('FRAGMENT_DEPTH_CHECK');
}
if (supportVSTextureReads) {
vs.defines.push('VERTEX_DEPTH_CHECK');
} else {
vs.defines.push('FRAGMENT_DEPTH_CHECK');
}

var vectorFragDefine = defined(this._batchTable) ? 'VECTOR_TILE' : '';
Expand All @@ -1721,12 +1712,10 @@ define([
defines : ['OPAQUE', vectorFragDefine],
sources : [fsSource]
});
if (this._shaderClampToGround) {
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
this._sp = ShaderProgram.replaceCache({
context : context,
Expand All @@ -1740,12 +1729,10 @@ define([
defines : ['TRANSLUCENT', vectorFragDefine],
sources : [fsSource]
});
if (this._shaderClampToGround) {
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
this._spTranslucent = ShaderProgram.replaceCache({
context : context,
Expand All @@ -1761,12 +1748,10 @@ define([
defines : [vectorFragDefine],
sources : [fsSource]
});
if (this._shaderClampToGround) {
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
this._sp = ShaderProgram.replaceCache({
context : context,
Expand All @@ -1782,12 +1767,10 @@ define([
defines : [vectorFragDefine],
sources : [fsSource]
});
if (this._shaderClampToGround) {
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
if (supportVSTextureReads) {
fs.defines.push('VERTEX_DEPTH_CHECK');
} else {
fs.defines.push('FRAGMENT_DEPTH_CHECK');
}
this._spTranslucent = ShaderProgram.replaceCache({
context : context,
Expand All @@ -1805,7 +1788,6 @@ define([
this._compiledShaderPixelOffsetScaleByDistance = this._shaderPixelOffsetScaleByDistance;
this._compiledShaderDistanceDisplayCondition = this._shaderDistanceDisplayCondition;
this._compiledShaderDisableDepthDistance = this._shaderDisableDepthDistance;
this._compiledShaderClampToGround = this._shaderClampToGround;
}

var commandList = frameState.commandList;
Expand Down
8 changes: 5 additions & 3 deletions Source/Shaders/BillboardCollectionVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,18 @@ if (lengthSq < disableDepthTestDistance) {
vec4 pEC1 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
float globeDepth1 = getGlobeDepth(pEC1);

if (globeDepth1 != 0.0 && pEC1.z < globeDepth1)
float depthsilon = 10.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you come up with 10.0? Have you tested other areas of terrain?

Great variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tested on both flat areas and mountainy areas. 10 was the lowest value that mostly got rid of the flickering. Other values I tested like 5 and 7 still had a lot of flickering when the terrain had more drastic slopes


if (globeDepth1 != 0.0 && pEC1.z + depthsilon < globeDepth1)
{
vec4 pEC2 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0, 1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
float globeDepth2 = getGlobeDepth(pEC2);

if (globeDepth2 != 0.0 && pEC2.z < globeDepth2)
if (globeDepth2 != 0.0 && pEC2.z + depthsilon < globeDepth2)
{
vec4 pEC3 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
float globeDepth3 = getGlobeDepth(pEC3);
if (globeDepth3 != 0.0 && pEC3.z < globeDepth3)
if (globeDepth3 != 0.0 && pEC3.z + depthsilon < globeDepth3)
{
positionEC.xyz = vec3(0.0);
}
Expand Down