Skip to content

Commit

Permalink
Updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 21, 2020
1 parent d6da21a commit f57b6ad
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 50 deletions.
Binary file modified Apps/Sandcastle/gallery/Cartographic Limit Rectangle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 20 additions & 15 deletions Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,28 @@ var AutomaticUniforms = {
},
}),

/**
* An automatic GLSL uniform containing the height in meters of the
* eye (camera) above or below the ellipsoid.
*
* @alias czm_eyeHeight
* @namespace
* @glslUniform
*
* @see UniformState#eyeHeight
*/
czm_eyeHeight: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.eyeHeight;
},
}),

/**
* An automatic GLSL uniform containing height (<code>x</code>) and height squared (<code>y</code>)
* of the eye (camera) in the 2D scene in meters.
* in meters of the eye (camera) above the 2D world plane. This uniform is only valid
* when the {@link SceneMode} is <code>SCENE2D</code>.
*
* @alias czm_eyeHeight2D
* @namespace
Expand Down Expand Up @@ -1896,19 +1915,5 @@ var AutomaticUniforms = {
return uniformState.ellipsoid.oneOverRadii;
},
}),

/**
* An automatic GLSL uniform that stores the camera's height above or below the ellipsoid.
*
* @alias czm_cameraHeight
* @glslUniform
*/
czm_cameraHeight: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.cameraHeight;
},
}),
};
export default AutomaticUniforms;
35 changes: 17 additions & 18 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ function UniformState() {
this._cameraDirection = new Cartesian3();
this._cameraRight = new Cartesian3();
this._cameraUp = new Cartesian3();
this._cameraHeight = 0.0;
this._frustum2DWidth = 0.0;
this._eyeHeight = 0.0;
this._eyeHeight2D = new Cartesian2();
this._pixelRatio = 1.0;
this._orthographicIn3D = false;
Expand Down Expand Up @@ -673,9 +673,20 @@ Object.defineProperties(UniformState.prototype, {
},

/**
* The the height (<code>x</code>) and the height squared (<code>y</code>)
* in meters of the camera above the 2D world plane. This uniform is only valid
* when the {@link SceneMode} equal to <code>SCENE2D</code>.
* The height in meters of the eye (camera) above or below the ellipsoid.
* @memberof UniformState.prototype
* @type {Number}
*/
eyeHeight: {
get: function () {
return this._eyeHeight;
},
},

/**
* The height (<code>x</code>) and the height squared (<code>y</code>)
* in meters of the eye (camera) above the 2D world plane. This uniform is only valid
* when the {@link SceneMode} is <code>SCENE2D</code>.
* @memberof UniformState.prototype
* @type {Cartesian2}
*/
Expand Down Expand Up @@ -1011,18 +1022,6 @@ Object.defineProperties(UniformState.prototype, {
return defaultValue(this._ellipsoid, Ellipsoid.WGS84);
},
},

/**
* The camera's height above or below the ellipsoid.
*
* @memberof UniformState.prototype
* @type {Number}
*/
cameraHeight: {
get: function () {
return this._cameraHeight;
},
},
});

function setView(uniformState, matrix) {
Expand Down Expand Up @@ -1076,9 +1075,9 @@ function setCamera(uniformState, camera) {

var positionCartographic = camera.positionCartographic;
if (!defined(positionCartographic)) {
uniformState._cameraHeight = -uniformState._ellipsoid.maximumRadius;
uniformState._eyeHeight = -uniformState._ellipsoid.maximumRadius;
} else {
uniformState._cameraHeight = positionCartographic.height;
uniformState._eyeHeight = positionCartographic.height;
}

uniformState._encodedCameraPositionMCDirty = true;
Expand Down
1 change: 0 additions & 1 deletion Source/Scene/processModelMaterialsCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ function generateTechnique(
if (hasNormals) {
fragmentShader += " vec3 normal = normalize(v_normal);\n";
if (khrMaterialsCommon.doubleSided) {
// !gl_FrontFacing doesn't work as expected on Mac/Intel so use the more verbose form instead. See https://github.com/CesiumGS/cesium/pull/8494.
fragmentShader += " if (czm_backFacing())\n";
fragmentShader += " {\n";
fragmentShader += " normal = -normal;\n";
Expand Down
1 change: 0 additions & 1 deletion Source/Scene/processPbrMaterials.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ function generateTechnique(
fragmentShader += " vec3 n = ng;\n";
}
if (material.doubleSided) {
// !gl_FrontFacing doesn't work as expected on Mac/Intel so use the more verbose form instead. See https://github.com/CesiumGS/cesium/pull/8494.
fragmentShader += " if (czm_backFacing())\n";
fragmentShader += " {\n";
fragmentShader += " n = -n;\n";
Expand Down
2 changes: 1 addition & 1 deletion Source/Shaders/GlobeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void main()
#ifdef UNDERGROUND_COLOR
if (czm_backFacing())
{
float distanceFromEllipsoid = max(czm_cameraHeight, 0.0);
float distanceFromEllipsoid = max(czm_eyeHeight, 0.0);
float distance = max(v_distance - distanceFromEllipsoid, 0.0);
float blendAmount = interpolateByDistance(u_undergroundColorAlphaByDistance, distance);
vec4 undergroundColor = vec4(u_undergroundColor.rgb, u_undergroundColor.a * blendAmount);
Expand Down
28 changes: 14 additions & 14 deletions Specs/Renderer/AutomaticUniformSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,20 @@ describe(
}).contextToRender();
});

it("has czm_eyeHeight", function () {
var frameState = createFrameState(context, createMockCamera());
context.uniformState.update(frameState);

var fs =
"void main() { " +
" gl_FragColor = vec4(czm_eyeHeight == 10.0); " +
"}";
expect({
context: context,
fragmentShader: fs,
}).contextToRender();
});

it("has czm_eyeHeight2D == 0,0 in Scene3D", function () {
var fs =
"void main() { " +
Expand Down Expand Up @@ -2171,20 +2185,6 @@ describe(
fragmentShader: fs,
}).contextToRender();
});

it("has czm_cameraHeight", function () {
var frameState = createFrameState(context, createMockCamera());
context.uniformState.update(frameState);

var fs =
"void main() { " +
" gl_FragColor = vec4(czm_cameraHeight == 10.0); " +
"}";
expect({
context: context,
fragmentShader: fs,
}).contextToRender();
});
},
"WebGL"
);

0 comments on commit f57b6ad

Please sign in to comment.