From f139fceed238760b331919ed988de6bb5bb64bee Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sun, 6 Nov 2016 15:51:18 -0500 Subject: [PATCH 1/2] Shadow map fixes --- Source/Scene/Scene.js | 2 +- Source/Scene/ShadowMap.js | 6 +++--- Source/Scene/ShadowMapShader.js | 4 ++-- Source/Shaders/Builtin/Functions/packDepth.glsl | 2 +- Source/Shaders/Builtin/Functions/unpackDepth.glsl | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 68247624c332..439e70b1baef 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -2586,7 +2586,7 @@ define([ }; var scratchPackedDepth = new Cartesian4(); - var packedDepthScale = new Cartesian4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0); + var packedDepthScale = new Cartesian4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0); /** * Returns the cartesian position reconstructed from the depth buffer and window position. diff --git a/Source/Scene/ShadowMap.js b/Source/Scene/ShadowMap.js index bf51dcd9d6af..b66b92e5976b 100644 --- a/Source/Scene/ShadowMap.js +++ b/Source/Scene/ShadowMap.js @@ -187,7 +187,7 @@ define([ // In IE11 polygon offset is not functional. // TODO : Also disabled for Chrome (ANGLE) temporarily. Re-enable once https://github.com/AnalyticalGraphicsInc/cesium/issues/4560 is resolved. var polygonOffsetSupported = true; - if (FeatureDetection.isInternetExplorer() || (FeatureDetection.isChrome() && FeatureDetection.isWindows())) { + if (FeatureDetection.isInternetExplorer() || FeatureDetection.isEdge() || ((FeatureDetection.isChrome() || FeatureDetection.isFirefox()) && FeatureDetection.isWindows() && !context.depthTexture)) { polygonOffsetSupported = false; } this._polygonOffsetSupported = polygonOffsetSupported; @@ -1471,10 +1471,10 @@ define([ var isTerrain = command.pass === Pass.GLOBE; var isOpaque = command.pass !== Pass.TRANSLUCENT; var isPointLight = shadowMap._isPointLight; - var useDepthTexture = shadowMap._usesDepthTexture; + var usesDepthTexture= shadowMap._usesDepthTexture; var castVS = ShadowMapShader.createShadowCastVertexShader(vertexShaderSource, isPointLight, isTerrain); - var castFS = ShadowMapShader.createShadowCastFragmentShader(fragmentShaderSource, isPointLight, useDepthTexture, isOpaque); + var castFS = ShadowMapShader.createShadowCastFragmentShader(fragmentShaderSource, isPointLight, usesDepthTexture, isOpaque); castShader = ShaderProgram.fromCache({ context : context, diff --git a/Source/Scene/ShadowMapShader.js b/Source/Scene/ShadowMapShader.js index dcb70bd245b3..5214d86a8f3e 100644 --- a/Source/Scene/ShadowMapShader.js +++ b/Source/Scene/ShadowMapShader.js @@ -48,7 +48,7 @@ define([ }); }; - ShadowMapShader.createShadowCastFragmentShader = function(fs, isPointLight, useDepthTexture, opaque) { + ShadowMapShader.createShadowCastFragmentShader = function(fs, isPointLight, usesDepthTexture, opaque) { var defines = fs.defines.slice(0); var sources = fs.sources.slice(0); @@ -92,7 +92,7 @@ define([ 'float distance = length(' + positionVaryingName + '); \n' + 'distance /= shadowMap_lightPositionEC.w; // radius \n' + 'gl_FragColor = czm_packDepth(distance); \n'; - } else if (useDepthTexture) { + } else if (usesDepthTexture) { fsSource += 'gl_FragColor = vec4(1.0); \n'; } else { fsSource += 'gl_FragColor = czm_packDepth(gl_FragCoord.z); \n'; diff --git a/Source/Shaders/Builtin/Functions/packDepth.glsl b/Source/Shaders/Builtin/Functions/packDepth.glsl index 102b8182f8f0..b7c55255abf9 100644 --- a/Source/Shaders/Builtin/Functions/packDepth.glsl +++ b/Source/Shaders/Builtin/Functions/packDepth.glsl @@ -11,7 +11,7 @@ vec4 czm_packDepth(float depth) { // See Aras Pranckevičius' post Encoding Floats to RGBA // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/ - vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * depth; + vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth; enc = fract(enc); enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0); return enc; diff --git a/Source/Shaders/Builtin/Functions/unpackDepth.glsl b/Source/Shaders/Builtin/Functions/unpackDepth.glsl index ef65efc258bf..d122e70b9179 100644 --- a/Source/Shaders/Builtin/Functions/unpackDepth.glsl +++ b/Source/Shaders/Builtin/Functions/unpackDepth.glsl @@ -12,5 +12,5 @@ { // See Aras Pranckevičius' post Encoding Floats to RGBA // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/ - return dot(packedDepth, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0)); + return dot(packedDepth, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)); } From 1175890ee9a4b5e3c68ec48970987a9fadf87cb4 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 7 Nov 2016 10:36:22 -0500 Subject: [PATCH 2/2] Update TODO --- Source/Scene/ShadowMap.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Scene/ShadowMap.js b/Source/Scene/ShadowMap.js index b66b92e5976b..85fa22cbcf09 100644 --- a/Source/Scene/ShadowMap.js +++ b/Source/Scene/ShadowMap.js @@ -184,8 +184,9 @@ define([ this._outOfViewPrevious = false; this._needsUpdate = true; - // In IE11 polygon offset is not functional. - // TODO : Also disabled for Chrome (ANGLE) temporarily. Re-enable once https://github.com/AnalyticalGraphicsInc/cesium/issues/4560 is resolved. + // In IE11 and Edge polygon offset is not functional. + // TODO : Also disabled for instances of Firefox and Chrome running ANGLE that do not support depth textures. + // Re-enable once https://github.com/AnalyticalGraphicsInc/cesium/issues/4560 is resolved. var polygonOffsetSupported = true; if (FeatureDetection.isInternetExplorer() || FeatureDetection.isEdge() || ((FeatureDetection.isChrome() || FeatureDetection.isFirefox()) && FeatureDetection.isWindows() && !context.depthTexture)) { polygonOffsetSupported = false;