Skip to content

Commit

Permalink
Don't hardcoded WGS84 is czm_ellipsoidRadii and czm_ellipsoidInterseR…
Browse files Browse the repository at this point in the history
…adii
  • Loading branch information
lilleyse committed Mar 16, 2020
1 parent d48ac3e commit 4081326
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 14 deletions.
28 changes: 28 additions & 0 deletions Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,34 @@ import WebGLConstants from '../Core/WebGLConstants.js';
getValue : function(uniformState) {
return uniformState.gamma;
}
}),

/**
* An automatic GLSL uniform that stores the ellipsoid radii.
*
* @alias czm_ellipsoidRadii
* @glslUniform
*/
czm_ellipsoidRadii : new AutomaticUniform({
size : 1,
datatype : WebGLConstants.FLOAT_VEC3,
getValue : function(uniformState) {
return uniformState.ellipsoid.radii;
}
}),

/**
* An automatic GLSL uniform that stores the ellipsoid inverse radii.
*
* @alias czm_ellipsoidRadii
* @glslUniform
*/
czm_ellipsoidInverseRadii : new AutomaticUniform({
size : 1,
datatype : WebGLConstants.FLOAT_VEC3,
getValue : function(uniformState) {
return uniformState.ellipsoid.oneOverRadii;
}
})
};
export default AutomaticUniforms;
15 changes: 15 additions & 0 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Cartographic from '../Core/Cartographic.js';
import Color from '../Core/Color.js';
import defaultValue from '../Core/defaultValue.js';
import defined from '../Core/defined.js';
import Ellipsoid from '../Core/Ellipsoid.js';
import EncodedCartesian3 from '../Core/EncodedCartesian3.js';
import CesiumMath from '../Core/Math.js';
import Matrix3 from '../Core/Matrix3.js';
Expand Down Expand Up @@ -135,6 +136,7 @@ import SunLight from '../Scene/SunLight.js';
this._pass = undefined;
this._mode = undefined;
this._mapProjection = undefined;
this._ellipsoid = undefined;
this._cameraDirection = new Cartesian3();
this._cameraRight = new Cartesian3();
this._cameraUp = new Cartesian3();
Expand Down Expand Up @@ -998,6 +1000,18 @@ import SunLight from '../Scene/SunLight.js';
get : function() {
return this._orthographicIn3D;
}
},

/**
* The current ellipsoid.
*
* @memberOf UniformState.prototype
* @type {Ellipsoid}
*/
ellipsoid : {
get : function() {
return defaultValue(this._ellipsoid, Ellipsoid.WGS84);
}
}
});

Expand Down Expand Up @@ -1143,6 +1157,7 @@ import SunLight from '../Scene/SunLight.js';
UniformState.prototype.update = function(frameState) {
this._mode = frameState.mode;
this._mapProjection = frameState.mapProjection;
this._ellipsoid = frameState.mapProjection.ellipsoid;
this._pixelRatio = frameState.pixelRatio;

var camera = frameState.camera;
Expand Down
7 changes: 0 additions & 7 deletions Source/Shaders/Builtin/Constants/ellipsoidInverseRadii.glsl

This file was deleted.

7 changes: 0 additions & 7 deletions Source/Shaders/Builtin/Constants/ellipsoidRadii.glsl

This file was deleted.

41 changes: 41 additions & 0 deletions Specs/Renderer/AutomaticUniformSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Cartesian3 } from '../../Source/Cesium.js';
import { Color } from '../../Source/Cesium.js';
import { defaultValue } from '../../Source/Cesium.js';
import { DirectionalLight } from '../../Source/Cesium.js';
import { Ellipsoid } from '../../Source/Cesium.js';
import { GeographicProjection } from '../../Source/Cesium.js';
import { Matrix4 } from '../../Source/Cesium.js';
import { OrthographicFrustum } from '../../Source/Cesium.js';
import { OrthographicOffCenterFrustum } from '../../Source/Cesium.js';
Expand Down Expand Up @@ -1378,4 +1380,43 @@ describe('Renderer/AutomaticUniforms', function() {
}).contextToRender();
});

it('has czm_ellipsoidRadii', function() {
var us = context.uniformState;
var frameState = createFrameState(context, createMockCamera());
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
frameState.mapProjection = new GeographicProjection(ellipsoid);
us.update(frameState);
var fs =
'void main() {' +
' bool b0 = czm_ellipsoidRadii.x == 1.0;' +
' bool b1 = czm_ellipsoidRadii.y == 2.0;' +
' bool b2 = czm_ellipsoidRadii.z == 3.0;' +
' gl_FragColor = vec4(b0 && b1 && b2);' +
'}';
expect({
context : context,
fragmentShader : fs
}).contextToRender();
});

it('has czm_ellipsoidInverseRadii', function() {
var us = context.uniformState;
var frameState = createFrameState(context, createMockCamera());
var ellipsoid = new Ellipsoid(1.0, 1.0 / 2.0, 1.0 / 3.0);
frameState.mapProjection = new GeographicProjection(ellipsoid);
us.update(frameState);
var fs =
'float roundNumber(float number) { return floor(number + 0.5); }' +
'void main() {' +
' bool b0 = roundNumber(czm_ellipsoidInverseRadii.x) == 1.0;' +
' bool b1 = roundNumber(czm_ellipsoidInverseRadii.y) == 2.0;' +
' bool b2 = roundNumber(czm_ellipsoidInverseRadii.z) == 3.0;' +
' gl_FragColor = vec4(b0 && b1 && b2);' +
'}';
expect({
context : context,
fragmentShader : fs
}).contextToRender();
});

}, 'WebGL');

0 comments on commit 4081326

Please sign in to comment.