Skip to content

Commit e7bc475

Browse files
authored
Merge pull request #4615 from AnalyticalGraphicsInc/shadow-map-fixes
Shadow map fixes
2 parents 4c8a9f1 + 1175890 commit e7bc475

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

Source/Scene/Scene.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2586,7 +2586,7 @@ define([
25862586
};
25872587

25882588
var scratchPackedDepth = new Cartesian4();
2589-
var packedDepthScale = new Cartesian4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0);
2589+
var packedDepthScale = new Cartesian4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0);
25902590

25912591
/**
25922592
* Returns the cartesian position reconstructed from the depth buffer and window position.

Source/Scene/ShadowMap.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,11 @@ define([
184184
this._outOfViewPrevious = false;
185185
this._needsUpdate = true;
186186

187-
// In IE11 polygon offset is not functional.
188-
// TODO : Also disabled for Chrome (ANGLE) temporarily. Re-enable once https://github.com/AnalyticalGraphicsInc/cesium/issues/4560 is resolved.
187+
// In IE11 and Edge polygon offset is not functional.
188+
// TODO : Also disabled for instances of Firefox and Chrome running ANGLE that do not support depth textures.
189+
// Re-enable once https://github.com/AnalyticalGraphicsInc/cesium/issues/4560 is resolved.
189190
var polygonOffsetSupported = true;
190-
if (FeatureDetection.isInternetExplorer() || (FeatureDetection.isChrome() && FeatureDetection.isWindows())) {
191+
if (FeatureDetection.isInternetExplorer() || FeatureDetection.isEdge() || ((FeatureDetection.isChrome() || FeatureDetection.isFirefox()) && FeatureDetection.isWindows() && !context.depthTexture)) {
191192
polygonOffsetSupported = false;
192193
}
193194
this._polygonOffsetSupported = polygonOffsetSupported;
@@ -1471,10 +1472,10 @@ define([
14711472
var isTerrain = command.pass === Pass.GLOBE;
14721473
var isOpaque = command.pass !== Pass.TRANSLUCENT;
14731474
var isPointLight = shadowMap._isPointLight;
1474-
var useDepthTexture = shadowMap._usesDepthTexture;
1475+
var usesDepthTexture= shadowMap._usesDepthTexture;
14751476

14761477
var castVS = ShadowMapShader.createShadowCastVertexShader(vertexShaderSource, isPointLight, isTerrain);
1477-
var castFS = ShadowMapShader.createShadowCastFragmentShader(fragmentShaderSource, isPointLight, useDepthTexture, isOpaque);
1478+
var castFS = ShadowMapShader.createShadowCastFragmentShader(fragmentShaderSource, isPointLight, usesDepthTexture, isOpaque);
14781479

14791480
castShader = ShaderProgram.fromCache({
14801481
context : context,

Source/Scene/ShadowMapShader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ define([
4848
});
4949
};
5050

51-
ShadowMapShader.createShadowCastFragmentShader = function(fs, isPointLight, useDepthTexture, opaque) {
51+
ShadowMapShader.createShadowCastFragmentShader = function(fs, isPointLight, usesDepthTexture, opaque) {
5252
var defines = fs.defines.slice(0);
5353
var sources = fs.sources.slice(0);
5454

@@ -92,7 +92,7 @@ define([
9292
'float distance = length(' + positionVaryingName + '); \n' +
9393
'distance /= shadowMap_lightPositionEC.w; // radius \n' +
9494
'gl_FragColor = czm_packDepth(distance); \n';
95-
} else if (useDepthTexture) {
95+
} else if (usesDepthTexture) {
9696
fsSource += 'gl_FragColor = vec4(1.0); \n';
9797
} else {
9898
fsSource += 'gl_FragColor = czm_packDepth(gl_FragCoord.z); \n';

Source/Shaders/Builtin/Functions/packDepth.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ vec4 czm_packDepth(float depth)
1111
{
1212
// See Aras Pranckevičius' post Encoding Floats to RGBA
1313
// http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
14-
vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * depth;
14+
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;
1515
enc = fract(enc);
1616
enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);
1717
return enc;

Source/Shaders/Builtin/Functions/unpackDepth.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
{
1313
// See Aras Pranckevičius' post Encoding Floats to RGBA
1414
// http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
15-
return dot(packedDepth, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));
15+
return dot(packedDepth, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));
1616
}

0 commit comments

Comments
 (0)