Skip to content

Commit

Permalink
Merge pull request #4615 from AnalyticalGraphicsInc/shadow-map-fixes
Browse files Browse the repository at this point in the history
Shadow map fixes
  • Loading branch information
mramato committed Nov 7, 2016
2 parents 4c8a9f1 + 1175890 commit e7bc475
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions Source/Scene/ShadowMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ 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.isChrome() && FeatureDetection.isWindows())) {
if (FeatureDetection.isInternetExplorer() || FeatureDetection.isEdge() || ((FeatureDetection.isChrome() || FeatureDetection.isFirefox()) && FeatureDetection.isWindows() && !context.depthTexture)) {
polygonOffsetSupported = false;
}
this._polygonOffsetSupported = polygonOffsetSupported;
Expand Down Expand Up @@ -1471,10 +1472,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,
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/ShadowMapShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion Source/Shaders/Builtin/Functions/packDepth.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Shaders/Builtin/Functions/unpackDepth.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit e7bc475

Please sign in to comment.