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

Shadow map fixes #4615

Merged
merged 3 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 26 additions & 5 deletions Source/Core/FeatureDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ define([
function isChrome() {
if (!defined(isChromeResult)) {
isChromeResult = false;

var fields = (/ Chrome\/([\.0-9]+)/).exec(theNavigator.userAgent);
if (fields !== null) {
isChromeResult = true;
chromeVersionResult = extractVersion(fields[1]);
if (/Google Inc/.test(theNavigator.vendor)) {
var fields = (/ Chrome\/([\.0-9]+)/).exec(theNavigator.userAgent);
if (fields !== null) {
isChromeResult = true;
chromeVersionResult = extractVersion(fields[1]);
}
}
}

Expand Down Expand Up @@ -116,6 +117,24 @@ define([
return isInternetExplorer() && internetExplorerVersionResult;
}

var isEdgeResult;
var edgeVersionResult;
function isEdge() {
if (!defined(isEdgeResult)) {
isEdgeResult = false;
var fields = (/ Edge\/([\.0-9]+)/).exec(theNavigator.userAgent);
if (fields !== null) {
isEdgeResult = true;
edgeVersionResult = extractVersion(fields[1]);
}
}
return isEdgeResult;
}

function edgeVersion() {
return isEdge() && edgeVersionResult;
}

var isFirefoxResult;
var firefoxVersionResult;
function isFirefox() {
Expand Down Expand Up @@ -193,6 +212,8 @@ define([
webkitVersion : webkitVersion,
isInternetExplorer : isInternetExplorer,
internetExplorerVersion : internetExplorerVersion,
isEdge : isEdge,
edgeVersion : edgeVersion,
isFirefox : isFirefox,
firefoxVersion : firefoxVersion,
isWindows : isWindows,
Expand Down
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the TODO comment to reflect the full scope of this check, since it's now out of date.

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));
}
12 changes: 12 additions & 0 deletions Specs/Core/FeatureDetectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ defineSuite([
}
});

it('detects Edge', function() {
var isEdge = FeatureDetection.isEdge();
expect(typeof isEdge).toEqual('boolean');

if (isEdge) {
var edgeVersion = FeatureDetection.edgeVersion();
checkVersionArray(edgeVersion);

console.log('detected Edge ' + edgeVersion.join('.'));
}
});

it('detects Firefox', function() {
var isFirefox = FeatureDetection.isFirefox();
expect(typeof isFirefox).toEqual('boolean');
Expand Down