mirror of https://github.com/CesiumGS/cesium.git
Shader builtin functions/structs/constants broken into individual files. ShaderProgram.js now only concatenates builtins that are referenced from the particular shader being compiled.
This commit is contained in:
parent
43b7bd9d23
commit
87ddf10e02
|
|
@ -11,39 +11,7 @@ define([
|
|||
'./UniformDatatype',
|
||||
'../Shaders/Builtin/Structs',
|
||||
'../Shaders/Builtin/Constants',
|
||||
'../Shaders/Builtin/Functions/RGBToXYZ',
|
||||
'../Shaders/Builtin/Functions/XYZToRGB',
|
||||
'../Shaders/Builtin/Functions/antialias',
|
||||
'../Shaders/Builtin/Functions/cellular',
|
||||
'../Shaders/Builtin/Functions/columbusViewMorph',
|
||||
'../Shaders/Builtin/Functions/computePosition',
|
||||
'../Shaders/Builtin/Functions/eastNorthUpToEyeCoordinates',
|
||||
'../Shaders/Builtin/Functions/ellipsoidContainsPoint',
|
||||
'../Shaders/Builtin/Functions/ellipsoidNew',
|
||||
'../Shaders/Builtin/Functions/ellipsoidWgs84TextureCoordinates',
|
||||
'../Shaders/Builtin/Functions/equalsEpsilon',
|
||||
'../Shaders/Builtin/Functions/eyeOffset',
|
||||
'../Shaders/Builtin/Functions/eyeToWindowCoordinates',
|
||||
'../Shaders/Builtin/Functions/geodeticSurfaceNormal',
|
||||
'../Shaders/Builtin/Functions/getDefaultMaterial',
|
||||
'../Shaders/Builtin/Functions/getWaterNoise',
|
||||
'../Shaders/Builtin/Functions/getWgs84EllipsoidEC',
|
||||
'../Shaders/Builtin/Functions/hue',
|
||||
'../Shaders/Builtin/Functions/isEmpty',
|
||||
'../Shaders/Builtin/Functions/isFull',
|
||||
'../Shaders/Builtin/Functions/latitudeToWebMercatorFraction',
|
||||
'../Shaders/Builtin/Functions/luminance',
|
||||
'../Shaders/Builtin/Functions/modelToWindowCoordinates',
|
||||
'../Shaders/Builtin/Functions/multiplyWithColorBalance',
|
||||
'../Shaders/Builtin/Functions/phong',
|
||||
'../Shaders/Builtin/Functions/pointAlongRay',
|
||||
'../Shaders/Builtin/Functions/rayEllipsoidIntersectionInterval',
|
||||
'../Shaders/Builtin/Functions/saturation',
|
||||
'../Shaders/Builtin/Functions/snoise',
|
||||
'../Shaders/Builtin/Functions/tangentToEyeSpaceMatrix',
|
||||
'../Shaders/Builtin/Functions/translateRelativeToEye',
|
||||
'../Shaders/Builtin/Functions/transpose',
|
||||
'../Shaders/Builtin/Functions/windowToEyeCoordinates'
|
||||
'../Shaders/Builtin/Functions'
|
||||
], function(
|
||||
defined,
|
||||
DeveloperError,
|
||||
|
|
@ -56,39 +24,7 @@ define([
|
|||
UniformDatatype,
|
||||
ShadersBuiltinStructs,
|
||||
ShadersBuiltinConstants,
|
||||
czm_RGBToXYZ,
|
||||
czm_XYZToRGB,
|
||||
czm_antialias,
|
||||
czm_cellular,
|
||||
czm_columbusViewMorph,
|
||||
czm_computePosition,
|
||||
czm_eastNorthUpToEyeCoordinates,
|
||||
czm_ellipsoidContainsPoint,
|
||||
czm_ellipsoidNew,
|
||||
czm_ellipsoidWgs84TextureCoordinates,
|
||||
czm_equalsEpsilon,
|
||||
czm_eyeOffset,
|
||||
czm_eyeToWindowCoordinates,
|
||||
czm_geodeticSurfaceNormal,
|
||||
czm_getDefaultMaterial,
|
||||
czm_getWaterNoise,
|
||||
czm_getWgs84EllipsoidEC,
|
||||
czm_hue,
|
||||
czm_isEmpty,
|
||||
czm_isFull,
|
||||
czm_latitudeToWebMercatorFraction,
|
||||
czm_luminance,
|
||||
czm_modelToWindowCoordinates,
|
||||
czm_multiplyWithColorBalance,
|
||||
czm_phong,
|
||||
czm_pointAlongRay,
|
||||
czm_rayEllipsoidIntersectionInterval,
|
||||
czm_saturation,
|
||||
czm_snoise,
|
||||
czm_tangentToEyeSpaceMatrix,
|
||||
czm_translateRelativeToEye,
|
||||
czm_transpose,
|
||||
czm_windowToEyeCoordinates) {
|
||||
ShadersBuiltinFunctions) {
|
||||
"use strict";
|
||||
/*global console*/
|
||||
|
||||
|
|
@ -2402,57 +2338,45 @@ define([
|
|||
};
|
||||
}
|
||||
|
||||
var builtInFunctions = {
|
||||
czm_RGBToXYZ : czm_RGBToXYZ,
|
||||
czm_XYZToRGB : czm_XYZToRGB,
|
||||
czm_antialias : czm_antialias,
|
||||
czm_cellular : czm_cellular,
|
||||
czm_columbusViewMorph : czm_columbusViewMorph,
|
||||
czm_computePosition : czm_computePosition,
|
||||
czm_eastNorthUpToEyeCoordinates : czm_eastNorthUpToEyeCoordinates,
|
||||
czm_ellipsoidContainsPoint : czm_ellipsoidContainsPoint,
|
||||
czm_ellipsoidNew : czm_ellipsoidNew,
|
||||
czm_ellipsoidWgs84TextureCoordinates : czm_ellipsoidWgs84TextureCoordinates,
|
||||
czm_equalsEpsilon : czm_equalsEpsilon,
|
||||
czm_eyeOffset : czm_eyeOffset,
|
||||
czm_eyeToWindowCoordinates : czm_eyeToWindowCoordinates,
|
||||
czm_geodeticSurfaceNormal : czm_geodeticSurfaceNormal,
|
||||
czm_getDefaultMaterial : czm_getDefaultMaterial,
|
||||
czm_getWaterNoise : czm_getWaterNoise,
|
||||
czm_getWgs84EllipsoidEC : czm_getWgs84EllipsoidEC,
|
||||
czm_hue : czm_hue,
|
||||
czm_isEmpty : czm_isEmpty,
|
||||
czm_isFull : czm_isFull,
|
||||
czm_latitudeToWebMercatorFraction : czm_latitudeToWebMercatorFraction,
|
||||
czm_luminance : czm_luminance,
|
||||
czm_modelToWindowCoordinates : czm_modelToWindowCoordinates,
|
||||
czm_multiplyWithColorBalance : czm_multiplyWithColorBalance,
|
||||
czm_phong : czm_phong,
|
||||
czm_pointAlongRay : czm_pointAlongRay,
|
||||
czm_rayEllipsoidIntersectionInterval : czm_rayEllipsoidIntersectionInterval,
|
||||
czm_saturation : czm_saturation,
|
||||
czm_snoise : czm_snoise,
|
||||
czm_tangentToEyeSpaceMatrix : czm_tangentToEyeSpaceMatrix,
|
||||
czm_translateRelativeToEye : czm_translateRelativeToEye,
|
||||
czm_transpose : czm_transpose,
|
||||
czm_windowToEyeCoordinates : czm_windowToEyeCoordinates
|
||||
};
|
||||
|
||||
function getBuiltinFunctions(source) {
|
||||
// This expects well-behaved shaders, e.g., the built-in functions are not commented out or redeclared.
|
||||
function identifyBuiltins(source, builtinDictionary) {
|
||||
// This expects well-behaved shaders, e.g., the built-ins are not commented out or redeclared.
|
||||
var definitions = '';
|
||||
var functions = builtInFunctions;
|
||||
for (var f in functions) {
|
||||
if (functions.hasOwnProperty(f)) {
|
||||
if (source.indexOf(f) !== -1) {
|
||||
definitions += functions[f] + ' \n';
|
||||
for (var b in builtinDictionary) {
|
||||
if (builtinDictionary.hasOwnProperty(b)) {
|
||||
if (source.indexOf(b) !== -1) {
|
||||
definitions += builtinDictionary[b] + ' \n';
|
||||
|
||||
// remove the entry from the dictionary so we can't recurse indefinitely
|
||||
delete builtinDictionary[b];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// recurse incase a found builtin calls other builtin functions/structs/constants
|
||||
if(definitions !== '') {
|
||||
definitions = definitions + '\n' + identifyBuiltins(definitions, builtinDictionary);
|
||||
}
|
||||
|
||||
return definitions;
|
||||
}
|
||||
|
||||
function getBuiltins(source) {
|
||||
var builtins = identifyBuiltins(source, cloneHashSet(ShadersBuiltinFunctions));
|
||||
builtins = identifyBuiltins(builtins + source, cloneHashSet(ShadersBuiltinStructs)) + builtins;
|
||||
builtins = identifyBuiltins(builtins + source, cloneHashSet(ShadersBuiltinConstants)) + builtins;
|
||||
return builtins;
|
||||
}
|
||||
|
||||
function cloneHashSet(originalHashSet) {
|
||||
var copy = {};
|
||||
for ( var property in originalHashSet ) {
|
||||
if ( originalHashSet.hasOwnProperty( property ) ) {
|
||||
copy[ property ] = originalHashSet[ property ];
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
function getFragmentShaderPrecision() {
|
||||
return '#ifdef GL_FRAGMENT_PRECISION_HIGH \n' +
|
||||
' precision highp float; \n' +
|
||||
|
|
@ -2494,24 +2418,20 @@ define([
|
|||
var vsSourceVersioned = extractShaderVersion(vertexShaderSource);
|
||||
var fsSourceVersioned = extractShaderVersion(fragmentShaderSource);
|
||||
|
||||
var vsAndBuiltinFunctions = getBuiltinFunctions(vsSourceVersioned.source) +
|
||||
var vsAndBuiltins = getBuiltins(vsSourceVersioned.source) +
|
||||
'\n#line 0\n' +
|
||||
vsSourceVersioned.source;
|
||||
var vsSource = vsSourceVersioned.version +
|
||||
ShadersBuiltinConstants +
|
||||
ShadersBuiltinStructs +
|
||||
getAutomaticUniforms(vsAndBuiltinFunctions) +
|
||||
vsAndBuiltinFunctions;
|
||||
getAutomaticUniforms(vsAndBuiltins) +
|
||||
vsAndBuiltins;
|
||||
|
||||
var fsAndBuiltinFunctions = getBuiltinFunctions(fsSourceVersioned.source) +
|
||||
var fsAndBuiltins = getBuiltins(fsSourceVersioned.source) +
|
||||
'\n#line 0\n' +
|
||||
fsSourceVersioned.source;
|
||||
var fsSource = fsSourceVersioned.version +
|
||||
getFragmentShaderPrecision() +
|
||||
ShadersBuiltinConstants +
|
||||
ShadersBuiltinStructs +
|
||||
getAutomaticUniforms(fsAndBuiltinFunctions) +
|
||||
fsAndBuiltinFunctions;
|
||||
getAutomaticUniforms(fsAndBuiltins) +
|
||||
fsAndBuiltins;
|
||||
|
||||
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
|
||||
gl.shaderSource(vertexShader, vsSource);
|
||||
|
|
|
|||
|
|
@ -1,329 +0,0 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>Math.PI</code>.
|
||||
*
|
||||
* @alias czm_pi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_pi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float twoPi = 2.0 * czm_pi;
|
||||
*/
|
||||
const float czm_pi = 3.141592653589793;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>1/pi</code>.
|
||||
*
|
||||
* @alias czm_oneOverPi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.ONE_OVER_PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_oneOverPi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 1.0 / czm_oneOverPi;
|
||||
*/
|
||||
const float czm_oneOverPi = 0.3183098861837907;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/2</code>.
|
||||
*
|
||||
* @alias czm_piOverTwo
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_TWO
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverTwo = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 2.0 * czm_piOverTwo;
|
||||
*/
|
||||
const float czm_piOverTwo = 1.5707963267948966;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/3</code>.
|
||||
*
|
||||
* @alias czm_piOverThree
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_THREE
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverThree = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 3.0 * czm_piOverThree;
|
||||
*/
|
||||
const float czm_piOverThree = 1.0471975511965976;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/4</code>.
|
||||
*
|
||||
* @alias czm_piOverFour
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_FOUR
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverFour = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 4.0 * czm_piOverFour;
|
||||
*/
|
||||
const float czm_piOverFour = 0.7853981633974483;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/6</code>.
|
||||
*
|
||||
* @alias czm_piOverSix
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_SIX
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverSix = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 6.0 * czm_piOverSix;
|
||||
*/
|
||||
const float czm_piOverSix = 0.5235987755982988;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>3pi/2</code>.
|
||||
*
|
||||
* @alias czm_threePiOver2
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.THREE_PI_OVER_TWO
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_threePiOver2 = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = (2.0 / 3.0) * czm_threePiOver2;
|
||||
*/
|
||||
const float czm_threePiOver2 = 4.71238898038469;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>2pi</code>.
|
||||
*
|
||||
* @alias czm_twoPi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.TWO_PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_twoPi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = czm_twoPi / 2.0;
|
||||
*/
|
||||
const float czm_twoPi = 6.283185307179586;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for <code>1/2pi</code>.
|
||||
*
|
||||
* @alias czm_oneOverTwoPi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.ONE_OVER_TWO_PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_oneOverTwoPi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 2.0 * czm_oneOverTwoPi;
|
||||
*/
|
||||
const float czm_oneOverTwoPi = 0.15915494309189535;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for converting degrees to radians.
|
||||
*
|
||||
* @alias czm_radiansPerDegree
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.RADIANS_PER_DEGREE
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_radiansPerDegree = ...;
|
||||
*
|
||||
* // Example
|
||||
* float rad = czm_radiansPerDegree * deg;
|
||||
*/
|
||||
const float czm_radiansPerDegree = 0.017453292519943295;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for converting radians to degrees.
|
||||
*
|
||||
* @alias czm_degreesPerRadian
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.DEGREES_PER_RADIAN
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_degreesPerRadian = ...;
|
||||
*
|
||||
* // Example
|
||||
* float deg = czm_degreesPerRadian * rad;
|
||||
*/
|
||||
const float czm_degreesPerRadian = 57.29577951308232;
|
||||
|
||||
/**
|
||||
* A built-in GLSL floating-point constant for one solar radius.
|
||||
*
|
||||
* @alias czm_solarRadius
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.SOLAR_RADIUS
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_solarRadius = ...;
|
||||
*/
|
||||
const float czm_solarRadius = 699500000.0;
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_infinity
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_infinity = 5906376272000.0; // Distance from the Sun to Pluto in meters. TODO: What is best given lowp, mediump, and highp?
|
||||
|
||||
/**
|
||||
* 0.1
|
||||
*
|
||||
* @name czm_epsilon1
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon1 = 0.1;
|
||||
|
||||
/**
|
||||
* 0.01
|
||||
*
|
||||
* @name czm_epsilon2
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon2 = 0.01;
|
||||
|
||||
/**
|
||||
* 0.001
|
||||
*
|
||||
* @name czm_epsilon3
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon3 = 0.001;
|
||||
|
||||
/**
|
||||
* 0.0001
|
||||
*
|
||||
* @name czm_epsilon4
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon4 = 0.0001;
|
||||
|
||||
/**
|
||||
* 0.00001
|
||||
*
|
||||
* @name czm_epsilon5
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon5 = 0.00001;
|
||||
|
||||
/**
|
||||
* 0.000001
|
||||
*
|
||||
* @name czm_epsilon6
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon6 = 0.000001;
|
||||
|
||||
/**
|
||||
* 0.0000001
|
||||
*
|
||||
* @name czm_epsilon7
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon7 = 0.0000001;
|
||||
|
||||
/**
|
||||
* The maximum latitude, in radians, both North and South, supported by a Web Mercator
|
||||
* (EPSG:3857) projection. Technically, the Mercator projection is defined
|
||||
* for any latitude up to (but not including) 90 degrees, but it makes sense
|
||||
* to cut it off sooner because it grows exponentially with increasing latitude.
|
||||
* The logic behind this particular cutoff value, which is the one used by
|
||||
* Google Maps, Bing Maps, and Esri, is that it makes the projection
|
||||
* square. That is, the extent is equal in the X and Y directions.
|
||||
*
|
||||
* The constant value is computed as follows:
|
||||
* czm_pi * 0.5 - (2.0 * atan(exp(-czm_pi)))
|
||||
*
|
||||
* @name czm_webMercatorMaxLatitude
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_webMercatorMaxLatitude = 1.4844222297453324;
|
||||
|
||||
/**
|
||||
* The constant identifier for the 2D {@link SceneMode}
|
||||
*
|
||||
* @name czm_sceneMode2D
|
||||
* @glslConstant
|
||||
* @see czm_sceneMode
|
||||
* @see czm_sceneModeColumbusView
|
||||
* @see czm_sceneMode3D
|
||||
* @see czm_sceneModeMorphing
|
||||
*/
|
||||
const float czm_sceneMode2D = 0.0;
|
||||
|
||||
/**
|
||||
* The constant identifier for the Columbus View {@link SceneMode}
|
||||
*
|
||||
* @name czm_sceneModeColumbusView
|
||||
* @glslConstant
|
||||
* @see czm_sceneMode
|
||||
* @see czm_sceneMode2D
|
||||
* @see czm_sceneMode3D
|
||||
* @see czm_sceneModeMorphing
|
||||
*/
|
||||
const float czm_sceneModeColumbusView = 1.0;
|
||||
|
||||
/**
|
||||
* The constant identifier for the 3D {@link SceneMode}
|
||||
*
|
||||
* @name czm_sceneMode3D
|
||||
* @glslConstant
|
||||
* @see czm_sceneMode
|
||||
* @see czm_sceneMode2D
|
||||
* @see czm_sceneModeColumbusView
|
||||
* @see czm_sceneModeMorphing
|
||||
*/
|
||||
const float czm_sceneMode3D = 2.0;
|
||||
|
||||
/**
|
||||
* The constant identifier for the Morphing {@link SceneMode}
|
||||
*
|
||||
* @name czm_sceneModeMorphing
|
||||
* @glslConstant
|
||||
* @see czm_sceneMode
|
||||
* @see czm_sceneMode2D
|
||||
* @see czm_sceneModeColumbusView
|
||||
* @see czm_sceneMode3D
|
||||
*/
|
||||
const float czm_sceneModeMorphing = 3.0;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for converting radians to degrees.
|
||||
*
|
||||
* @alias czm_degreesPerRadian
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.DEGREES_PER_RADIAN
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_degreesPerRadian = ...;
|
||||
*
|
||||
* // Example
|
||||
* float deg = czm_degreesPerRadian * rad;
|
||||
*/
|
||||
const float czm_degreesPerRadian = 57.29577951308232;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 0.1
|
||||
*
|
||||
* @name czm_epsilon1
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon1 = 0.1;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 0.01
|
||||
*
|
||||
* @name czm_epsilon2
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon2 = 0.01;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 0.001
|
||||
*
|
||||
* @name czm_epsilon3
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon3 = 0.001;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 0.0001
|
||||
*
|
||||
* @name czm_epsilon4
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon4 = 0.0001;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 0.00001
|
||||
*
|
||||
* @name czm_epsilon5
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon5 = 0.00001;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 0.000001
|
||||
*
|
||||
* @name czm_epsilon6
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon6 = 0.000001;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 0.0000001
|
||||
*
|
||||
* @name czm_epsilon7
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_epsilon7 = 0.0000001;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_infinity
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_infinity = 5906376272000.0; // Distance from the Sun to Pluto in meters. TODO: What is best given lowp, mediump, and highp?
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>1/pi</code>.
|
||||
*
|
||||
* @alias czm_oneOverPi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.ONE_OVER_PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_oneOverPi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 1.0 / czm_oneOverPi;
|
||||
*/
|
||||
const float czm_oneOverPi = 0.3183098861837907;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>1/2pi</code>.
|
||||
*
|
||||
* @alias czm_oneOverTwoPi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.ONE_OVER_TWO_PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_oneOverTwoPi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 2.0 * czm_oneOverTwoPi;
|
||||
*/
|
||||
const float czm_oneOverTwoPi = 0.15915494309189535;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>Math.PI</code>.
|
||||
*
|
||||
* @alias czm_pi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_pi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float twoPi = 2.0 * czm_pi;
|
||||
*/
|
||||
const float czm_pi = 3.141592653589793;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/4</code>.
|
||||
*
|
||||
* @alias czm_piOverFour
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_FOUR
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverFour = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 4.0 * czm_piOverFour;
|
||||
*/
|
||||
const float czm_piOverFour = 0.7853981633974483;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/6</code>.
|
||||
*
|
||||
* @alias czm_piOverSix
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_SIX
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverSix = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 6.0 * czm_piOverSix;
|
||||
*/
|
||||
const float czm_piOverSix = 0.5235987755982988;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/3</code>.
|
||||
*
|
||||
* @alias czm_piOverThree
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_THREE
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverThree = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 3.0 * czm_piOverThree;
|
||||
*/
|
||||
const float czm_piOverThree = 1.0471975511965976;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>pi/2</code>.
|
||||
*
|
||||
* @alias czm_piOverTwo
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.PI_OVER_TWO
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_piOverTwo = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = 2.0 * czm_piOverTwo;
|
||||
*/
|
||||
const float czm_piOverTwo = 1.5707963267948966;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for converting degrees to radians.
|
||||
*
|
||||
* @alias czm_radiansPerDegree
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.RADIANS_PER_DEGREE
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_radiansPerDegree = ...;
|
||||
*
|
||||
* // Example
|
||||
* float rad = czm_radiansPerDegree * deg;
|
||||
*/
|
||||
const float czm_radiansPerDegree = 0.017453292519943295;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for one solar radius.
|
||||
*
|
||||
* @alias czm_solarRadius
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.SOLAR_RADIUS
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_solarRadius = ...;
|
||||
*/
|
||||
const float czm_solarRadius = 699500000.0;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>3pi/2</code>.
|
||||
*
|
||||
* @alias czm_threePiOver2
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.THREE_PI_OVER_TWO
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_threePiOver2 = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = (2.0 / 3.0) * czm_threePiOver2;
|
||||
*/
|
||||
const float czm_threePiOver2 = 4.71238898038469;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* A built-in GLSL floating-point constant for <code>2pi</code>.
|
||||
*
|
||||
* @alias czm_twoPi
|
||||
* @glslConstant
|
||||
*
|
||||
* @see CesiumMath.TWO_PI
|
||||
*
|
||||
* @example
|
||||
* // GLSL declaration
|
||||
* const float czm_twoPi = ...;
|
||||
*
|
||||
* // Example
|
||||
* float pi = czm_twoPi / 2.0;
|
||||
*/
|
||||
const float czm_twoPi = 6.283185307179586;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* The maximum latitude, in radians, both North and South, supported by a Web Mercator
|
||||
* (EPSG:3857) projection. Technically, the Mercator projection is defined
|
||||
* for any latitude up to (but not including) 90 degrees, but it makes sense
|
||||
* to cut it off sooner because it grows exponentially with increasing latitude.
|
||||
* The logic behind this particular cutoff value, which is the one used by
|
||||
* Google Maps, Bing Maps, and Esri, is that it makes the projection
|
||||
* square. That is, the extent is equal in the X and Y directions.
|
||||
*
|
||||
* The constant value is computed as follows:
|
||||
* czm_pi * 0.5 - (2.0 * atan(exp(-czm_pi)))
|
||||
*
|
||||
* @name czm_webMercatorMaxLatitude
|
||||
* @glslConstant
|
||||
*/
|
||||
const float czm_webMercatorMaxLatitude = 1.4844222297453324;
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/**
|
||||
* Used as input to every material's czm_getMaterial function.
|
||||
*
|
||||
* @name czm_materialInput
|
||||
* @glslStruct
|
||||
*
|
||||
* @property {float} s 1D texture coordinates.
|
||||
* @property {vec2} st 2D texture coordinates.
|
||||
* @property {vec3} str 3D texture coordinates.
|
||||
* @property {vec3} normalEC Unperturbed surface normal in eye coordinates.
|
||||
* @property {mat3} tangentToEyeMatrix Matrix for converting a tangent space normal to eye space.
|
||||
* @property {vec3} positionToEyeEC Vector from the fragment to the eye in eye coordinates. The magnitude is the distance in meters from the fragment to the eye.
|
||||
*/
|
||||
struct czm_materialInput
|
||||
{
|
||||
float s;
|
||||
vec2 st;
|
||||
vec3 str;
|
||||
vec3 normalEC;
|
||||
mat3 tangentToEyeMatrix;
|
||||
vec3 positionToEyeEC;
|
||||
};
|
||||
|
||||
/**
|
||||
* Holds material information that can be used for lighting. Returned by all czm_getMaterial functions.
|
||||
*
|
||||
* @name czm_material
|
||||
* @glslStruct
|
||||
*
|
||||
* @property {vec3} diffuse Incoming light that scatters evenly in all directions.
|
||||
* @property {float} specular Intensity of incoming light reflecting in a single direction.
|
||||
* @property {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight.
|
||||
* @property {vec3} normal Surface's normal in eye coordinates. It is used for effects such as normal mapping. The default is the surface's unmodified normal.
|
||||
* @property {vec3} emission Light emitted by the material equally in all directions. The default is vec3(0.0), which emits no light.
|
||||
* @property {float} alpha Opacity of this material. 0.0 is completely transparent; 1.0 is completely opaque.
|
||||
*/
|
||||
struct czm_material
|
||||
{
|
||||
vec3 diffuse;
|
||||
float specular;
|
||||
float shininess;
|
||||
vec3 normal;
|
||||
vec3 emission;
|
||||
float alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_ray
|
||||
* @glslStruct
|
||||
*/
|
||||
struct czm_ray
|
||||
{
|
||||
vec3 origin;
|
||||
vec3 direction;
|
||||
};
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_raySegment
|
||||
* @glslStruct
|
||||
*/
|
||||
struct czm_raySegment
|
||||
{
|
||||
float start;
|
||||
float stop;
|
||||
};
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_emptyRaySegment
|
||||
* @glslConstant
|
||||
*/
|
||||
const czm_raySegment czm_emptyRaySegment = czm_raySegment(-czm_infinity, -czm_infinity);
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_fullRaySegment
|
||||
* @glslConstant
|
||||
*/
|
||||
const czm_raySegment czm_fullRaySegment = czm_raySegment(0.0, czm_infinity);
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_ellipsoid
|
||||
* @glslStruct
|
||||
*/
|
||||
struct czm_ellipsoid
|
||||
{
|
||||
vec3 center;
|
||||
vec3 radii;
|
||||
vec3 inverseRadii;
|
||||
vec3 inverseRadiiSquared;
|
||||
};
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
/** DOC_TBA
|
||||
*
|
||||
* @name czm_ellipsoid
|
||||
* @glslStruct
|
||||
*/
|
||||
struct czm_ellipsoid
|
||||
{
|
||||
vec3 center;
|
||||
vec3 radii;
|
||||
vec3 inverseRadii;
|
||||
vec3 inverseRadiiSquared;
|
||||
};
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* Holds material information that can be used for lighting. Returned by all czm_getMaterial functions.
|
||||
*
|
||||
* @name czm_material
|
||||
* @glslStruct
|
||||
*
|
||||
* @property {vec3} diffuse Incoming light that scatters evenly in all directions.
|
||||
* @property {float} specular Intensity of incoming light reflecting in a single direction.
|
||||
* @property {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight.
|
||||
* @property {vec3} normal Surface's normal in eye coordinates. It is used for effects such as normal mapping. The default is the surface's unmodified normal.
|
||||
* @property {vec3} emission Light emitted by the material equally in all directions. The default is vec3(0.0), which emits no light.
|
||||
* @property {float} alpha Opacity of this material. 0.0 is completely transparent; 1.0 is completely opaque.
|
||||
*/
|
||||
struct czm_material
|
||||
{
|
||||
vec3 diffuse;
|
||||
float specular;
|
||||
float shininess;
|
||||
vec3 normal;
|
||||
vec3 emission;
|
||||
float alpha;
|
||||
};
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* Used as input to every material's czm_getMaterial function.
|
||||
*
|
||||
* @name czm_materialInput
|
||||
* @glslStruct
|
||||
*
|
||||
* @property {float} s 1D texture coordinates.
|
||||
* @property {vec2} st 2D texture coordinates.
|
||||
* @property {vec3} str 3D texture coordinates.
|
||||
* @property {vec3} normalEC Unperturbed surface normal in eye coordinates.
|
||||
* @property {mat3} tangentToEyeMatrix Matrix for converting a tangent space normal to eye space.
|
||||
* @property {vec3} positionToEyeEC Vector from the fragment to the eye in eye coordinates. The magnitude is the distance in meters from the fragment to the eye.
|
||||
*/
|
||||
struct czm_materialInput
|
||||
{
|
||||
float s;
|
||||
vec2 st;
|
||||
vec3 str;
|
||||
vec3 normalEC;
|
||||
mat3 tangentToEyeMatrix;
|
||||
vec3 positionToEyeEC;
|
||||
};
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_ray
|
||||
* @glslStruct
|
||||
*/
|
||||
struct czm_ray
|
||||
{
|
||||
vec3 origin;
|
||||
vec3 direction;
|
||||
};
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_raySegment
|
||||
* @glslStruct
|
||||
*/
|
||||
struct czm_raySegment
|
||||
{
|
||||
float start;
|
||||
float stop;
|
||||
};
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_emptyRaySegment
|
||||
* @glslConstant
|
||||
*/
|
||||
const czm_raySegment czm_emptyRaySegment = czm_raySegment(-czm_infinity, -czm_infinity);
|
||||
|
||||
/**
|
||||
* DOC_TBA
|
||||
*
|
||||
* @name czm_fullRaySegment
|
||||
* @glslConstant
|
||||
*/
|
||||
const czm_raySegment czm_fullRaySegment = czm_raySegment(0.0, czm_infinity);
|
||||
|
|
@ -25,11 +25,26 @@ forEachFile('existingjsfiles', function(relativePath, file) {
|
|||
leftOverJsFiles.add(file.getAbsolutePath());
|
||||
});
|
||||
|
||||
var builtinFunctions = [];
|
||||
var builtinConstants = [];
|
||||
var builtinStructs = [];
|
||||
|
||||
forEachFile('glslfiles', function(relativePath, file) {
|
||||
"use strict";
|
||||
var glslFile = file;
|
||||
var jsFile = new File(file.getParent(), file.getName().replace('.glsl', '.js'));
|
||||
|
||||
// identify built in functions, structs, and constants
|
||||
if(glslFile.getPath().indexOf('Builtin' + File.separator + 'Functions') != -1) {
|
||||
builtinFunctions.push(file.getName().replace('.glsl', ''));
|
||||
}
|
||||
else if(glslFile.getPath().indexOf('Builtin' + File.separator + 'Constants') != -1) {
|
||||
builtinConstants.push(file.getName().replace('.glsl', ''));
|
||||
}
|
||||
else if(glslFile.getPath().indexOf('Builtin' + File.separator + 'Structs') != -1) {
|
||||
builtinStructs.push(file.getName().replace('.glsl', ''));
|
||||
}
|
||||
|
||||
leftOverJsFiles.remove(jsFile.getAbsolutePath());
|
||||
|
||||
if (jsFile.exists() && jsFile.lastModified() > glslFile.lastModified() && jsFile.lastModified() > minifyStateFileLastModified) {
|
||||
|
|
@ -66,4 +81,121 @@ return "' + contents + '";\n\
|
|||
// delete any left over JS files from old shaders
|
||||
for ( var it = leftOverJsFiles.iterator(); it.hasNext();) {
|
||||
new File(it.next())['delete']();
|
||||
}
|
||||
}
|
||||
|
||||
// create BuiltinFunctions.js for runtime concatenation of builtin functions
|
||||
//var functionsFile = new File('D:/gbeatty_cesium/Source/Shaders/Builtin', 'Functions.js');
|
||||
var functionsFile = new File(project.getProperty('shadersDirectory') + '/Builtin', 'Functions.js');
|
||||
|
||||
var amdPath = '';
|
||||
var amdClassName = '';
|
||||
var builtinLookup = '';
|
||||
|
||||
for (var i = 0; i < builtinFunctions.length; i++) {
|
||||
var builtinFunction = builtinFunctions[i];
|
||||
|
||||
if(i !== 0) {
|
||||
amdPath = amdPath + ',\n';
|
||||
amdClassName = amdClassName + ',\n';
|
||||
builtinLookup = builtinLookup + ',\n';
|
||||
}
|
||||
|
||||
amdPath = amdPath + ' \'./Functions/' + builtinFunction + '\'';
|
||||
amdClassName = amdClassName + ' ' + builtinFunction;
|
||||
builtinLookup = builtinLookup + ' ' + builtinFunction + ' : ' + builtinFunction;
|
||||
}
|
||||
|
||||
contents = '\
|
||||
//This file is automatically rebuilt by the Cesium build process.\n\
|
||||
/*global define*/\n\
|
||||
define([\n' +
|
||||
amdPath +
|
||||
'\n ], function(\n' +
|
||||
amdClassName +
|
||||
') {\n\
|
||||
"use strict";\n\
|
||||
return {\n' + builtinLookup + '};\n\
|
||||
});';
|
||||
|
||||
writeFileContents(functionsFile.getAbsolutePath(), contents, true);
|
||||
|
||||
|
||||
//create BuiltinConstants.js for runtime concatenation of built in constants
|
||||
var constantsFile = new File(project.getProperty('shadersDirectory') + '/Builtin', 'Constants.js');
|
||||
|
||||
amdPath = '';
|
||||
amdClassName = '';
|
||||
builtinLookup = '';
|
||||
|
||||
for (var i = 0; i < builtinConstants.length; i++) {
|
||||
var builtinConstant = builtinConstants[i];
|
||||
|
||||
if(i !== 0) {
|
||||
amdPath = amdPath + ',\n';
|
||||
amdClassName = amdClassName + ',\n';
|
||||
builtinLookup = builtinLookup + ',\n';
|
||||
}
|
||||
|
||||
amdPath = amdPath + ' \'./Constants/' + builtinConstant + '\'';
|
||||
amdClassName = amdClassName + ' ' + builtinConstant;
|
||||
builtinLookup = builtinLookup + ' ' + builtinConstant + ' : ' + builtinConstant;
|
||||
}
|
||||
|
||||
contents = '\
|
||||
//This file is automatically rebuilt by the Cesium build process.\n\
|
||||
/*global define*/\n\
|
||||
define([\n' +
|
||||
amdPath +
|
||||
'\n ], function(\n' +
|
||||
amdClassName +
|
||||
') {\n\
|
||||
"use strict";\n\
|
||||
return {\n' + builtinLookup + '};\n\
|
||||
});';
|
||||
|
||||
writeFileContents(constantsFile.getAbsolutePath(), contents, true);
|
||||
|
||||
|
||||
//create BuiltinStructs.js for runtime concatenation of built in constants
|
||||
var structsFile = new File(project.getProperty('shadersDirectory') + '/Builtin', 'Structs.js');
|
||||
|
||||
amdPath = '';
|
||||
amdClassName = '';
|
||||
builtinLookup = '';
|
||||
|
||||
for (var i = 0; i < builtinStructs.length; i++) {
|
||||
var builtinStruct = builtinStructs[i];
|
||||
|
||||
if(i !== 0) {
|
||||
amdPath = amdPath + ',\n';
|
||||
amdClassName = amdClassName + ',\n';
|
||||
builtinLookup = builtinLookup + ',\n';
|
||||
}
|
||||
|
||||
amdPath = amdPath + ' \'./Structs/' + builtinStruct + '\'';
|
||||
amdClassName = amdClassName + ' ' + builtinStruct;
|
||||
builtinLookup = builtinLookup + ' ' + builtinStruct + ' : ' + builtinStruct;
|
||||
}
|
||||
|
||||
contents = '\
|
||||
//This file is automatically rebuilt by the Cesium build process.\n\
|
||||
/*global define*/\n\
|
||||
define([\n' +
|
||||
amdPath +
|
||||
'\n ], function(\n' +
|
||||
amdClassName +
|
||||
') {\n\
|
||||
"use strict";\n\
|
||||
return {\n' + builtinLookup + '};\n\
|
||||
});';
|
||||
|
||||
writeFileContents(structsFile.getAbsolutePath(), contents, true);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue