Skip to content

Commit 22ecbe6

Browse files
committed
Add option to disable log depth. Fix frustum equality and frustum changed flag.
1 parent 0d90d98 commit 22ecbe6

8 files changed

+61
-25
lines changed

Source/Core/OrthographicFrustum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ define([
259259
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
260260
*/
261261
OrthographicFrustum.prototype.equals = function(other) {
262-
if (!defined(other)) {
262+
if (!defined(other) || !(other instanceof OrthographicFrustum)) {
263263
return false;
264264
}
265265

Source/Core/OrthographicOffCenterFrustum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ define([
361361
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
362362
*/
363363
OrthographicOffCenterFrustum.prototype.equals = function(other) {
364-
return (defined(other) &&
364+
return (defined(other) && other instanceof OrthographicOffCenterFrustum &&
365365
this.right === other.right &&
366366
this.left === other.left &&
367367
this.top === other.top &&

Source/Core/PerspectiveFrustum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ define([
354354
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
355355
*/
356356
PerspectiveFrustum.prototype.equals = function(other) {
357-
if (!defined(other)) {
357+
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
358358
return false;
359359
}
360360

Source/Core/PerspectiveOffCenterFrustum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ define([
412412
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
413413
*/
414414
PerspectiveOffCenterFrustum.prototype.equals = function(other) {
415-
return (defined(other) &&
415+
return (defined(other) && other instanceof PerspectiveOffCenterFrustum &&
416416
this.right === other.right &&
417417
this.left === other.left &&
418418
this.top === other.top &&

Source/Scene/Scene.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ define([
266266
}
267267

268268
this._logDepthBuffer = context.fragmentDepth;
269+
this._logDepthBufferChanged = true;
269270

270271
this._id = createGuid();
271272
this._jobScheduler = new JobScheduler();
@@ -1379,6 +1380,22 @@ define([
13791380
//>>includeEnd('debug');
13801381
this._minimumDisableDepthTestDistance = value;
13811382
}
1383+
},
1384+
1385+
/**
1386+
* Whether or not to use a logarithmic depth buffer. Enabling this option will allow for less frustums in the multi-frustum,
1387+
* increasing performance. This property relies on {@link Context#fragmentDepth} being supported.
1388+
*/
1389+
logDepthBuffer : {
1390+
get : function() {
1391+
return this._logDepthBuffer;
1392+
},
1393+
set : function(value) {
1394+
if (this._context.fragmentDepth && this._logDepthBuffer !== value) {
1395+
this._logDepthBuffer = value;
1396+
this._logDepthBufferChanged = true;
1397+
}
1398+
}
13821399
}
13831400
});
13841401

@@ -1432,7 +1449,7 @@ define([
14321449
}
14331450

14341451
var derivedCommands = command.derivedCommands;
1435-
if ((scene._frustumChanged || command.dirty) && defined(derivedCommands)) {
1452+
if ((scene._logDepthBufferChanged || scene._frustumChanged || command.dirty) && defined(derivedCommands)) {
14361453
command.dirty = false;
14371454

14381455
var frustum = scene.camera.frustum;
@@ -3099,14 +3116,14 @@ define([
30993116
tryAndCatchError(this, time, update);
31003117
this._postUpdate.raiseEvent(this, time);
31013118

3102-
this._frustumChanged = this._camera.frustum !== this._cameraClone.frustum;
3119+
this._frustumChanged = !this._camera.frustum.equals(this._cameraClone.frustum);
31033120
if (this._frustumChanged && this._logDepthBuffer && !(this._camera.frustum instanceof OrthographicFrustum || this._camera.frustum instanceof OrthographicOffCenterFrustum)) {
31043121
this._camera.frustum.near = 1.0;
31053122
this._camera.frustum.far = 10000000000.0;
31063123
}
31073124

31083125
var cameraChanged = checkForCameraUpdates(this);
3109-
var shouldRender = !this.requestRenderMode || this._renderRequested || cameraChanged || this._frustumChanged || (this.mode === SceneMode.MORPHING);
3126+
var shouldRender = !this.requestRenderMode || this._renderRequested || cameraChanged || this._frustumChanged || this._logDepthBufferChanged || (this.mode === SceneMode.MORPHING);
31103127
if (!shouldRender && defined(this.maximumRenderTimeChange) && defined(this._lastRenderTime)) {
31113128
var difference = Math.abs(JulianDate.secondsDifference(this._lastRenderTime, time));
31123129
shouldRender = shouldRender || difference > this.maximumRenderTimeChange;
@@ -3115,6 +3132,7 @@ define([
31153132
if (shouldRender) {
31163133
this._lastRenderTime = JulianDate.clone(time, this._lastRenderTime);
31173134
this._renderRequested = false;
3135+
this._logDepthBufferChanged = false;
31183136

31193137
// Render
31203138
this._preRender.raiseEvent(this, time);

Source/Shaders/EllipsoidFS.glsl

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#ifdef WRITE_DEPTH
2+
#ifdef GL_EXT_frag_depth
3+
#extension GL_EXT_frag_depth : enable
4+
#endif
5+
#endif
6+
17
uniform vec3 u_radii;
28
uniform vec3 u_oneOverEllipsoidRadiiSquared;
39

@@ -90,7 +96,16 @@ void main()
9096
t = (intersection.start != 0.0) ? intersection.start : intersection.stop;
9197
vec3 positionEC = czm_pointAlongRay(ray, t);
9298
vec4 positionCC = czm_projection * vec4(positionEC, 1.0);
99+
#ifdef LOG_DEPTH
93100
czm_writeLogZ(1.0 + positionCC.w);
101+
#else
102+
float z = positionCC.z / positionCC.w;
103+
104+
float n = czm_depthRange.near;
105+
float f = czm_depthRange.far;
106+
107+
gl_FragDepthEXT = (z * (f - n) + f + n) * 0.5;
108+
#endif
94109
#endif
95110
#endif
96111
}

Source/Shaders/PostProcessFilters/PointCloudEyeDomeLighting.glsl

+20-17
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,28 @@ void main()
2525
{
2626
discard;
2727
}
28-
else
29-
{
30-
vec4 color = texture2D(u_pointCloud_colorTexture, v_textureCoordinates);
3128

32-
// sample from neighbors up, down, left, right
33-
float distX = u_distancesAndEdlStrength.x;
34-
float distY = u_distancesAndEdlStrength.y;
29+
vec4 color = texture2D(u_pointCloud_colorTexture, v_textureCoordinates);
3530

36-
vec2 responseAndCount = vec2(0.0);
31+
// sample from neighbors up, down, left, right
32+
float distX = u_distancesAndEdlStrength.x;
33+
float distY = u_distancesAndEdlStrength.y;
3734

38-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, distY));
39-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(distX, 0));
40-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, -distY));
41-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(-distX, 0));
35+
vec2 responseAndCount = vec2(0.0);
4236

43-
float response = responseAndCount.x / responseAndCount.y;
44-
float shade = exp(-response * 300.0 * u_distancesAndEdlStrength.z);
45-
color.rgb *= shade;
46-
gl_FragColor = vec4(color);
47-
gl_FragDepthEXT = czm_eyeToWindowCoordinates(vec4(ecAlphaDepth.xyz, 1.0)).z;
48-
}
37+
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, distY));
38+
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(distX, 0));
39+
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, -distY));
40+
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(-distX, 0));
41+
42+
float response = responseAndCount.x / responseAndCount.y;
43+
float shade = exp(-response * 300.0 * u_distancesAndEdlStrength.z);
44+
color.rgb *= shade;
45+
gl_FragColor = vec4(color);
46+
47+
#ifdef LOG_DEPTH
48+
czm_writeLogZ(1.0 + (czm_projection * vec4(ecAlphaDepth.xyz, 1.0)).w);
49+
#else
50+
gl_FragDepthEXT = czm_eyeToWindowCoordinates(vec4(ecAlphaDepth.xyz, 1.0)).z;
51+
#endif
4952
}

Source/Shaders/Vector3DTilePolylinesVS.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ void main()
2121
gl_Position = czm_viewportOrthographic * positionWC;
2222

2323
#ifdef LOG_DEPTH
24-
czm_vertexLogZ(czm_projection * u_modifiedModelView * currentPosition);
24+
czm_vertexLogZ(czm_projection * p);
2525
#endif
2626
}

0 commit comments

Comments
 (0)