-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 Start #3551
Shadow Map Start #3551
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> | ||
<meta name="description" content="Shadow maps."> | ||
<meta name="cesium-sandcastle-labels" content="Tutorials,Showcases"> | ||
<title>Cesium Demo</title> | ||
<script type="text/javascript" src="../Sandcastle-header.js"></script> | ||
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script> | ||
<script type="text/javascript"> | ||
require.config({ | ||
baseUrl : '../../../Source', | ||
waitSeconds : 60 | ||
}); | ||
</script> | ||
</head> | ||
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> | ||
<style> | ||
@import url(../templates/bucket.css); | ||
</style> | ||
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"><h1>Loading...</h1></div> | ||
<div id="toolbar"></div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
"use strict"; | ||
//Sandcastle_Begin | ||
|
||
var globeVisible = false; | ||
|
||
var viewer = new Cesium.Viewer('cesiumContainer', { | ||
infoBox : false, | ||
selectionIndicator : false, | ||
globe : globeVisible ? undefined : false, | ||
skyAtmosphere : globeVisible ? undefined : false | ||
}); | ||
|
||
var scene = viewer.scene; | ||
var camera = scene.camera; | ||
var shadowMap = scene.sunShadowMap; | ||
shadowMap.debugShow = true; | ||
|
||
var centerLongitude = -1.31968; | ||
var centerLatitude = 0.698874; | ||
|
||
camera.lookAt(Cesium.Cartesian3.fromRadians(centerLongitude, centerLatitude, 50), new Cesium.Cartesian3(0.0, 0.0, 30.0)); | ||
|
||
function createModel(url) { | ||
var origin = Cesium.Cartesian3.fromRadians(centerLongitude, centerLatitude, 50); | ||
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, 0.0, 0.0, 0.0); | ||
|
||
var model = scene.primitives.add(Cesium.Model.fromGltf({ | ||
url : url, | ||
modelMatrix : modelMatrix | ||
})); | ||
|
||
model.readyPromise.then(function(model) { | ||
// Play and loop all animations at half-speed | ||
model.activeAnimations.addAll({ | ||
speedup : 0.5, | ||
loop : Cesium.ModelAnimationLoop.REPEAT | ||
}); | ||
}).otherwise(function(error){ | ||
window.alert(error); | ||
}); | ||
} | ||
|
||
//createModel('../../SampleData/models/CesiumAir/Cesium_Air.glb'); | ||
createModel('../../SampleData/models/shadow_tester.gltf'); | ||
|
||
function setCascades(cascades) { | ||
return function() { | ||
window.alert('Set cascades: ' + i); | ||
}; | ||
} | ||
|
||
var cascades = 4; | ||
var cascadeOptions = []; | ||
for (var i = 1; i <= cascades; ++i) { | ||
cascadeOptions.push({ | ||
text : 'Cascades: ' + i, | ||
onSelect : setCascades(i) | ||
}); | ||
} | ||
|
||
Sandcastle.addToolbarMenu(cascadeOptions); | ||
|
||
Sandcastle.addToolbarButton('Debug on/off', function() { | ||
shadowMap.debugShow = !shadowMap.debugShow; | ||
}); | ||
|
||
Sandcastle.addToolbarButton('Freeze on/off', function() { | ||
shadowMap.debugFreezeFrame = !shadowMap.debugFreezeFrame; | ||
}); | ||
|
||
|
||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== "undefined") { | ||
startup(Cesium); | ||
} else if (typeof require === "function") { | ||
require(["Cesium"], startup); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,8 @@ define([ | |
this._resolutionScale = 1.0; | ||
|
||
this._fogDensity = undefined; | ||
|
||
this.shadowMap = undefined; | ||
} | ||
|
||
defineProperties(UniformState.prototype, { | ||
|
@@ -845,6 +847,23 @@ define([ | |
projection.project(sunCartographic, uniformState._sunPositionColumbusView); | ||
} | ||
|
||
/** | ||
* Synchronizes the frustum's state with the camera state. This is called | ||
* by the {@link Scene} when rendering to ensure that automatic GLSL uniforms | ||
* are set to the right value. | ||
* | ||
* @param {Object} camera The camera to synchronize with. | ||
*/ | ||
UniformState.prototype.updateCamera = function(camera) { | ||
setView(this, camera.viewMatrix); | ||
setInverseView(this, camera.inverseViewMatrix); | ||
setCamera(this, camera); | ||
|
||
this._entireFrustum.x = camera.frustum.near; | ||
this._entireFrustum.y = camera.frustum.far; | ||
this.updateFrustum(camera.frustum); | ||
}; | ||
|
||
/** | ||
* Synchronizes the frustum's state with the uniform state. This is called | ||
* by the {@link Scene} when rendering to ensure that automatic GLSL uniforms | ||
|
@@ -876,19 +895,17 @@ define([ | |
* are set to the right value. | ||
* | ||
* @param {FrameState} frameState The frameState to synchronize with. | ||
* @param {ShadowMap} [shadowMap] The shadow map. | ||
*/ | ||
UniformState.prototype.update = function(frameState) { | ||
UniformState.prototype.update = function(frameState, shadowMap) { | ||
this._mode = frameState.mode; | ||
this._mapProjection = frameState.mapProjection; | ||
|
||
var canvas = frameState.context._canvas; | ||
this._resolutionScale = canvas.width / canvas.clientWidth; | ||
|
||
var camera = frameState.camera; | ||
|
||
setView(this, camera.viewMatrix); | ||
setInverseView(this, camera.inverseViewMatrix); | ||
setCamera(this, camera); | ||
this.updateCamera(camera); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't looked at the rest of the code yet, but does it make sense to not call this here and require the user to call it, e.g.,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a TODO to your roadmap since those tests should probably call |
||
|
||
if (frameState.mode === SceneMode.SCENE2D) { | ||
this._frustum2DWidth = camera.frustum.right - camera.frustum.left; | ||
|
@@ -902,12 +919,10 @@ define([ | |
|
||
setSunAndMoonDirections(this, frameState); | ||
|
||
this._entireFrustum.x = camera.frustum.near; | ||
this._entireFrustum.y = camera.frustum.far; | ||
this.updateFrustum(camera.frustum); | ||
|
||
this._fogDensity = frameState.fog.density; | ||
|
||
this.shadowMap = shadowMap; | ||
|
||
this._frameState = frameState; | ||
this._temeToPseudoFixed = Transforms.computeTemeToPseudoFixedMatrix(frameState.time, this._temeToPseudoFixed); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bagnell so far is this inline with your vision of having separate viewports with separate cameras for things like picture-in-picture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, this is fine with me.