Add existing to tracked

This commit is contained in:
Jay
2026-08-11 09:53:42 -04:00
parent afe07f3055
commit ffd6e3d73c
8531 changed files with 4396230 additions and 0 deletions
@@ -0,0 +1,24 @@
/**
* Converts an HSB color (hue, saturation, brightness) to RGB
* HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl}
*
* @name czm_HSBToRGB
* @glslFunction
*
* @param {vec3} hsb The color in HSB.
*
* @returns {vec3} The color in RGB.
*
* @example
* vec3 hsb = czm_RGBToHSB(rgb);
* hsb.z *= 0.1;
* rgb = czm_HSBToRGB(hsb);
*/
const vec4 K_HSB2RGB = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 czm_HSBToRGB(vec3 hsb)
{
vec3 p = abs(fract(hsb.xxx + K_HSB2RGB.xyz) * 6.0 - K_HSB2RGB.www);
return hsb.z * mix(K_HSB2RGB.xxx, clamp(p - K_HSB2RGB.xxx, 0.0, 1.0), hsb.y);
}
@@ -0,0 +1,26 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts an HSB color (hue, saturation, brightness) to RGB\n\
* HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl}\n\
*\n\
* @name czm_HSBToRGB\n\
* @glslFunction\n\
* \n\
* @param {vec3} hsb The color in HSB.\n\
*\n\
* @returns {vec3} The color in RGB.\n\
*\n\
* @example\n\
* vec3 hsb = czm_RGBToHSB(rgb);\n\
* hsb.z *= 0.1;\n\
* rgb = czm_HSBToRGB(hsb);\n\
*/\n\
\n\
const vec4 K_HSB2RGB = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\
\n\
vec3 czm_HSBToRGB(vec3 hsb)\n\
{\n\
vec3 p = abs(fract(hsb.xxx + K_HSB2RGB.xyz) * 6.0 - K_HSB2RGB.www);\n\
return hsb.z * mix(K_HSB2RGB.xxx, clamp(p - K_HSB2RGB.xxx, 0.0, 1.0), hsb.y);\n\
}\n\
";
@@ -0,0 +1,31 @@
/**
* Converts an HSL color (hue, saturation, lightness) to RGB
* HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html}
*
* @name czm_HSLToRGB
* @glslFunction
*
* @param {vec3} rgb The color in HSL.
*
* @returns {vec3} The color in RGB.
*
* @example
* vec3 hsl = czm_RGBToHSL(rgb);
* hsl.z *= 0.1;
* rgb = czm_HSLToRGB(hsl);
*/
vec3 hueToRGB(float hue)
{
float r = abs(hue * 6.0 - 3.0) - 1.0;
float g = 2.0 - abs(hue * 6.0 - 2.0);
float b = 2.0 - abs(hue * 6.0 - 4.0);
return clamp(vec3(r, g, b), 0.0, 1.0);
}
vec3 czm_HSLToRGB(vec3 hsl)
{
vec3 rgb = hueToRGB(hsl.x);
float c = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y;
return (rgb - 0.5) * c + hsl.z;
}
@@ -0,0 +1,33 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts an HSL color (hue, saturation, lightness) to RGB\n\
* HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html}\n\
*\n\
* @name czm_HSLToRGB\n\
* @glslFunction\n\
* \n\
* @param {vec3} rgb The color in HSL.\n\
*\n\
* @returns {vec3} The color in RGB.\n\
*\n\
* @example\n\
* vec3 hsl = czm_RGBToHSL(rgb);\n\
* hsl.z *= 0.1;\n\
* rgb = czm_HSLToRGB(hsl);\n\
*/\n\
\n\
vec3 hueToRGB(float hue)\n\
{\n\
float r = abs(hue * 6.0 - 3.0) - 1.0;\n\
float g = 2.0 - abs(hue * 6.0 - 2.0);\n\
float b = 2.0 - abs(hue * 6.0 - 4.0);\n\
return clamp(vec3(r, g, b), 0.0, 1.0);\n\
}\n\
\n\
vec3 czm_HSLToRGB(vec3 hsl)\n\
{\n\
vec3 rgb = hueToRGB(hsl.x);\n\
float c = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y;\n\
return (rgb - 0.5) * c + hsl.z;\n\
}\n\
";
@@ -0,0 +1,27 @@
/**
* Converts an RGB color to HSB (hue, saturation, brightness)
* HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl}
*
* @name czm_RGBToHSB
* @glslFunction
*
* @param {vec3} rgb The color in RGB.
*
* @returns {vec3} The color in HSB.
*
* @example
* vec3 hsb = czm_RGBToHSB(rgb);
* hsb.z *= 0.1;
* rgb = czm_HSBToRGB(hsb);
*/
const vec4 K_RGB2HSB = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec3 czm_RGBToHSB(vec3 rgb)
{
vec4 p = mix(vec4(rgb.bg, K_RGB2HSB.wz), vec4(rgb.gb, K_RGB2HSB.xy), step(rgb.b, rgb.g));
vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r));
float d = q.x - min(q.w, q.y);
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + czm_epsilon7)), d / (q.x + czm_epsilon7), q.x);
}
@@ -0,0 +1,29 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts an RGB color to HSB (hue, saturation, brightness)\n\
* HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl}\n\
*\n\
* @name czm_RGBToHSB\n\
* @glslFunction\n\
* \n\
* @param {vec3} rgb The color in RGB.\n\
*\n\
* @returns {vec3} The color in HSB.\n\
*\n\
* @example\n\
* vec3 hsb = czm_RGBToHSB(rgb);\n\
* hsb.z *= 0.1;\n\
* rgb = czm_HSBToRGB(hsb);\n\
*/\n\
\n\
const vec4 K_RGB2HSB = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\
\n\
vec3 czm_RGBToHSB(vec3 rgb)\n\
{\n\
vec4 p = mix(vec4(rgb.bg, K_RGB2HSB.wz), vec4(rgb.gb, K_RGB2HSB.xy), step(rgb.b, rgb.g));\n\
vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r));\n\
\n\
float d = q.x - min(q.w, q.y);\n\
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + czm_epsilon7)), d / (q.x + czm_epsilon7), q.x);\n\
}\n\
";
@@ -0,0 +1,34 @@
/**
* Converts an RGB color to HSL (hue, saturation, lightness)
* HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html}
*
* @name czm_RGBToHSL
* @glslFunction
*
* @param {vec3} rgb The color in RGB.
*
* @returns {vec3} The color in HSL.
*
* @example
* vec3 hsl = czm_RGBToHSL(rgb);
* hsl.z *= 0.1;
* rgb = czm_HSLToRGB(hsl);
*/
vec3 RGBtoHCV(vec3 rgb)
{
// Based on work by Sam Hocevar and Emil Persson
vec4 p = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0 / 3.0) : vec4(rgb.gb, 0.0, -1.0 / 3.0);
vec4 q = (rgb.r < p.x) ? vec4(p.xyw, rgb.r) : vec4(rgb.r, p.yzx);
float c = q.x - min(q.w, q.y);
float h = abs((q.w - q.y) / (6.0 * c + czm_epsilon7) + q.z);
return vec3(h, c, q.x);
}
vec3 czm_RGBToHSL(vec3 rgb)
{
vec3 hcv = RGBtoHCV(rgb);
float l = hcv.z - hcv.y * 0.5;
float s = hcv.y / (1.0 - abs(l * 2.0 - 1.0) + czm_epsilon7);
return vec3(hcv.x, s, l);
}
@@ -0,0 +1,36 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts an RGB color to HSL (hue, saturation, lightness)\n\
* HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html}\n\
*\n\
* @name czm_RGBToHSL\n\
* @glslFunction\n\
* \n\
* @param {vec3} rgb The color in RGB.\n\
*\n\
* @returns {vec3} The color in HSL.\n\
*\n\
* @example\n\
* vec3 hsl = czm_RGBToHSL(rgb);\n\
* hsl.z *= 0.1;\n\
* rgb = czm_HSLToRGB(hsl);\n\
*/\n\
\n\
vec3 RGBtoHCV(vec3 rgb)\n\
{\n\
// Based on work by Sam Hocevar and Emil Persson\n\
vec4 p = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0 / 3.0) : vec4(rgb.gb, 0.0, -1.0 / 3.0);\n\
vec4 q = (rgb.r < p.x) ? vec4(p.xyw, rgb.r) : vec4(rgb.r, p.yzx);\n\
float c = q.x - min(q.w, q.y);\n\
float h = abs((q.w - q.y) / (6.0 * c + czm_epsilon7) + q.z);\n\
return vec3(h, c, q.x);\n\
}\n\
\n\
vec3 czm_RGBToHSL(vec3 rgb)\n\
{\n\
vec3 hcv = RGBtoHCV(rgb);\n\
float l = hcv.z - hcv.y * 0.5;\n\
float s = hcv.y / (1.0 - abs(l * 2.0 - 1.0) + czm_epsilon7);\n\
return vec3(hcv.x, s, l);\n\
}\n\
";
@@ -0,0 +1,30 @@
/**
* Converts an RGB color to CIE Yxy.
* <p>The conversion is described in
* {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform}
* </p>
*
* @name czm_RGBToXYZ
* @glslFunction
*
* @param {vec3} rgb The color in RGB.
*
* @returns {vec3} The color in CIE Yxy.
*
* @example
* vec3 xyz = czm_RGBToXYZ(rgb);
* xyz.x = max(xyz.x - luminanceThreshold, 0.0);
* rgb = czm_XYZToRGB(xyz);
*/
vec3 czm_RGBToXYZ(vec3 rgb)
{
const mat3 RGB2XYZ = mat3(0.4124, 0.2126, 0.0193,
0.3576, 0.7152, 0.1192,
0.1805, 0.0722, 0.9505);
vec3 xyz = RGB2XYZ * rgb;
vec3 Yxy;
Yxy.r = xyz.g;
float temp = dot(vec3(1.0), xyz);
Yxy.gb = xyz.rg / temp;
return Yxy;
}
@@ -0,0 +1,32 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts an RGB color to CIE Yxy.\n\
* <p>The conversion is described in\n\
* {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform}\n\
* </p>\n\
* \n\
* @name czm_RGBToXYZ\n\
* @glslFunction\n\
* \n\
* @param {vec3} rgb The color in RGB.\n\
*\n\
* @returns {vec3} The color in CIE Yxy.\n\
*\n\
* @example\n\
* vec3 xyz = czm_RGBToXYZ(rgb);\n\
* xyz.x = max(xyz.x - luminanceThreshold, 0.0);\n\
* rgb = czm_XYZToRGB(xyz);\n\
*/\n\
vec3 czm_RGBToXYZ(vec3 rgb)\n\
{\n\
const mat3 RGB2XYZ = mat3(0.4124, 0.2126, 0.0193,\n\
0.3576, 0.7152, 0.1192,\n\
0.1805, 0.0722, 0.9505);\n\
vec3 xyz = RGB2XYZ * rgb;\n\
vec3 Yxy;\n\
Yxy.r = xyz.g;\n\
float temp = dot(vec3(1.0), xyz);\n\
Yxy.gb = xyz.rg / temp;\n\
return Yxy;\n\
}\n\
";
@@ -0,0 +1,30 @@
/**
* Converts a CIE Yxy color to RGB.
* <p>The conversion is described in
* {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform}
* </p>
*
* @name czm_XYZToRGB
* @glslFunction
*
* @param {vec3} Yxy The color in CIE Yxy.
*
* @returns {vec3} The color in RGB.
*
* @example
* vec3 xyz = czm_RGBToXYZ(rgb);
* xyz.x = max(xyz.x - luminanceThreshold, 0.0);
* rgb = czm_XYZToRGB(xyz);
*/
vec3 czm_XYZToRGB(vec3 Yxy)
{
const mat3 XYZ2RGB = mat3( 3.2405, -0.9693, 0.0556,
-1.5371, 1.8760, -0.2040,
-0.4985, 0.0416, 1.0572);
vec3 xyz;
xyz.r = Yxy.r * Yxy.g / Yxy.b;
xyz.g = Yxy.r;
xyz.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b;
return XYZ2RGB * xyz;
}
@@ -0,0 +1,32 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts a CIE Yxy color to RGB.\n\
* <p>The conversion is described in\n\
* {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform}\n\
* </p>\n\
* \n\
* @name czm_XYZToRGB\n\
* @glslFunction\n\
* \n\
* @param {vec3} Yxy The color in CIE Yxy.\n\
*\n\
* @returns {vec3} The color in RGB.\n\
*\n\
* @example\n\
* vec3 xyz = czm_RGBToXYZ(rgb);\n\
* xyz.x = max(xyz.x - luminanceThreshold, 0.0);\n\
* rgb = czm_XYZToRGB(xyz);\n\
*/\n\
vec3 czm_XYZToRGB(vec3 Yxy)\n\
{\n\
const mat3 XYZ2RGB = mat3( 3.2405, -0.9693, 0.0556,\n\
-1.5371, 1.8760, -0.2040,\n\
-0.4985, 0.0416, 1.0572);\n\
vec3 xyz;\n\
xyz.r = Yxy.r * Yxy.g / Yxy.b;\n\
xyz.g = Yxy.r;\n\
xyz.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b;\n\
\n\
return XYZ2RGB * xyz;\n\
}\n\
";
@@ -0,0 +1,16 @@
// See:
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
vec3 czm_acesTonemapping(vec3 color) {
float g = 0.985;
float a = 0.065;
float b = 0.0001;
float c = 0.433;
float d = 0.238;
color = (color * (color + a) - b) / (color * (g * color + c) + d);
color = clamp(color, 0.0, 1.0);
return color;
}
@@ -0,0 +1,18 @@
//This file is automatically rebuilt by the Cesium build process.
export default "// See:\n\
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/\n\
\n\
vec3 czm_acesTonemapping(vec3 color) {\n\
float g = 0.985;\n\
float a = 0.065;\n\
float b = 0.0001;\n\
float c = 0.433;\n\
float d = 0.238;\n\
\n\
color = (color * (color + a) - b) / (color * (g * color + c) + d);\n\
\n\
color = clamp(color, 0.0, 1.0);\n\
\n\
return color;\n\
}\n\
";
@@ -0,0 +1,11 @@
/**
* @private
*/
float czm_alphaWeight(float a)
{
float z = (gl_FragCoord.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];
// See Weighted Blended Order-Independent Transparency for examples of different weighting functions:
// http://jcgt.org/published/0002/02/09/
return pow(a + 0.01, 4.0) + max(1e-2, min(3.0 * 1e3, 0.003 / (1e-5 + pow(abs(z) / 200.0, 4.0))));
}
@@ -0,0 +1,13 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* @private\n\
*/\n\
float czm_alphaWeight(float a)\n\
{\n\
float z = (gl_FragCoord.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];\n\
\n\
// See Weighted Blended Order-Independent Transparency for examples of different weighting functions:\n\
// http://jcgt.org/published/0002/02/09/\n\
return pow(a + 0.01, 4.0) + max(1e-2, min(3.0 * 1e3, 0.003 / (1e-5 + pow(abs(z) / 200.0, 4.0))));\n\
}\n\
";
@@ -0,0 +1,39 @@
/**
* Procedural anti-aliasing by blurring two colors that meet at a sharp edge.
*
* @name czm_antialias
* @glslFunction
*
* @param {vec4} color1 The color on one side of the edge.
* @param {vec4} color2 The color on the other side of the edge.
* @param {vec4} currentcolor The current color, either <code>color1</code> or <code>color2</code>.
* @param {float} dist The distance to the edge in texture coordinates.
* @param {float} [fuzzFactor=0.1] Controls the blurriness between the two colors.
* @returns {vec4} The anti-aliased color.
*
* @example
* // GLSL declarations
* vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor);
* vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist);
*
* // get the color for a material that has a sharp edge at the line y = 0.5 in texture space
* float dist = abs(textureCoordinates.t - 0.5);
* vec4 currentColor = mix(bottomColor, topColor, step(0.5, textureCoordinates.t));
* vec4 color = czm_antialias(bottomColor, topColor, currentColor, dist, 0.1);
*/
vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor)
{
float val1 = clamp(dist / fuzzFactor, 0.0, 1.0);
float val2 = clamp((dist - 0.5) / fuzzFactor, 0.0, 1.0);
val1 = val1 * (1.0 - val2);
val1 = val1 * val1 * (3.0 - (2.0 * val1));
val1 = pow(val1, 0.5); //makes the transition nicer
vec4 midColor = (color1 + color2) * 0.5;
return mix(midColor, currentColor, val1);
}
vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist)
{
return czm_antialias(color1, color2, currentColor, dist, 0.1);
}
@@ -0,0 +1,41 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Procedural anti-aliasing by blurring two colors that meet at a sharp edge.\n\
*\n\
* @name czm_antialias\n\
* @glslFunction\n\
*\n\
* @param {vec4} color1 The color on one side of the edge.\n\
* @param {vec4} color2 The color on the other side of the edge.\n\
* @param {vec4} currentcolor The current color, either <code>color1</code> or <code>color2</code>.\n\
* @param {float} dist The distance to the edge in texture coordinates.\n\
* @param {float} [fuzzFactor=0.1] Controls the blurriness between the two colors.\n\
* @returns {vec4} The anti-aliased color.\n\
*\n\
* @example\n\
* // GLSL declarations\n\
* vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor);\n\
* vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist);\n\
*\n\
* // get the color for a material that has a sharp edge at the line y = 0.5 in texture space\n\
* float dist = abs(textureCoordinates.t - 0.5);\n\
* vec4 currentColor = mix(bottomColor, topColor, step(0.5, textureCoordinates.t));\n\
* vec4 color = czm_antialias(bottomColor, topColor, currentColor, dist, 0.1);\n\
*/\n\
vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor)\n\
{\n\
float val1 = clamp(dist / fuzzFactor, 0.0, 1.0);\n\
float val2 = clamp((dist - 0.5) / fuzzFactor, 0.0, 1.0);\n\
val1 = val1 * (1.0 - val2);\n\
val1 = val1 * val1 * (3.0 - (2.0 * val1));\n\
val1 = pow(val1, 0.5); //makes the transition nicer\n\
\n\
vec4 midColor = (color1 + color2) * 0.5;\n\
return mix(midColor, currentColor, val1);\n\
}\n\
\n\
vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist)\n\
{\n\
return czm_antialias(color1, color2, currentColor, dist, 0.1);\n\
}\n\
";
@@ -0,0 +1,32 @@
/**
* Apply a HSB color shift to an RGB color.
*
* @param {vec3} rgb The color in RGB space.
* @param {vec3} hsbShift The amount to shift each component. The xyz components correspond to hue, saturation, and brightness. Shifting the hue by +/- 1.0 corresponds to shifting the hue by a full cycle. Saturation and brightness are clamped between 0 and 1 after the adjustment
* @param {bool} ignoreBlackPixels If true, black pixels will be unchanged. This is necessary in some shaders such as atmosphere-related effects.
*
* @return {vec3} The RGB color after shifting in HSB space and clamping saturation and brightness to a valid range.
*/
vec3 czm_applyHSBShift(vec3 rgb, vec3 hsbShift, bool ignoreBlackPixels) {
// Convert rgb color to hsb
vec3 hsb = czm_RGBToHSB(rgb);
// Perform hsb shift
// Hue cycles around so no clamp is needed.
hsb.x += hsbShift.x; // hue
hsb.y = clamp(hsb.y + hsbShift.y, 0.0, 1.0); // saturation
// brightness
//
// Some shaders such as atmosphere-related effects need to leave black
// pixels unchanged
if (ignoreBlackPixels) {
hsb.z = hsb.z > czm_epsilon7 ? hsb.z + hsbShift.z : 0.0;
} else {
hsb.z = hsb.z + hsbShift.z;
}
hsb.z = clamp(hsb.z, 0.0, 1.0);
// Convert shifted hsb back to rgb
return czm_HSBToRGB(hsb);
}
@@ -0,0 +1,34 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Apply a HSB color shift to an RGB color.\n\
*\n\
* @param {vec3} rgb The color in RGB space.\n\
* @param {vec3} hsbShift The amount to shift each component. The xyz components correspond to hue, saturation, and brightness. Shifting the hue by +/- 1.0 corresponds to shifting the hue by a full cycle. Saturation and brightness are clamped between 0 and 1 after the adjustment\n\
* @param {bool} ignoreBlackPixels If true, black pixels will be unchanged. This is necessary in some shaders such as atmosphere-related effects.\n\
*\n\
* @return {vec3} The RGB color after shifting in HSB space and clamping saturation and brightness to a valid range.\n\
*/\n\
vec3 czm_applyHSBShift(vec3 rgb, vec3 hsbShift, bool ignoreBlackPixels) {\n\
// Convert rgb color to hsb\n\
vec3 hsb = czm_RGBToHSB(rgb);\n\
\n\
// Perform hsb shift\n\
// Hue cycles around so no clamp is needed.\n\
hsb.x += hsbShift.x; // hue\n\
hsb.y = clamp(hsb.y + hsbShift.y, 0.0, 1.0); // saturation\n\
\n\
// brightness\n\
//\n\
// Some shaders such as atmosphere-related effects need to leave black\n\
// pixels unchanged\n\
if (ignoreBlackPixels) {\n\
hsb.z = hsb.z > czm_epsilon7 ? hsb.z + hsbShift.z : 0.0;\n\
} else {\n\
hsb.z = hsb.z + hsbShift.z;\n\
}\n\
hsb.z = clamp(hsb.z, 0.0, 1.0);\n\
\n\
// Convert shifted hsb back to rgb\n\
return czm_HSBToRGB(hsb);\n\
}\n\
";
@@ -0,0 +1,18 @@
/**
* Approximately computes spherical coordinates given a normal.
* Uses approximate inverse trigonometry for speed and consistency,
* since inverse trigonometry can differ from vendor-to-vendor and when compared with the CPU.
*
* @name czm_approximateSphericalCoordinates
* @glslFunction
*
* @param {vec3} normal arbitrary-length normal.
*
* @returns {vec2} Approximate latitude and longitude spherical coordinates.
*/
vec2 czm_approximateSphericalCoordinates(vec3 normal) {
// Project into plane with vertical for latitude
float latitudeApproximation = czm_fastApproximateAtan(sqrt(normal.x * normal.x + normal.y * normal.y), normal.z);
float longitudeApproximation = czm_fastApproximateAtan(normal.x, normal.y);
return vec2(latitudeApproximation, longitudeApproximation);
}
@@ -0,0 +1,20 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Approximately computes spherical coordinates given a normal.\n\
* Uses approximate inverse trigonometry for speed and consistency,\n\
* since inverse trigonometry can differ from vendor-to-vendor and when compared with the CPU.\n\
*\n\
* @name czm_approximateSphericalCoordinates\n\
* @glslFunction\n\
*\n\
* @param {vec3} normal arbitrary-length normal.\n\
*\n\
* @returns {vec2} Approximate latitude and longitude spherical coordinates.\n\
*/\n\
vec2 czm_approximateSphericalCoordinates(vec3 normal) {\n\
// Project into plane with vertical for latitude\n\
float latitudeApproximation = czm_fastApproximateAtan(sqrt(normal.x * normal.x + normal.y * normal.y), normal.z);\n\
float longitudeApproximation = czm_fastApproximateAtan(normal.x, normal.y);\n\
return vec2(latitudeApproximation, longitudeApproximation);\n\
}\n\
";
@@ -0,0 +1,10 @@
/**
* Compute a rational approximation to tanh(x)
*
* @param {float} x A real number input
* @returns {float} An approximation for tanh(x)
*/
float czm_approximateTanh(float x) {
float x2 = x * x;
return max(-1.0, min(1.0, x * (27.0 + x2) / (27.0 + 9.0 * x2)));
}
@@ -0,0 +1,12 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Compute a rational approximation to tanh(x)\n\
*\n\
* @param {float} x A real number input\n\
* @returns {float} An approximation for tanh(x)\n\
*/\n\
float czm_approximateTanh(float x) {\n\
float x2 = x * x;\n\
return max(-1.0, min(1.0, x * (27.0 + x2) / (27.0 + 9.0 * x2)));\n\
}\n\
";
@@ -0,0 +1,13 @@
/**
* Determines if the fragment is back facing
*
* @name czm_backFacing
* @glslFunction
*
* @returns {bool} <code>true</code> if the fragment is back facing; otherwise, <code>false</code>.
*/
bool czm_backFacing()
{
// !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.
return gl_FrontFacing == false;
}
@@ -0,0 +1,15 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Determines if the fragment is back facing\n\
*\n\
* @name czm_backFacing\n\
* @glslFunction \n\
* \n\
* @returns {bool} <code>true</code> if the fragment is back facing; otherwise, <code>false</code>.\n\
*/\n\
bool czm_backFacing()\n\
{\n\
// !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.\n\
return gl_FrontFacing == false;\n\
}\n\
";
@@ -0,0 +1,71 @@
/**
* Branchless ternary operator to be used when it's inexpensive to explicitly
* evaluate both possibilities for a float expression.
*
* @name czm_branchFreeTernary
* @glslFunction
*
* @param {bool} comparison A comparison statement
* @param {float} a Value to return if the comparison is true.
* @param {float} b Value to return if the comparison is false.
*
* @returns {float} equivalent of comparison ? a : b
*/
float czm_branchFreeTernary(bool comparison, float a, float b) {
float useA = float(comparison);
return a * useA + b * (1.0 - useA);
}
/**
* Branchless ternary operator to be used when it's inexpensive to explicitly
* evaluate both possibilities for a vec2 expression.
*
* @name czm_branchFreeTernary
* @glslFunction
*
* @param {bool} comparison A comparison statement
* @param {vec2} a Value to return if the comparison is true.
* @param {vec2} b Value to return if the comparison is false.
*
* @returns {vec2} equivalent of comparison ? a : b
*/
vec2 czm_branchFreeTernary(bool comparison, vec2 a, vec2 b) {
float useA = float(comparison);
return a * useA + b * (1.0 - useA);
}
/**
* Branchless ternary operator to be used when it's inexpensive to explicitly
* evaluate both possibilities for a vec3 expression.
*
* @name czm_branchFreeTernary
* @glslFunction
*
* @param {bool} comparison A comparison statement
* @param {vec3} a Value to return if the comparison is true.
* @param {vec3} b Value to return if the comparison is false.
*
* @returns {vec3} equivalent of comparison ? a : b
*/
vec3 czm_branchFreeTernary(bool comparison, vec3 a, vec3 b) {
float useA = float(comparison);
return a * useA + b * (1.0 - useA);
}
/**
* Branchless ternary operator to be used when it's inexpensive to explicitly
* evaluate both possibilities for a vec4 expression.
*
* @name czm_branchFreeTernary
* @glslFunction
*
* @param {bool} comparison A comparison statement
* @param {vec3} a Value to return if the comparison is true.
* @param {vec3} b Value to return if the comparison is false.
*
* @returns {vec3} equivalent of comparison ? a : b
*/
vec4 czm_branchFreeTernary(bool comparison, vec4 a, vec4 b) {
float useA = float(comparison);
return a * useA + b * (1.0 - useA);
}
@@ -0,0 +1,73 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Branchless ternary operator to be used when it's inexpensive to explicitly\n\
* evaluate both possibilities for a float expression.\n\
*\n\
* @name czm_branchFreeTernary\n\
* @glslFunction\n\
*\n\
* @param {bool} comparison A comparison statement\n\
* @param {float} a Value to return if the comparison is true.\n\
* @param {float} b Value to return if the comparison is false.\n\
*\n\
* @returns {float} equivalent of comparison ? a : b\n\
*/\n\
float czm_branchFreeTernary(bool comparison, float a, float b) {\n\
float useA = float(comparison);\n\
return a * useA + b * (1.0 - useA);\n\
}\n\
\n\
/**\n\
* Branchless ternary operator to be used when it's inexpensive to explicitly\n\
* evaluate both possibilities for a vec2 expression.\n\
*\n\
* @name czm_branchFreeTernary\n\
* @glslFunction\n\
*\n\
* @param {bool} comparison A comparison statement\n\
* @param {vec2} a Value to return if the comparison is true.\n\
* @param {vec2} b Value to return if the comparison is false.\n\
*\n\
* @returns {vec2} equivalent of comparison ? a : b\n\
*/\n\
vec2 czm_branchFreeTernary(bool comparison, vec2 a, vec2 b) {\n\
float useA = float(comparison);\n\
return a * useA + b * (1.0 - useA);\n\
}\n\
\n\
/**\n\
* Branchless ternary operator to be used when it's inexpensive to explicitly\n\
* evaluate both possibilities for a vec3 expression.\n\
*\n\
* @name czm_branchFreeTernary\n\
* @glslFunction\n\
*\n\
* @param {bool} comparison A comparison statement\n\
* @param {vec3} a Value to return if the comparison is true.\n\
* @param {vec3} b Value to return if the comparison is false.\n\
*\n\
* @returns {vec3} equivalent of comparison ? a : b\n\
*/\n\
vec3 czm_branchFreeTernary(bool comparison, vec3 a, vec3 b) {\n\
float useA = float(comparison);\n\
return a * useA + b * (1.0 - useA);\n\
}\n\
\n\
/**\n\
* Branchless ternary operator to be used when it's inexpensive to explicitly\n\
* evaluate both possibilities for a vec4 expression.\n\
*\n\
* @name czm_branchFreeTernary\n\
* @glslFunction\n\
*\n\
* @param {bool} comparison A comparison statement\n\
* @param {vec3} a Value to return if the comparison is true.\n\
* @param {vec3} b Value to return if the comparison is false.\n\
*\n\
* @returns {vec3} equivalent of comparison ? a : b\n\
*/\n\
vec4 czm_branchFreeTernary(bool comparison, vec4 a, vec4 b) {\n\
float useA = float(comparison);\n\
return a * useA + b * (1.0 - useA);\n\
}\n\
";
@@ -0,0 +1,8 @@
vec4 czm_cascadeColor(vec4 weights)
{
return vec4(1.0, 0.0, 0.0, 1.0) * weights.x +
vec4(0.0, 1.0, 0.0, 1.0) * weights.y +
vec4(0.0, 0.0, 1.0, 1.0) * weights.z +
vec4(1.0, 0.0, 1.0, 1.0) * weights.w;
}
@@ -0,0 +1,10 @@
//This file is automatically rebuilt by the Cesium build process.
export default "\n\
vec4 czm_cascadeColor(vec4 weights)\n\
{\n\
return vec4(1.0, 0.0, 0.0, 1.0) * weights.x +\n\
vec4(0.0, 1.0, 0.0, 1.0) * weights.y +\n\
vec4(0.0, 0.0, 1.0, 1.0) * weights.z +\n\
vec4(1.0, 0.0, 1.0, 1.0) * weights.w;\n\
}\n\
";
@@ -0,0 +1,7 @@
uniform vec4 shadowMap_cascadeDistances;
float czm_cascadeDistance(vec4 weights)
{
return dot(shadowMap_cascadeDistances, weights);
}
@@ -0,0 +1,9 @@
//This file is automatically rebuilt by the Cesium build process.
export default "\n\
uniform vec4 shadowMap_cascadeDistances;\n\
\n\
float czm_cascadeDistance(vec4 weights)\n\
{\n\
return dot(shadowMap_cascadeDistances, weights);\n\
}\n\
";
@@ -0,0 +1,10 @@
uniform mat4 shadowMap_cascadeMatrices[4];
mat4 czm_cascadeMatrix(vec4 weights)
{
return shadowMap_cascadeMatrices[0] * weights.x +
shadowMap_cascadeMatrices[1] * weights.y +
shadowMap_cascadeMatrices[2] * weights.z +
shadowMap_cascadeMatrices[3] * weights.w;
}
@@ -0,0 +1,12 @@
//This file is automatically rebuilt by the Cesium build process.
export default "\n\
uniform mat4 shadowMap_cascadeMatrices[4];\n\
\n\
mat4 czm_cascadeMatrix(vec4 weights)\n\
{\n\
return shadowMap_cascadeMatrices[0] * weights.x +\n\
shadowMap_cascadeMatrices[1] * weights.y +\n\
shadowMap_cascadeMatrices[2] * weights.z +\n\
shadowMap_cascadeMatrices[3] * weights.w;\n\
}\n\
";
@@ -0,0 +1,10 @@
uniform vec4 shadowMap_cascadeSplits[2];
vec4 czm_cascadeWeights(float depthEye)
{
// One component is set to 1.0 and all others set to 0.0.
vec4 near = step(shadowMap_cascadeSplits[0], vec4(depthEye));
vec4 far = step(depthEye, shadowMap_cascadeSplits[1]);
return near * far;
}
@@ -0,0 +1,12 @@
//This file is automatically rebuilt by the Cesium build process.
export default "\n\
uniform vec4 shadowMap_cascadeSplits[2];\n\
\n\
vec4 czm_cascadeWeights(float depthEye)\n\
{\n\
// One component is set to 1.0 and all others set to 0.0.\n\
vec4 near = step(shadowMap_cascadeSplits[0], vec4(depthEye));\n\
vec4 far = step(depthEye, shadowMap_cascadeSplits[1]);\n\
return near * far;\n\
}\n\
";
@@ -0,0 +1,37 @@
float getSignedDistance(vec2 uv, highp sampler2D clippingDistance) {
float signedDistance = texture(clippingDistance, uv).r;
return (signedDistance - 0.5) * 2.0;
}
void czm_clipPolygons(highp sampler2D clippingDistance, int extentsLength, vec2 clippingPosition, int regionIndex) {
// Position is completely outside of polygons bounds
vec2 rectUv = clippingPosition;
if (regionIndex < 0 || rectUv.x <= 0.0 || rectUv.y <= 0.0 || rectUv.x >= 1.0 || rectUv.y >= 1.0) {
#ifdef CLIPPING_INVERSE
discard;
#endif
return;
}
vec2 clippingDistanceTextureDimensions = vec2(textureSize(clippingDistance, 0));
vec2 sampleOffset = max(1.0 / clippingDistanceTextureDimensions, vec2(0.005));
float dimension = float(extentsLength);
if (extentsLength > 2) {
dimension = ceil(log2(float(extentsLength)));
}
vec2 textureOffset = vec2(mod(float(regionIndex), dimension), floor(float(regionIndex) / dimension)) / dimension;
vec2 uv = textureOffset + rectUv / dimension;
float signedDistance = getSignedDistance(uv, clippingDistance);
#ifdef CLIPPING_INVERSE
if (signedDistance > 0.0) {
discard;
}
#else
if (signedDistance < 0.0) {
discard;
}
#endif
}
@@ -0,0 +1,39 @@
//This file is automatically rebuilt by the Cesium build process.
export default "float getSignedDistance(vec2 uv, highp sampler2D clippingDistance) {\n\
float signedDistance = texture(clippingDistance, uv).r;\n\
return (signedDistance - 0.5) * 2.0;\n\
}\n\
\n\
void czm_clipPolygons(highp sampler2D clippingDistance, int extentsLength, vec2 clippingPosition, int regionIndex) {\n\
// Position is completely outside of polygons bounds\n\
vec2 rectUv = clippingPosition;\n\
if (regionIndex < 0 || rectUv.x <= 0.0 || rectUv.y <= 0.0 || rectUv.x >= 1.0 || rectUv.y >= 1.0) {\n\
#ifdef CLIPPING_INVERSE \n\
discard;\n\
#endif\n\
return;\n\
}\n\
\n\
vec2 clippingDistanceTextureDimensions = vec2(textureSize(clippingDistance, 0));\n\
vec2 sampleOffset = max(1.0 / clippingDistanceTextureDimensions, vec2(0.005));\n\
float dimension = float(extentsLength);\n\
if (extentsLength > 2) {\n\
dimension = ceil(log2(float(extentsLength)));\n\
}\n\
\n\
vec2 textureOffset = vec2(mod(float(regionIndex), dimension), floor(float(regionIndex) / dimension)) / dimension;\n\
vec2 uv = textureOffset + rectUv / dimension;\n\
\n\
float signedDistance = getSignedDistance(uv, clippingDistance);\n\
\n\
#ifdef CLIPPING_INVERSE\n\
if (signedDistance > 0.0) {\n\
discard;\n\
}\n\
#else\n\
if (signedDistance < 0.0) {\n\
discard;\n\
}\n\
#endif\n\
}\n\
";
@@ -0,0 +1,19 @@
/**
* DOC_TBA
*
* @name czm_columbusViewMorph
* @glslFunction
*/
vec4 czm_columbusViewMorph(vec4 position2D, vec4 position3D, float time)
{
// Just linear for now.
// We're manually doing the equivalent of a `mix` here because, some GPUs
// (NVidia GeForce 3070 Ti and Intel Arc A750, to name two), `mix` seems to
// use an alternate formulation that introduces jitter even when `time` is
// 0.0 or 1.0. That is, the value of `p` won't be exactly `position2D.xyz`
// when `time` is 0.0 and it won't be exactly `position3D.xyz` when `time` is
// 1.0. The "textbook" formulation here, while probably a bit slower,
// does not have this problem.
vec3 p = position2D.xyz * (1.0 - time) + position3D.xyz * time;
return vec4(p, 1.0);
}
@@ -0,0 +1,21 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* DOC_TBA\n\
*\n\
* @name czm_columbusViewMorph\n\
* @glslFunction\n\
*/\n\
vec4 czm_columbusViewMorph(vec4 position2D, vec4 position3D, float time)\n\
{\n\
// Just linear for now.\n\
// We're manually doing the equivalent of a `mix` here because, some GPUs\n\
// (NVidia GeForce 3070 Ti and Intel Arc A750, to name two), `mix` seems to\n\
// use an alternate formulation that introduces jitter even when `time` is\n\
// 0.0 or 1.0. That is, the value of `p` won't be exactly `position2D.xyz`\n\
// when `time` is 0.0 and it won't be exactly `position3D.xyz` when `time` is\n\
// 1.0. The \"textbook\" formulation here, while probably a bit slower,\n\
// does not have this problem.\n\
vec3 p = position2D.xyz * (1.0 - time) + position3D.xyz * time;\n\
return vec4(p, 1.0);\n\
}\n\
";
@@ -0,0 +1,88 @@
/**
* Compute the atmosphere color, applying Rayleigh and Mie scattering. This
* builtin uses automatic uniforms so the atmophere settings are synced with the
* state of the Scene, even in other contexts like Model.
*
* @name czm_computeAtmosphereColor
* @glslFunction
*
* @param {vec3} positionWC Position of the fragment in world coords (low precision)
* @param {vec3} lightDirection Light direction from the sun or other light source.
* @param {vec3} rayleighColor The Rayleigh scattering color computed by a scattering function
* @param {vec3} mieColor The Mie scattering color computed by a scattering function
* @param {float} opacity The opacity computed by a scattering function.
*/
vec4 czm_computeAtmosphereColor(
vec3 positionWC,
vec3 lightDirection,
vec3 rayleighColor,
vec3 mieColor,
float opacity
) {
// Setup the primary ray: from the camera position to the vertex position.
vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;
vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);
float cosAngle = dot(cameraToPositionWCDirection, lightDirection);
float cosAngleSq = cosAngle * cosAngle;
float G = czm_atmosphereMieAnisotropy;
float GSq = G * G;
// The Rayleigh phase function.
float rayleighPhase = 3.0 / (50.2654824574) * (1.0 + cosAngleSq);
// The Mie phase function.
float miePhase = 3.0 / (25.1327412287) * ((1.0 - GSq) * (cosAngleSq + 1.0)) / (pow(1.0 + GSq - 2.0 * cosAngle * G, 1.5) * (2.0 + GSq));
// The final color is generated by combining the effects of the Rayleigh and Mie scattering.
vec3 rayleigh = rayleighPhase * rayleighColor;
vec3 mie = miePhase * mieColor;
vec3 color = (rayleigh + mie) * czm_atmosphereLightIntensity;
return vec4(color, opacity);
}
/**
* Compute the atmosphere color, applying Rayleigh and Mie scattering. This
* builtin uses automatic uniforms so the atmophere settings are synced with the
* state of the Scene, even in other contexts like Model.
*
* @name czm_computeAtmosphereColor
* @glslFunction
*
* @param {czm_ray} primaryRay Ray from the origin to sky fragment to in world coords (low precision)
* @param {vec3} lightDirection Light direction from the sun or other light source.
* @param {vec3} rayleighColor The Rayleigh scattering color computed by a scattering function
* @param {vec3} mieColor The Mie scattering color computed by a scattering function
* @param {float} opacity The opacity computed by a scattering function.
*/
vec4 czm_computeAtmosphereColor(
czm_ray primaryRay,
vec3 lightDirection,
vec3 rayleighColor,
vec3 mieColor,
float opacity
) {
vec3 direction = normalize(primaryRay.direction);
float cosAngle = dot(direction, lightDirection);
float cosAngleSq = cosAngle * cosAngle;
float G = czm_atmosphereMieAnisotropy;
float GSq = G * G;
// The Rayleigh phase function.
float rayleighPhase = 3.0 / (50.2654824574) * (1.0 + cosAngleSq);
// The Mie phase function.
float miePhase = 3.0 / (25.1327412287) * ((1.0 - GSq) * (cosAngleSq + 1.0)) / (pow(1.0 + GSq - 2.0 * cosAngle * G, 1.5) * (2.0 + GSq));
// The final color is generated by combining the effects of the Rayleigh and Mie scattering.
vec3 rayleigh = rayleighPhase * rayleighColor;
vec3 mie = miePhase * mieColor;
vec3 color = (rayleigh + mie) * czm_atmosphereLightIntensity;
return vec4(color, opacity);
}
@@ -0,0 +1,90 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Compute the atmosphere color, applying Rayleigh and Mie scattering. This\n\
* builtin uses automatic uniforms so the atmophere settings are synced with the\n\
* state of the Scene, even in other contexts like Model.\n\
*\n\
* @name czm_computeAtmosphereColor\n\
* @glslFunction\n\
*\n\
* @param {vec3} positionWC Position of the fragment in world coords (low precision)\n\
* @param {vec3} lightDirection Light direction from the sun or other light source.\n\
* @param {vec3} rayleighColor The Rayleigh scattering color computed by a scattering function\n\
* @param {vec3} mieColor The Mie scattering color computed by a scattering function\n\
* @param {float} opacity The opacity computed by a scattering function.\n\
*/\n\
vec4 czm_computeAtmosphereColor(\n\
vec3 positionWC,\n\
vec3 lightDirection,\n\
vec3 rayleighColor,\n\
vec3 mieColor,\n\
float opacity\n\
) {\n\
// Setup the primary ray: from the camera position to the vertex position.\n\
vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;\n\
vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);\n\
\n\
float cosAngle = dot(cameraToPositionWCDirection, lightDirection);\n\
float cosAngleSq = cosAngle * cosAngle;\n\
\n\
float G = czm_atmosphereMieAnisotropy;\n\
float GSq = G * G;\n\
\n\
// The Rayleigh phase function.\n\
float rayleighPhase = 3.0 / (50.2654824574) * (1.0 + cosAngleSq);\n\
// The Mie phase function.\n\
float miePhase = 3.0 / (25.1327412287) * ((1.0 - GSq) * (cosAngleSq + 1.0)) / (pow(1.0 + GSq - 2.0 * cosAngle * G, 1.5) * (2.0 + GSq));\n\
\n\
// The final color is generated by combining the effects of the Rayleigh and Mie scattering.\n\
vec3 rayleigh = rayleighPhase * rayleighColor;\n\
vec3 mie = miePhase * mieColor;\n\
\n\
vec3 color = (rayleigh + mie) * czm_atmosphereLightIntensity;\n\
\n\
return vec4(color, opacity);\n\
}\n\
\n\
/**\n\
* Compute the atmosphere color, applying Rayleigh and Mie scattering. This\n\
* builtin uses automatic uniforms so the atmophere settings are synced with the\n\
* state of the Scene, even in other contexts like Model.\n\
*\n\
* @name czm_computeAtmosphereColor\n\
* @glslFunction\n\
*\n\
* @param {czm_ray} primaryRay Ray from the origin to sky fragment to in world coords (low precision)\n\
* @param {vec3} lightDirection Light direction from the sun or other light source.\n\
* @param {vec3} rayleighColor The Rayleigh scattering color computed by a scattering function\n\
* @param {vec3} mieColor The Mie scattering color computed by a scattering function\n\
* @param {float} opacity The opacity computed by a scattering function.\n\
*/\n\
vec4 czm_computeAtmosphereColor(\n\
czm_ray primaryRay,\n\
vec3 lightDirection,\n\
vec3 rayleighColor,\n\
vec3 mieColor,\n\
float opacity\n\
) {\n\
vec3 direction = normalize(primaryRay.direction);\n\
\n\
float cosAngle = dot(direction, lightDirection);\n\
float cosAngleSq = cosAngle * cosAngle;\n\
\n\
float G = czm_atmosphereMieAnisotropy;\n\
float GSq = G * G;\n\
\n\
// The Rayleigh phase function.\n\
float rayleighPhase = 3.0 / (50.2654824574) * (1.0 + cosAngleSq);\n\
// The Mie phase function.\n\
float miePhase = 3.0 / (25.1327412287) * ((1.0 - GSq) * (cosAngleSq + 1.0)) / (pow(1.0 + GSq - 2.0 * cosAngle * G, 1.5) * (2.0 + GSq));\n\
\n\
// The final color is generated by combining the effects of the Rayleigh and Mie scattering.\n\
vec3 rayleigh = rayleighPhase * rayleighColor;\n\
vec3 mie = miePhase * mieColor;\n\
\n\
vec3 color = (rayleigh + mie) * czm_atmosphereLightIntensity;\n\
\n\
return vec4(color, opacity);\n\
}\n\
\n\
";
@@ -0,0 +1,30 @@
/**
* Compute atmosphere scattering for the ground atmosphere and fog. This method
* uses automatic uniforms so it is always synced with the scene settings.
*
* @name czm_computeGroundAtmosphereScattering
* @glslfunction
*
* @param {vec3} positionWC The position of the fragment in world coordinates.
* @param {vec3} lightDirection The direction of the light to calculate the scattering from.
* @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.
* @param {vec3} mieColor The variable the Mie scattering will be written to.
* @param {float} opacity The variable the transmittance will be written to.
*/
void czm_computeGroundAtmosphereScattering(vec3 positionWC, vec3 lightDirection, out vec3 rayleighColor, out vec3 mieColor, out float opacity) {
vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;
vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);
czm_ray primaryRay = czm_ray(czm_viewerPositionWC, cameraToPositionWCDirection);
float atmosphereInnerRadius = length(positionWC);
czm_computeScattering(
primaryRay,
length(cameraToPositionWC),
lightDirection,
atmosphereInnerRadius,
rayleighColor,
mieColor,
opacity
);
}
@@ -0,0 +1,32 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Compute atmosphere scattering for the ground atmosphere and fog. This method\n\
* uses automatic uniforms so it is always synced with the scene settings.\n\
*\n\
* @name czm_computeGroundAtmosphereScattering\n\
* @glslfunction\n\
*\n\
* @param {vec3} positionWC The position of the fragment in world coordinates.\n\
* @param {vec3} lightDirection The direction of the light to calculate the scattering from.\n\
* @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.\n\
* @param {vec3} mieColor The variable the Mie scattering will be written to.\n\
* @param {float} opacity The variable the transmittance will be written to.\n\
*/\n\
void czm_computeGroundAtmosphereScattering(vec3 positionWC, vec3 lightDirection, out vec3 rayleighColor, out vec3 mieColor, out float opacity) {\n\
vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;\n\
vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);\n\
czm_ray primaryRay = czm_ray(czm_viewerPositionWC, cameraToPositionWCDirection);\n\
\n\
float atmosphereInnerRadius = length(positionWC);\n\
\n\
czm_computeScattering(\n\
primaryRay,\n\
length(cameraToPositionWC),\n\
lightDirection,\n\
atmosphereInnerRadius,\n\
rayleighColor,\n\
mieColor,\n\
opacity\n\
);\n\
}\n\
";
@@ -0,0 +1,22 @@
/**
* Returns a position in model coordinates relative to eye taking into
* account the current scene mode: 3D, 2D, or Columbus view.
* <p>
* This uses standard position attributes, <code>position3DHigh</code>,
* <code>position3DLow</code>, <code>position2DHigh</code>, and <code>position2DLow</code>,
* and should be used when writing a vertex shader for an {@link Appearance}.
* </p>
*
* @name czm_computePosition
* @glslFunction
*
* @returns {vec4} The position relative to eye.
*
* @example
* vec4 p = czm_computePosition();
* v_positionEC = (czm_modelViewRelativeToEye * p).xyz;
* gl_Position = czm_modelViewProjectionRelativeToEye * p;
*
* @see czm_translateRelativeToEye
*/
vec4 czm_computePosition();
@@ -0,0 +1,24 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Returns a position in model coordinates relative to eye taking into\n\
* account the current scene mode: 3D, 2D, or Columbus view.\n\
* <p>\n\
* This uses standard position attributes, <code>position3DHigh</code>, \n\
* <code>position3DLow</code>, <code>position2DHigh</code>, and <code>position2DLow</code>, \n\
* and should be used when writing a vertex shader for an {@link Appearance}.\n\
* </p>\n\
*\n\
* @name czm_computePosition\n\
* @glslFunction\n\
*\n\
* @returns {vec4} The position relative to eye.\n\
*\n\
* @example\n\
* vec4 p = czm_computePosition();\n\
* v_positionEC = (czm_modelViewRelativeToEye * p).xyz;\n\
* gl_Position = czm_modelViewProjectionRelativeToEye * p;\n\
*\n\
* @see czm_translateRelativeToEye\n\
*/\n\
vec4 czm_computePosition();\n\
";
@@ -0,0 +1,149 @@
/**
* This function computes the colors contributed by Rayliegh and Mie scattering on a given ray, as well as
* the transmittance value for the ray. This function uses automatic uniforms
* so the atmosphere settings are always synced with the current scene.
*
* @name czm_computeScattering
* @glslfunction
*
* @param {czm_ray} primaryRay The ray from the camera to the position.
* @param {float} primaryRayLength The length of the primary ray.
* @param {vec3} lightDirection The direction of the light to calculate the scattering from.
* @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.
* @param {vec3} mieColor The variable the Mie scattering will be written to.
* @param {float} opacity The variable the transmittance will be written to.
*/
void czm_computeScattering(
czm_ray primaryRay,
float primaryRayLength,
vec3 lightDirection,
float atmosphereInnerRadius,
out vec3 rayleighColor,
out vec3 mieColor,
out float opacity
) {
const float ATMOSPHERE_THICKNESS = 111e3; // The thickness of the atmosphere in meters.
const int PRIMARY_STEPS_MAX = 16; // Maximum number of times the ray from the camera to the world position (primary ray) is sampled.
const int LIGHT_STEPS_MAX = 4; // Maximum number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.
// Initialize the default scattering amounts to 0.
rayleighColor = vec3(0.0);
mieColor = vec3(0.0);
opacity = 0.0;
float atmosphereOuterRadius = atmosphereInnerRadius + ATMOSPHERE_THICKNESS;
vec3 origin = vec3(0.0);
// Calculate intersection from the camera to the outer ring of the atmosphere.
czm_raySegment primaryRayAtmosphereIntersect = czm_raySphereIntersectionInterval(primaryRay, origin, atmosphereOuterRadius);
// Return empty colors if no intersection with the atmosphere geometry.
if (primaryRayAtmosphereIntersect == czm_emptyRaySegment) {
return;
}
// To deal with smaller values of PRIMARY_STEPS (e.g. 4)
// we implement a split strategy: sky or horizon.
// For performance reasons, instead of a if/else branch
// a soft choice is implemented through a weight 0.0 <= w_stop_gt_lprl <= 1.0
float x = 1e-7 * primaryRayAtmosphereIntersect.stop / length(primaryRayLength);
// Value close to 0.0: close to the horizon
// Value close to 1.0: above in the sky
float w_stop_gt_lprl = 0.5 * (1.0 + czm_approximateTanh(x));
// The ray should start from the first intersection with the outer atmopshere, or from the camera position, if it is inside the atmosphere.
float start_0 = primaryRayAtmosphereIntersect.start;
primaryRayAtmosphereIntersect.start = max(primaryRayAtmosphereIntersect.start, 0.0);
// The ray should end at the exit from the atmosphere or at the distance to the vertex, whichever is smaller.
primaryRayAtmosphereIntersect.stop = min(primaryRayAtmosphereIntersect.stop, length(primaryRayLength));
// For the number of ray steps, distinguish inside or outside atmosphere (outer space)
// (1) from outer space we have to use more ray steps to get a realistic rendering
// (2) within atmosphere we need fewer steps for faster rendering
float x_o_a = start_0 - ATMOSPHERE_THICKNESS; // ATMOSPHERE_THICKNESS used as an ad-hoc constant, no precise meaning here, only the order of magnitude matters
float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + czm_approximateTanh(x_o_a));
int PRIMARY_STEPS = PRIMARY_STEPS_MAX - int(w_inside_atmosphere * 12.0); // Number of times the ray from the camera to the world position (primary ray) is sampled.
int LIGHT_STEPS = LIGHT_STEPS_MAX - int(w_inside_atmosphere * 2.0); // Number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.
// Setup for sampling positions along the ray - starting from the intersection with the outer ring of the atmosphere.
float rayPositionLength = primaryRayAtmosphereIntersect.start;
// (1) Outside the atmosphere: constant rayStepLength
// (2) Inside atmosphere: variable rayStepLength to compensate the rough rendering of the smaller number of ray steps
float totalRayLength = primaryRayAtmosphereIntersect.stop - rayPositionLength;
float rayStepLengthIncrease = w_inside_atmosphere * ((1.0 - w_stop_gt_lprl) * totalRayLength / (float(PRIMARY_STEPS * (PRIMARY_STEPS + 1)) / 2.0));
float rayStepLength = max(1.0 - w_inside_atmosphere, w_stop_gt_lprl) * totalRayLength / max(7.0 * w_inside_atmosphere, float(PRIMARY_STEPS));
vec3 rayleighAccumulation = vec3(0.0);
vec3 mieAccumulation = vec3(0.0);
vec2 opticalDepth = vec2(0.0);
vec2 heightScale = vec2(czm_atmosphereRayleighScaleHeight, czm_atmosphereMieScaleHeight);
// Sample positions on the primary ray.
for (int i = 0; i < PRIMARY_STEPS_MAX; ++i) {
// The loop should be: for (int i = 0; i < PRIMARY_STEPS; ++i) {...} but WebGL1 cannot
// loop with non-constant condition, so it has to break early instead
if (i >= PRIMARY_STEPS) {
break;
}
// Calculate sample position along viewpoint ray.
vec3 samplePosition = primaryRay.origin + primaryRay.direction * (rayPositionLength + rayStepLength);
// Calculate height of sample position above ellipsoid.
float sampleHeight = length(samplePosition) - atmosphereInnerRadius;
// Calculate and accumulate density of particles at the sample position.
vec2 sampleDensity = exp(-sampleHeight / heightScale) * rayStepLength;
opticalDepth += sampleDensity;
// Generate ray from the sample position segment to the light source, up to the outer ring of the atmosphere.
czm_ray lightRay = czm_ray(samplePosition, lightDirection);
czm_raySegment lightRayAtmosphereIntersect = czm_raySphereIntersectionInterval(lightRay, origin, atmosphereOuterRadius);
float lightStepLength = lightRayAtmosphereIntersect.stop / float(LIGHT_STEPS);
float lightPositionLength = 0.0;
vec2 lightOpticalDepth = vec2(0.0);
// Sample positions along the light ray, to accumulate incidence of light on the latest sample segment.
for (int j = 0; j < LIGHT_STEPS_MAX; ++j) {
// The loop should be: for (int j = 0; i < LIGHT_STEPS; ++j) {...} but WebGL1 cannot
// loop with non-constant condition, so it has to break early instead
if (j >= LIGHT_STEPS) {
break;
}
// Calculate sample position along light ray.
vec3 lightPosition = samplePosition + lightDirection * (lightPositionLength + lightStepLength * 0.5);
// Calculate height of the light sample position above ellipsoid.
float lightHeight = length(lightPosition) - atmosphereInnerRadius;
// Calculate density of photons at the light sample position.
lightOpticalDepth += exp(-lightHeight / heightScale) * lightStepLength;
// Increment distance on light ray.
lightPositionLength += lightStepLength;
}
// Compute attenuation via the primary ray and the light ray.
vec3 attenuation = exp(-((czm_atmosphereMieCoefficient * (opticalDepth.y + lightOpticalDepth.y)) + (czm_atmosphereRayleighCoefficient * (opticalDepth.x + lightOpticalDepth.x))));
// Accumulate the scattering.
rayleighAccumulation += sampleDensity.x * attenuation;
mieAccumulation += sampleDensity.y * attenuation;
// Increment distance on primary ray.
rayPositionLength += (rayStepLength += rayStepLengthIncrease);
}
// Compute the scattering amount.
rayleighColor = czm_atmosphereRayleighCoefficient * rayleighAccumulation;
mieColor = czm_atmosphereMieCoefficient * mieAccumulation;
// Compute the transmittance i.e. how much light is passing through the atmosphere.
opacity = length(exp(-((czm_atmosphereMieCoefficient * opticalDepth.y) + (czm_atmosphereRayleighCoefficient * opticalDepth.x))));
}
@@ -0,0 +1,151 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* This function computes the colors contributed by Rayliegh and Mie scattering on a given ray, as well as\n\
* the transmittance value for the ray. This function uses automatic uniforms\n\
* so the atmosphere settings are always synced with the current scene.\n\
*\n\
* @name czm_computeScattering\n\
* @glslfunction\n\
*\n\
* @param {czm_ray} primaryRay The ray from the camera to the position.\n\
* @param {float} primaryRayLength The length of the primary ray.\n\
* @param {vec3} lightDirection The direction of the light to calculate the scattering from.\n\
* @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.\n\
* @param {vec3} mieColor The variable the Mie scattering will be written to.\n\
* @param {float} opacity The variable the transmittance will be written to.\n\
*/\n\
void czm_computeScattering(\n\
czm_ray primaryRay,\n\
float primaryRayLength,\n\
vec3 lightDirection,\n\
float atmosphereInnerRadius,\n\
out vec3 rayleighColor,\n\
out vec3 mieColor,\n\
out float opacity\n\
) {\n\
const float ATMOSPHERE_THICKNESS = 111e3; // The thickness of the atmosphere in meters.\n\
const int PRIMARY_STEPS_MAX = 16; // Maximum number of times the ray from the camera to the world position (primary ray) is sampled.\n\
const int LIGHT_STEPS_MAX = 4; // Maximum number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.\n\
\n\
// Initialize the default scattering amounts to 0.\n\
rayleighColor = vec3(0.0);\n\
mieColor = vec3(0.0);\n\
opacity = 0.0;\n\
\n\
float atmosphereOuterRadius = atmosphereInnerRadius + ATMOSPHERE_THICKNESS;\n\
\n\
vec3 origin = vec3(0.0);\n\
\n\
// Calculate intersection from the camera to the outer ring of the atmosphere.\n\
czm_raySegment primaryRayAtmosphereIntersect = czm_raySphereIntersectionInterval(primaryRay, origin, atmosphereOuterRadius);\n\
\n\
// Return empty colors if no intersection with the atmosphere geometry.\n\
if (primaryRayAtmosphereIntersect == czm_emptyRaySegment) {\n\
return;\n\
}\n\
\n\
// To deal with smaller values of PRIMARY_STEPS (e.g. 4)\n\
// we implement a split strategy: sky or horizon.\n\
// For performance reasons, instead of a if/else branch\n\
// a soft choice is implemented through a weight 0.0 <= w_stop_gt_lprl <= 1.0\n\
float x = 1e-7 * primaryRayAtmosphereIntersect.stop / length(primaryRayLength);\n\
// Value close to 0.0: close to the horizon\n\
// Value close to 1.0: above in the sky\n\
float w_stop_gt_lprl = 0.5 * (1.0 + czm_approximateTanh(x));\n\
\n\
// The ray should start from the first intersection with the outer atmopshere, or from the camera position, if it is inside the atmosphere.\n\
float start_0 = primaryRayAtmosphereIntersect.start;\n\
primaryRayAtmosphereIntersect.start = max(primaryRayAtmosphereIntersect.start, 0.0);\n\
// The ray should end at the exit from the atmosphere or at the distance to the vertex, whichever is smaller.\n\
primaryRayAtmosphereIntersect.stop = min(primaryRayAtmosphereIntersect.stop, length(primaryRayLength));\n\
\n\
// For the number of ray steps, distinguish inside or outside atmosphere (outer space)\n\
// (1) from outer space we have to use more ray steps to get a realistic rendering\n\
// (2) within atmosphere we need fewer steps for faster rendering\n\
float x_o_a = start_0 - ATMOSPHERE_THICKNESS; // ATMOSPHERE_THICKNESS used as an ad-hoc constant, no precise meaning here, only the order of magnitude matters\n\
float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + czm_approximateTanh(x_o_a));\n\
int PRIMARY_STEPS = PRIMARY_STEPS_MAX - int(w_inside_atmosphere * 12.0); // Number of times the ray from the camera to the world position (primary ray) is sampled.\n\
int LIGHT_STEPS = LIGHT_STEPS_MAX - int(w_inside_atmosphere * 2.0); // Number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.\n\
\n\
// Setup for sampling positions along the ray - starting from the intersection with the outer ring of the atmosphere.\n\
float rayPositionLength = primaryRayAtmosphereIntersect.start;\n\
// (1) Outside the atmosphere: constant rayStepLength\n\
// (2) Inside atmosphere: variable rayStepLength to compensate the rough rendering of the smaller number of ray steps\n\
float totalRayLength = primaryRayAtmosphereIntersect.stop - rayPositionLength;\n\
float rayStepLengthIncrease = w_inside_atmosphere * ((1.0 - w_stop_gt_lprl) * totalRayLength / (float(PRIMARY_STEPS * (PRIMARY_STEPS + 1)) / 2.0));\n\
float rayStepLength = max(1.0 - w_inside_atmosphere, w_stop_gt_lprl) * totalRayLength / max(7.0 * w_inside_atmosphere, float(PRIMARY_STEPS));\n\
\n\
vec3 rayleighAccumulation = vec3(0.0);\n\
vec3 mieAccumulation = vec3(0.0);\n\
vec2 opticalDepth = vec2(0.0);\n\
vec2 heightScale = vec2(czm_atmosphereRayleighScaleHeight, czm_atmosphereMieScaleHeight);\n\
\n\
// Sample positions on the primary ray.\n\
for (int i = 0; i < PRIMARY_STEPS_MAX; ++i) {\n\
\n\
// The loop should be: for (int i = 0; i < PRIMARY_STEPS; ++i) {...} but WebGL1 cannot\n\
// loop with non-constant condition, so it has to break early instead\n\
if (i >= PRIMARY_STEPS) {\n\
break;\n\
}\n\
\n\
// Calculate sample position along viewpoint ray.\n\
vec3 samplePosition = primaryRay.origin + primaryRay.direction * (rayPositionLength + rayStepLength);\n\
\n\
// Calculate height of sample position above ellipsoid.\n\
float sampleHeight = length(samplePosition) - atmosphereInnerRadius;\n\
\n\
// Calculate and accumulate density of particles at the sample position.\n\
vec2 sampleDensity = exp(-sampleHeight / heightScale) * rayStepLength;\n\
opticalDepth += sampleDensity;\n\
\n\
// Generate ray from the sample position segment to the light source, up to the outer ring of the atmosphere.\n\
czm_ray lightRay = czm_ray(samplePosition, lightDirection);\n\
czm_raySegment lightRayAtmosphereIntersect = czm_raySphereIntersectionInterval(lightRay, origin, atmosphereOuterRadius);\n\
\n\
float lightStepLength = lightRayAtmosphereIntersect.stop / float(LIGHT_STEPS);\n\
float lightPositionLength = 0.0;\n\
\n\
vec2 lightOpticalDepth = vec2(0.0);\n\
\n\
// Sample positions along the light ray, to accumulate incidence of light on the latest sample segment.\n\
for (int j = 0; j < LIGHT_STEPS_MAX; ++j) {\n\
\n\
// The loop should be: for (int j = 0; i < LIGHT_STEPS; ++j) {...} but WebGL1 cannot\n\
// loop with non-constant condition, so it has to break early instead\n\
if (j >= LIGHT_STEPS) {\n\
break;\n\
}\n\
\n\
// Calculate sample position along light ray.\n\
vec3 lightPosition = samplePosition + lightDirection * (lightPositionLength + lightStepLength * 0.5);\n\
\n\
// Calculate height of the light sample position above ellipsoid.\n\
float lightHeight = length(lightPosition) - atmosphereInnerRadius;\n\
\n\
// Calculate density of photons at the light sample position.\n\
lightOpticalDepth += exp(-lightHeight / heightScale) * lightStepLength;\n\
\n\
// Increment distance on light ray.\n\
lightPositionLength += lightStepLength;\n\
}\n\
\n\
// Compute attenuation via the primary ray and the light ray.\n\
vec3 attenuation = exp(-((czm_atmosphereMieCoefficient * (opticalDepth.y + lightOpticalDepth.y)) + (czm_atmosphereRayleighCoefficient * (opticalDepth.x + lightOpticalDepth.x))));\n\
\n\
// Accumulate the scattering.\n\
rayleighAccumulation += sampleDensity.x * attenuation;\n\
mieAccumulation += sampleDensity.y * attenuation;\n\
\n\
// Increment distance on primary ray.\n\
rayPositionLength += (rayStepLength += rayStepLengthIncrease);\n\
}\n\
\n\
// Compute the scattering amount.\n\
rayleighColor = czm_atmosphereRayleighCoefficient * rayleighAccumulation;\n\
mieColor = czm_atmosphereMieCoefficient * mieAccumulation;\n\
\n\
// Compute the transmittance i.e. how much light is passing through the atmosphere.\n\
opacity = length(exp(-((czm_atmosphereMieCoefficient * opticalDepth.y) + (czm_atmosphereRayleighCoefficient * opticalDepth.x))));\n\
}\n\
";
@@ -0,0 +1,24 @@
/**
* Applies a 2D texture transformation matrix to texture coordinates.
* This function applies translation, rotation, and scaling transformations
* as specified by the KHR_texture_transform glTF extension.
*
* @name czm_computeTextureTransform
* @glslFunction
*
* @param {vec2} texCoord The texture coordinates to transform.
* @param {mat3} textureTransform The 3x3 transformation matrix.
*
* @returns {vec2} The transformed texture coordinates.
*
* @example
* // GLSL declaration
* vec2 czm_computeTextureTransform(vec2 texCoord, mat3 textureTransform);
*
* // Apply texture transform to UV coordinates
* vec2 transformedUV = czm_computeTextureTransform(uv, u_textureTransform);
*/
vec2 czm_computeTextureTransform(vec2 texCoord, mat3 textureTransform)
{
return vec2(textureTransform * vec3(texCoord, 1.0));
}
@@ -0,0 +1,25 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Applies a 2D texture transformation matrix to texture coordinates.\n\
* This function applies translation, rotation, and scaling transformations\n\
* as specified by the KHR_texture_transform glTF extension.\n\
*\n\
* @name czm_computeTextureTransform\n\
* @glslFunction\n\
*\n\
* @param {vec2} texCoord The texture coordinates to transform.\n\
* @param {mat3} textureTransform The 3x3 transformation matrix.\n\
*\n\
* @returns {vec2} The transformed texture coordinates.\n\
*\n\
* @example\n\
* // GLSL declaration\n\
* vec2 czm_computeTextureTransform(vec2 texCoord, mat3 textureTransform);\n\
*\n\
* // Apply texture transform to UV coordinates\n\
* vec2 transformedUV = czm_computeTextureTransform(uv, u_textureTransform);\n\
*/\n\
vec2 czm_computeTextureTransform(vec2 texCoord, mat3 textureTransform)\n\
{\n\
return vec2(textureTransform * vec3(texCoord, 1.0));\n\
}";
@@ -0,0 +1,211 @@
/**
* @private
*/
vec2 cordic(float angle)
{
// Scale the vector by the appropriate factor for the 24 iterations to follow.
vec2 vector = vec2(6.0725293500888267e-1, 0.0);
// Iteration 1
float sense = (angle < 0.0) ? -1.0 : 1.0;
// float factor = sense * 1.0; // 2^-0
mat2 rotation = mat2(1.0, sense, -sense, 1.0);
vector = rotation * vector;
angle -= sense * 7.8539816339744828e-1; // atan(2^-0)
// Iteration 2
sense = (angle < 0.0) ? -1.0 : 1.0;
float factor = sense * 5.0e-1; // 2^-1
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 4.6364760900080609e-1; // atan(2^-1)
// Iteration 3
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 2.5e-1; // 2^-2
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 2.4497866312686414e-1; // atan(2^-2)
// Iteration 4
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 1.25e-1; // 2^-3
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 1.2435499454676144e-1; // atan(2^-3)
// Iteration 5
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 6.25e-2; // 2^-4
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 6.2418809995957350e-2; // atan(2^-4)
// Iteration 6
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 3.125e-2; // 2^-5
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 3.1239833430268277e-2; // atan(2^-5)
// Iteration 7
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 1.5625e-2; // 2^-6
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 1.5623728620476831e-2; // atan(2^-6)
// Iteration 8
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 7.8125e-3; // 2^-7
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 7.8123410601011111e-3; // atan(2^-7)
// Iteration 9
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 3.90625e-3; // 2^-8
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 3.9062301319669718e-3; // atan(2^-8)
// Iteration 10
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 1.953125e-3; // 2^-9
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 1.9531225164788188e-3; // atan(2^-9)
// Iteration 11
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 9.765625e-4; // 2^-10
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 9.7656218955931946e-4; // atan(2^-10)
// Iteration 12
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 4.8828125e-4; // 2^-11
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 4.8828121119489829e-4; // atan(2^-11)
// Iteration 13
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 2.44140625e-4; // 2^-12
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 2.4414062014936177e-4; // atan(2^-12)
// Iteration 14
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 1.220703125e-4; // 2^-13
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 1.2207031189367021e-4; // atan(2^-13)
// Iteration 15
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 6.103515625e-5; // 2^-14
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 6.1035156174208773e-5; // atan(2^-14)
// Iteration 16
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 3.0517578125e-5; // 2^-15
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 3.0517578115526096e-5; // atan(2^-15)
// Iteration 17
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 1.52587890625e-5; // 2^-16
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 1.5258789061315762e-5; // atan(2^-16)
// Iteration 18
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 7.62939453125e-6; // 2^-17
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 7.6293945311019700e-6; // atan(2^-17)
// Iteration 19
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 3.814697265625e-6; // 2^-18
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 3.8146972656064961e-6; // atan(2^-18)
// Iteration 20
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 1.9073486328125e-6; // 2^-19
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 1.9073486328101870e-6; // atan(2^-19)
// Iteration 21
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 9.5367431640625e-7; // 2^-20
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 9.5367431640596084e-7; // atan(2^-20)
// Iteration 22
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 4.76837158203125e-7; // 2^-21
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 4.7683715820308884e-7; // atan(2^-21)
// Iteration 23
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 2.384185791015625e-7; // 2^-22
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
angle -= sense * 2.3841857910155797e-7; // atan(2^-22)
// Iteration 24
sense = (angle < 0.0) ? -1.0 : 1.0;
factor = sense * 1.1920928955078125e-7; // 2^-23
rotation[0][1] = factor;
rotation[1][0] = -factor;
vector = rotation * vector;
// angle -= sense * 1.1920928955078068e-7; // atan(2^-23)
return vector;
}
/**
* Computes the cosine and sine of the provided angle using the CORDIC algorithm.
*
* @name czm_cosineAndSine
* @glslFunction
*
* @param {float} angle The angle in radians.
*
* @returns {vec2} The resulting cosine of the angle (as the x coordinate) and sine of the angle (as the y coordinate).
*
* @example
* vec2 v = czm_cosineAndSine(czm_piOverSix);
* float cosine = v.x;
* float sine = v.y;
*/
vec2 czm_cosineAndSine(float angle)
{
if (angle < -czm_piOverTwo || angle > czm_piOverTwo)
{
if (angle < 0.0)
{
return -cordic(angle + czm_pi);
}
else
{
return -cordic(angle - czm_pi);
}
}
else
{
return cordic(angle);
}
}
@@ -0,0 +1,213 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* @private\n\
*/\n\
vec2 cordic(float angle)\n\
{\n\
// Scale the vector by the appropriate factor for the 24 iterations to follow.\n\
vec2 vector = vec2(6.0725293500888267e-1, 0.0);\n\
// Iteration 1\n\
float sense = (angle < 0.0) ? -1.0 : 1.0;\n\
// float factor = sense * 1.0; // 2^-0\n\
mat2 rotation = mat2(1.0, sense, -sense, 1.0);\n\
vector = rotation * vector;\n\
angle -= sense * 7.8539816339744828e-1; // atan(2^-0)\n\
// Iteration 2\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
float factor = sense * 5.0e-1; // 2^-1\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 4.6364760900080609e-1; // atan(2^-1)\n\
// Iteration 3\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 2.5e-1; // 2^-2\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 2.4497866312686414e-1; // atan(2^-2)\n\
// Iteration 4\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 1.25e-1; // 2^-3\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 1.2435499454676144e-1; // atan(2^-3)\n\
// Iteration 5\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 6.25e-2; // 2^-4\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 6.2418809995957350e-2; // atan(2^-4)\n\
// Iteration 6\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 3.125e-2; // 2^-5\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 3.1239833430268277e-2; // atan(2^-5)\n\
// Iteration 7\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 1.5625e-2; // 2^-6\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 1.5623728620476831e-2; // atan(2^-6)\n\
// Iteration 8\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 7.8125e-3; // 2^-7\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 7.8123410601011111e-3; // atan(2^-7)\n\
// Iteration 9\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 3.90625e-3; // 2^-8\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 3.9062301319669718e-3; // atan(2^-8)\n\
// Iteration 10\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 1.953125e-3; // 2^-9\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 1.9531225164788188e-3; // atan(2^-9)\n\
// Iteration 11\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 9.765625e-4; // 2^-10\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 9.7656218955931946e-4; // atan(2^-10)\n\
// Iteration 12\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 4.8828125e-4; // 2^-11\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 4.8828121119489829e-4; // atan(2^-11)\n\
// Iteration 13\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 2.44140625e-4; // 2^-12\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 2.4414062014936177e-4; // atan(2^-12)\n\
// Iteration 14\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 1.220703125e-4; // 2^-13\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 1.2207031189367021e-4; // atan(2^-13)\n\
// Iteration 15\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 6.103515625e-5; // 2^-14\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 6.1035156174208773e-5; // atan(2^-14)\n\
// Iteration 16\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 3.0517578125e-5; // 2^-15\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 3.0517578115526096e-5; // atan(2^-15)\n\
// Iteration 17\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 1.52587890625e-5; // 2^-16\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 1.5258789061315762e-5; // atan(2^-16)\n\
// Iteration 18\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 7.62939453125e-6; // 2^-17\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 7.6293945311019700e-6; // atan(2^-17)\n\
// Iteration 19\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 3.814697265625e-6; // 2^-18\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 3.8146972656064961e-6; // atan(2^-18)\n\
// Iteration 20\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 1.9073486328125e-6; // 2^-19\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 1.9073486328101870e-6; // atan(2^-19)\n\
// Iteration 21\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 9.5367431640625e-7; // 2^-20\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 9.5367431640596084e-7; // atan(2^-20)\n\
// Iteration 22\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 4.76837158203125e-7; // 2^-21\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 4.7683715820308884e-7; // atan(2^-21)\n\
// Iteration 23\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 2.384185791015625e-7; // 2^-22\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
angle -= sense * 2.3841857910155797e-7; // atan(2^-22)\n\
// Iteration 24\n\
sense = (angle < 0.0) ? -1.0 : 1.0;\n\
factor = sense * 1.1920928955078125e-7; // 2^-23\n\
rotation[0][1] = factor;\n\
rotation[1][0] = -factor;\n\
vector = rotation * vector;\n\
// angle -= sense * 1.1920928955078068e-7; // atan(2^-23)\n\
\n\
return vector;\n\
}\n\
\n\
/**\n\
* Computes the cosine and sine of the provided angle using the CORDIC algorithm.\n\
*\n\
* @name czm_cosineAndSine\n\
* @glslFunction\n\
*\n\
* @param {float} angle The angle in radians.\n\
*\n\
* @returns {vec2} The resulting cosine of the angle (as the x coordinate) and sine of the angle (as the y coordinate).\n\
*\n\
* @example\n\
* vec2 v = czm_cosineAndSine(czm_piOverSix);\n\
* float cosine = v.x;\n\
* float sine = v.y;\n\
*/\n\
vec2 czm_cosineAndSine(float angle)\n\
{\n\
if (angle < -czm_piOverTwo || angle > czm_piOverTwo)\n\
{\n\
if (angle < 0.0)\n\
{\n\
return -cordic(angle + czm_pi);\n\
}\n\
else\n\
{\n\
return -cordic(angle - czm_pi);\n\
}\n\
}\n\
else\n\
{\n\
return cordic(angle);\n\
}\n\
}\n\
";
@@ -0,0 +1,22 @@
/**
* Decodes RGB values packed into a single float at 8-bit precision. Encoded
* representation is equivalent to 0xFFFFFF in JavaScript.
*
* @name czm_decodeRGB8
* @glslFunction
*
* @param {float} encoded Float-encoded RGB values.
* @returns {vec4} Decoded RGB values.
*/
vec4 czm_decodeRGB8(float encoded) {
const float SHIFT_RIGHT16 = 1.0 / 65536.0;
const float SHIFT_RIGHT8 = 1.0 / 256.0;
const float SHIFT_LEFT16 = 65536.0;
const float SHIFT_LEFT8 = 256.0;
vec4 color = vec4(255.0);
color.r = floor(encoded * SHIFT_RIGHT16);
color.g = floor((encoded - color.r * SHIFT_LEFT16) * SHIFT_RIGHT8);
color.b = floor(encoded - color.r * SHIFT_LEFT16 - color.g * SHIFT_LEFT8);
return color / 255.0;
}
@@ -0,0 +1,24 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Decodes RGB values packed into a single float at 8-bit precision. Encoded\n\
* representation is equivalent to 0xFFFFFF in JavaScript.\n\
*\n\
* @name czm_decodeRGB8\n\
* @glslFunction\n\
*\n\
* @param {float} encoded Float-encoded RGB values.\n\
* @returns {vec4} Decoded RGB values.\n\
*/\n\
vec4 czm_decodeRGB8(float encoded) {\n\
const float SHIFT_RIGHT16 = 1.0 / 65536.0;\n\
const float SHIFT_RIGHT8 = 1.0 / 256.0;\n\
const float SHIFT_LEFT16 = 65536.0;\n\
const float SHIFT_LEFT8 = 256.0;\n\
\n\
vec4 color = vec4(255.0);\n\
color.r = floor(encoded * SHIFT_RIGHT16);\n\
color.g = floor((encoded - color.r * SHIFT_LEFT16) * SHIFT_RIGHT8);\n\
color.b = floor(encoded - color.r * SHIFT_LEFT16 - color.g * SHIFT_LEFT8);\n\
return color / 255.0;\n\
}\n\
";
@@ -0,0 +1,17 @@
/**
* Decompresses texture coordinates that were packed into a single float.
*
* @name czm_decompressTextureCoordinates
* @glslFunction
*
* @param {float} encoded The compressed texture coordinates.
* @returns {vec2} The decompressed texture coordinates.
*/
vec2 czm_decompressTextureCoordinates(float encoded)
{
float temp = encoded / 4096.0;
float xZeroTo4095 = floor(temp);
float stx = xZeroTo4095 / 4095.0;
float sty = (encoded - xZeroTo4095 * 4096.0) / 4095.0;
return vec2(stx, sty);
}
@@ -0,0 +1,19 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Decompresses texture coordinates that were packed into a single float.\n\
*\n\
* @name czm_decompressTextureCoordinates\n\
* @glslFunction\n\
*\n\
* @param {float} encoded The compressed texture coordinates.\n\
* @returns {vec2} The decompressed texture coordinates.\n\
*/\n\
vec2 czm_decompressTextureCoordinates(float encoded)\n\
{\n\
float temp = encoded / 4096.0;\n\
float xZeroTo4095 = floor(temp);\n\
float stx = xZeroTo4095 / 4095.0;\n\
float sty = (encoded - xZeroTo4095 * 4096.0) / 4095.0;\n\
return vec2(stx, sty);\n\
}\n\
";
@@ -0,0 +1,47 @@
// emulated noperspective
#if (__VERSION__ == 300 || defined(GL_EXT_frag_depth)) && !defined(LOG_DEPTH)
out float v_WindowZ;
#endif
/**
* Emulates GL_DEPTH_CLAMP, which is not available in WebGL 1 or 2.
* GL_DEPTH_CLAMP clamps geometry that is outside the near and far planes,
* capping the shadow volume. More information here:
* https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_depth_clamp.txt.
*
* When GL_EXT_frag_depth is available we emulate GL_DEPTH_CLAMP by ensuring
* no geometry gets clipped by setting the clip space z value to 0.0 and then
* sending the unaltered screen space z value (using emulated noperspective
* interpolation) to the frag shader where it is clamped to [0,1] and then
* written with gl_FragDepth (see czm_writeDepthClamp). This technique is based on:
* https://stackoverflow.com/questions/5960757/how-to-emulate-gl-depth-clamp-nv.
*
* When GL_EXT_frag_depth is not available, which is the case on some mobile
* devices, we must attempt to fix this only in the vertex shader.
* The approach is to clamp the z value to the far plane, which closes the
* shadow volume but also distorts the geometry, so there can still be artifacts
* on frustum seams.
*
* @name czm_depthClamp
* @glslFunction
*
* @param {vec4} coords The vertex in clip coordinates.
* @returns {vec4} The modified vertex.
*
* @example
* gl_Position = czm_depthClamp(czm_modelViewProjection * vec4(position, 1.0));
*
* @see czm_writeDepthClamp
*/
vec4 czm_depthClamp(vec4 coords)
{
#ifndef LOG_DEPTH
#if __VERSION__ == 300 || defined(GL_EXT_frag_depth)
v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w;
coords.z = 0.0;
#else
coords.z = min(coords.z, coords.w);
#endif
#endif
return coords;
}
@@ -0,0 +1,49 @@
//This file is automatically rebuilt by the Cesium build process.
export default "// emulated noperspective\n\
#if (__VERSION__ == 300 || defined(GL_EXT_frag_depth)) && !defined(LOG_DEPTH)\n\
out float v_WindowZ;\n\
#endif\n\
\n\
/**\n\
* Emulates GL_DEPTH_CLAMP, which is not available in WebGL 1 or 2.\n\
* GL_DEPTH_CLAMP clamps geometry that is outside the near and far planes, \n\
* capping the shadow volume. More information here: \n\
* https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_depth_clamp.txt.\n\
*\n\
* When GL_EXT_frag_depth is available we emulate GL_DEPTH_CLAMP by ensuring \n\
* no geometry gets clipped by setting the clip space z value to 0.0 and then\n\
* sending the unaltered screen space z value (using emulated noperspective\n\
* interpolation) to the frag shader where it is clamped to [0,1] and then\n\
* written with gl_FragDepth (see czm_writeDepthClamp). This technique is based on:\n\
* https://stackoverflow.com/questions/5960757/how-to-emulate-gl-depth-clamp-nv.\n\
*\n\
* When GL_EXT_frag_depth is not available, which is the case on some mobile \n\
* devices, we must attempt to fix this only in the vertex shader. \n\
* The approach is to clamp the z value to the far plane, which closes the \n\
* shadow volume but also distorts the geometry, so there can still be artifacts\n\
* on frustum seams.\n\
*\n\
* @name czm_depthClamp\n\
* @glslFunction\n\
*\n\
* @param {vec4} coords The vertex in clip coordinates.\n\
* @returns {vec4} The modified vertex.\n\
*\n\
* @example\n\
* gl_Position = czm_depthClamp(czm_modelViewProjection * vec4(position, 1.0));\n\
*\n\
* @see czm_writeDepthClamp\n\
*/\n\
vec4 czm_depthClamp(vec4 coords)\n\
{\n\
#ifndef LOG_DEPTH\n\
#if __VERSION__ == 300 || defined(GL_EXT_frag_depth)\n\
v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w;\n\
coords.z = 0.0;\n\
#else\n\
coords.z = min(coords.z, coords.w);\n\
#endif\n\
#endif\n\
return coords;\n\
}\n\
";
@@ -0,0 +1,33 @@
/**
* Computes a 3x3 rotation matrix that transforms vectors from an ellipsoid's east-north-up coordinate system
* to eye coordinates. In east-north-up coordinates, x points east, y points north, and z points along the
* surface normal. East-north-up can be used as an ellipsoid's tangent space for operations such as bump mapping.
* <br /><br />
* The ellipsoid is assumed to be centered at the model coordinate's origin.
*
* @name czm_eastNorthUpToEyeCoordinates
* @glslFunction
*
* @param {vec3} positionMC The position on the ellipsoid in model coordinates.
* @param {vec3} normalEC The normalized ellipsoid surface normal, at <code>positionMC</code>, in eye coordinates.
*
* @returns {mat3} A 3x3 rotation matrix that transforms vectors from the east-north-up coordinate system to eye coordinates.
*
* @example
* // Transform a vector defined in the east-north-up coordinate
* // system, (0, 0, 1) which is the surface normal, to eye
* // coordinates.
* mat3 m = czm_eastNorthUpToEyeCoordinates(positionMC, normalEC);
* vec3 normalEC = m * vec3(0.0, 0.0, 1.0);
*/
mat3 czm_eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)
{
vec3 tangentMC = normalize(vec3(-positionMC.y, positionMC.x, 0.0)); // normalized surface tangent in model coordinates
vec3 tangentEC = normalize(czm_normal3D * tangentMC); // normalized surface tangent in eye coordinates
vec3 bitangentEC = normalize(cross(normalEC, tangentEC)); // normalized surface bitangent in eye coordinates
return mat3(
tangentEC.x, tangentEC.y, tangentEC.z,
bitangentEC.x, bitangentEC.y, bitangentEC.z,
normalEC.x, normalEC.y, normalEC.z);
}
@@ -0,0 +1,35 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Computes a 3x3 rotation matrix that transforms vectors from an ellipsoid's east-north-up coordinate system \n\
* to eye coordinates. In east-north-up coordinates, x points east, y points north, and z points along the \n\
* surface normal. East-north-up can be used as an ellipsoid's tangent space for operations such as bump mapping.\n\
* <br /><br />\n\
* The ellipsoid is assumed to be centered at the model coordinate's origin.\n\
*\n\
* @name czm_eastNorthUpToEyeCoordinates\n\
* @glslFunction\n\
*\n\
* @param {vec3} positionMC The position on the ellipsoid in model coordinates.\n\
* @param {vec3} normalEC The normalized ellipsoid surface normal, at <code>positionMC</code>, in eye coordinates.\n\
*\n\
* @returns {mat3} A 3x3 rotation matrix that transforms vectors from the east-north-up coordinate system to eye coordinates.\n\
*\n\
* @example\n\
* // Transform a vector defined in the east-north-up coordinate \n\
* // system, (0, 0, 1) which is the surface normal, to eye \n\
* // coordinates.\n\
* mat3 m = czm_eastNorthUpToEyeCoordinates(positionMC, normalEC);\n\
* vec3 normalEC = m * vec3(0.0, 0.0, 1.0);\n\
*/\n\
mat3 czm_eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)\n\
{\n\
vec3 tangentMC = normalize(vec3(-positionMC.y, positionMC.x, 0.0)); // normalized surface tangent in model coordinates\n\
vec3 tangentEC = normalize(czm_normal3D * tangentMC); // normalized surface tangent in eye coordinates\n\
vec3 bitangentEC = normalize(cross(normalEC, tangentEC)); // normalized surface bitangent in eye coordinates\n\
\n\
return mat3(\n\
tangentEC.x, tangentEC.y, tangentEC.z,\n\
bitangentEC.x, bitangentEC.y, bitangentEC.z,\n\
normalEC.x, normalEC.y, normalEC.z);\n\
}\n\
";
@@ -0,0 +1,12 @@
/**
* DOC_TBA
*
* @name czm_ellipsoidContainsPoint
* @glslFunction
*
*/
bool czm_ellipsoidContainsPoint(vec3 ellipsoid_inverseRadii, vec3 point)
{
vec3 scaled = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(point, 1.0)).xyz;
return (dot(scaled, scaled) <= 1.0);
}
@@ -0,0 +1,14 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* DOC_TBA\n\
*\n\
* @name czm_ellipsoidContainsPoint\n\
* @glslFunction\n\
*\n\
*/\n\
bool czm_ellipsoidContainsPoint(vec3 ellipsoid_inverseRadii, vec3 point)\n\
{\n\
vec3 scaled = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(point, 1.0)).xyz;\n\
return (dot(scaled, scaled) <= 1.0);\n\
}\n\
";
@@ -0,0 +1,10 @@
/**
* Approximate uv coordinates based on the ellipsoid normal.
*
* @name czm_ellipsoidTextureCoordinates
* @glslFunction
*/
vec2 czm_ellipsoidTextureCoordinates(vec3 normal)
{
return vec2(atan(normal.y, normal.x) * czm_oneOverTwoPi + 0.5, asin(normal.z) * czm_oneOverPi + 0.5);
}
@@ -0,0 +1,12 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Approximate uv coordinates based on the ellipsoid normal.\n\
*\n\
* @name czm_ellipsoidTextureCoordinates\n\
* @glslFunction\n\
*/\n\
vec2 czm_ellipsoidTextureCoordinates(vec3 normal)\n\
{\n\
return vec2(atan(normal.y, normal.x) * czm_oneOverTwoPi + 0.5, asin(normal.z) * czm_oneOverPi + 0.5);\n\
}\n\
";
@@ -0,0 +1,36 @@
/**
* Compares <code>left</code> and <code>right</code> componentwise. Returns <code>true</code>
* if they are within <code>epsilon</code> and <code>false</code> otherwise. The inputs
* <code>left</code> and <code>right</code> can be <code>float</code>s, <code>vec2</code>s,
* <code>vec3</code>s, or <code>vec4</code>s.
*
* @name czm_equalsEpsilon
* @glslFunction
*
* @param {} left The first vector.
* @param {} right The second vector.
* @param {float} epsilon The epsilon to use for equality testing.
* @returns {bool} <code>true</code> if the components are within <code>epsilon</code> and <code>false</code> otherwise.
*
* @example
* // GLSL declarations
* bool czm_equalsEpsilon(float left, float right, float epsilon);
* bool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon);
* bool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon);
* bool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon);
*/
bool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon) {
return all(lessThanEqual(abs(left - right), vec4(epsilon)));
}
bool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon) {
return all(lessThanEqual(abs(left - right), vec3(epsilon)));
}
bool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon) {
return all(lessThanEqual(abs(left - right), vec2(epsilon)));
}
bool czm_equalsEpsilon(float left, float right, float epsilon) {
return (abs(left - right) <= epsilon);
}
@@ -0,0 +1,38 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Compares <code>left</code> and <code>right</code> componentwise. Returns <code>true</code>\n\
* if they are within <code>epsilon</code> and <code>false</code> otherwise. The inputs\n\
* <code>left</code> and <code>right</code> can be <code>float</code>s, <code>vec2</code>s,\n\
* <code>vec3</code>s, or <code>vec4</code>s.\n\
*\n\
* @name czm_equalsEpsilon\n\
* @glslFunction\n\
*\n\
* @param {} left The first vector.\n\
* @param {} right The second vector.\n\
* @param {float} epsilon The epsilon to use for equality testing.\n\
* @returns {bool} <code>true</code> if the components are within <code>epsilon</code> and <code>false</code> otherwise.\n\
*\n\
* @example\n\
* // GLSL declarations\n\
* bool czm_equalsEpsilon(float left, float right, float epsilon);\n\
* bool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon);\n\
* bool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon);\n\
* bool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon);\n\
*/\n\
bool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon) {\n\
return all(lessThanEqual(abs(left - right), vec4(epsilon)));\n\
}\n\
\n\
bool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon) {\n\
return all(lessThanEqual(abs(left - right), vec3(epsilon)));\n\
}\n\
\n\
bool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon) {\n\
return all(lessThanEqual(abs(left - right), vec2(epsilon)));\n\
}\n\
\n\
bool czm_equalsEpsilon(float left, float right, float epsilon) {\n\
return (abs(left - right) <= epsilon);\n\
}\n\
";
@@ -0,0 +1,20 @@
/**
* DOC_TBA
*
* @name czm_eyeOffset
* @glslFunction
*
* @param {vec4} positionEC DOC_TBA.
* @param {vec3} eyeOffset DOC_TBA.
*
* @returns {vec4} DOC_TBA.
*/
vec4 czm_eyeOffset(vec4 positionEC, vec3 eyeOffset)
{
// This equation is approximate in x and y.
vec4 p = positionEC;
vec4 zEyeOffset = normalize(p) * eyeOffset.z;
p.xy += eyeOffset.xy + zEyeOffset.xy;
p.z += zEyeOffset.z;
return p;
}
@@ -0,0 +1,22 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* DOC_TBA\n\
*\n\
* @name czm_eyeOffset\n\
* @glslFunction\n\
*\n\
* @param {vec4} positionEC DOC_TBA.\n\
* @param {vec3} eyeOffset DOC_TBA.\n\
*\n\
* @returns {vec4} DOC_TBA.\n\
*/\n\
vec4 czm_eyeOffset(vec4 positionEC, vec3 eyeOffset)\n\
{\n\
// This equation is approximate in x and y.\n\
vec4 p = positionEC;\n\
vec4 zEyeOffset = normalize(p) * eyeOffset.z;\n\
p.xy += eyeOffset.xy + zEyeOffset.xy;\n\
p.z += zEyeOffset.z;\n\
return p;\n\
}\n\
";
@@ -0,0 +1,32 @@
/**
* Transforms a position from eye to window coordinates. The transformation
* from eye to clip coordinates is done using {@link czm_projection}.
* The transform from normalized device coordinates to window coordinates is
* done using {@link czm_viewportTransformation}, which assumes a depth range
* of <code>near = 0</code> and <code>far = 1</code>.
* <br /><br />
* This transform is useful when there is a need to manipulate window coordinates
* in a vertex shader as done by {@link BillboardCollection}.
*
* @name czm_eyeToWindowCoordinates
* @glslFunction
*
* @param {vec4} position The position in eye coordinates to transform.
*
* @returns {vec4} The transformed position in window coordinates.
*
* @see czm_modelToWindowCoordinates
* @see czm_projection
* @see czm_viewportTransformation
* @see BillboardCollection
*
* @example
* vec4 positionWC = czm_eyeToWindowCoordinates(positionEC);
*/
vec4 czm_eyeToWindowCoordinates(vec4 positionEC)
{
vec4 q = czm_projection * positionEC; // clip coordinates
q.xyz /= q.w; // normalized device coordinates
q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates
return q;
}
@@ -0,0 +1,34 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Transforms a position from eye to window coordinates. The transformation\n\
* from eye to clip coordinates is done using {@link czm_projection}.\n\
* The transform from normalized device coordinates to window coordinates is\n\
* done using {@link czm_viewportTransformation}, which assumes a depth range\n\
* of <code>near = 0</code> and <code>far = 1</code>.\n\
* <br /><br />\n\
* This transform is useful when there is a need to manipulate window coordinates\n\
* in a vertex shader as done by {@link BillboardCollection}.\n\
*\n\
* @name czm_eyeToWindowCoordinates\n\
* @glslFunction\n\
*\n\
* @param {vec4} position The position in eye coordinates to transform.\n\
*\n\
* @returns {vec4} The transformed position in window coordinates.\n\
*\n\
* @see czm_modelToWindowCoordinates\n\
* @see czm_projection\n\
* @see czm_viewportTransformation\n\
* @see BillboardCollection\n\
*\n\
* @example\n\
* vec4 positionWC = czm_eyeToWindowCoordinates(positionEC);\n\
*/\n\
vec4 czm_eyeToWindowCoordinates(vec4 positionEC)\n\
{\n\
vec4 q = czm_projection * positionEC; // clip coordinates\n\
q.xyz /= q.w; // normalized device coordinates\n\
q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates\n\
return q;\n\
}\n\
";
@@ -0,0 +1,55 @@
/**
* Approxiamtes atan over the range [0, 1]. Safe to flip output for negative input.
*
* Based on Michal Drobot's approximation from ShaderFastLibs, which in turn is based on
* "Efficient approximations for the arctangent function," Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006.
* Adapted from ShaderFastLibs under MIT License.
*
* Chosen for the following characteristics over range [0, 1]:
* - basically no error at 0 and 1, important for getting around range limit (naive atan2 via atan requires infinite range atan)
* - no visible artifacts from first-derivative discontinuities, unlike latitude via range-reduced sqrt asin approximations (at equator)
*
* The original code is x * (-0.1784 * abs(x) - 0.0663 * x * x + 1.0301);
* Removed the abs() in here because it isn't needed, the input range is guaranteed as [0, 1] by how we're approximating atan2.
*
* @name czm_fastApproximateAtan
* @glslFunction
*
* @param {float} x Value between 0 and 1 inclusive.
*
* @returns {float} Approximation of atan(x)
*/
float czm_fastApproximateAtan(float x) {
return x * (-0.1784 * x - 0.0663 * x * x + 1.0301);
}
/**
* Approximation of atan2.
*
* Range reduction math based on nvidia's cg reference implementation for atan2: http://developer.download.nvidia.com/cg/atan2.html
* However, we replaced their atan curve with Michael Drobot's (see above).
*
* @name czm_fastApproximateAtan
* @glslFunction
*
* @param {float} x Value between -1 and 1 inclusive.
* @param {float} y Value between -1 and 1 inclusive.
*
* @returns {float} Approximation of atan2(x, y)
*/
float czm_fastApproximateAtan(float x, float y) {
// atan approximations are usually only reliable over [-1, 1], or, in our case, [0, 1] due to modifications.
// So range-reduce using abs and by flipping whether x or y is on top.
float t = abs(x); // t used as swap and atan result.
float opposite = abs(y);
float adjacent = max(t, opposite);
opposite = min(t, opposite);
t = czm_fastApproximateAtan(opposite / adjacent);
// Undo range reduction
t = czm_branchFreeTernary(abs(y) > abs(x), czm_piOverTwo - t, t);
t = czm_branchFreeTernary(x < 0.0, czm_pi - t, t);
t = czm_branchFreeTernary(y < 0.0, -t, t);
return t;
}
@@ -0,0 +1,57 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Approxiamtes atan over the range [0, 1]. Safe to flip output for negative input.\n\
*\n\
* Based on Michal Drobot's approximation from ShaderFastLibs, which in turn is based on\n\
* \"Efficient approximations for the arctangent function,\" Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006.\n\
* Adapted from ShaderFastLibs under MIT License.\n\
*\n\
* Chosen for the following characteristics over range [0, 1]:\n\
* - basically no error at 0 and 1, important for getting around range limit (naive atan2 via atan requires infinite range atan)\n\
* - no visible artifacts from first-derivative discontinuities, unlike latitude via range-reduced sqrt asin approximations (at equator)\n\
*\n\
* The original code is x * (-0.1784 * abs(x) - 0.0663 * x * x + 1.0301);\n\
* Removed the abs() in here because it isn't needed, the input range is guaranteed as [0, 1] by how we're approximating atan2.\n\
*\n\
* @name czm_fastApproximateAtan\n\
* @glslFunction\n\
*\n\
* @param {float} x Value between 0 and 1 inclusive.\n\
*\n\
* @returns {float} Approximation of atan(x)\n\
*/\n\
float czm_fastApproximateAtan(float x) {\n\
return x * (-0.1784 * x - 0.0663 * x * x + 1.0301);\n\
}\n\
\n\
/**\n\
* Approximation of atan2.\n\
*\n\
* Range reduction math based on nvidia's cg reference implementation for atan2: http://developer.download.nvidia.com/cg/atan2.html\n\
* However, we replaced their atan curve with Michael Drobot's (see above).\n\
*\n\
* @name czm_fastApproximateAtan\n\
* @glslFunction\n\
*\n\
* @param {float} x Value between -1 and 1 inclusive.\n\
* @param {float} y Value between -1 and 1 inclusive.\n\
*\n\
* @returns {float} Approximation of atan2(x, y)\n\
*/\n\
float czm_fastApproximateAtan(float x, float y) {\n\
// atan approximations are usually only reliable over [-1, 1], or, in our case, [0, 1] due to modifications.\n\
// So range-reduce using abs and by flipping whether x or y is on top.\n\
float t = abs(x); // t used as swap and atan result.\n\
float opposite = abs(y);\n\
float adjacent = max(t, opposite);\n\
opposite = min(t, opposite);\n\
\n\
t = czm_fastApproximateAtan(opposite / adjacent);\n\
\n\
// Undo range reduction\n\
t = czm_branchFreeTernary(abs(y) > abs(x), czm_piOverTwo - t, t);\n\
t = czm_branchFreeTernary(x < 0.0, czm_pi - t, t);\n\
t = czm_branchFreeTernary(y < 0.0, -t, t);\n\
return t;\n\
}\n\
";
+38
View File
@@ -0,0 +1,38 @@
/**
* Gets the color with fog at a distance from the camera.
*
* @name czm_fog
* @glslFunction
*
* @param {float} distanceToCamera The distance to the camera in meters.
* @param {vec3} color The original color.
* @param {vec3} fogColor The color of the fog.
*
* @returns {vec3} The color adjusted for fog at the distance from the camera.
*/
vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor)
{
float scalar = distanceToCamera * czm_fogDensity;
float fog = 1.0 - exp(-(scalar * scalar));
return mix(color, fogColor, fog);
}
/**
* Gets the color with fog at a distance from the camera.
*
* @name czm_fog
* @glslFunction
*
* @param {float} distanceToCamera The distance to the camera in meters.
* @param {vec3} color The original color.
* @param {vec3} fogColor The color of the fog.
* @param {float} fogModifierConstant A constant to modify the appearance of fog.
*
* @returns {vec3} The color adjusted for fog at the distance from the camera.
*/
vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor, float fogModifierConstant)
{
float scalar = distanceToCamera * czm_fogDensity;
float fog = 1.0 - exp(-((fogModifierConstant * scalar + fogModifierConstant) * (scalar * (1.0 + fogModifierConstant))));
return mix(color, fogColor, fog);
}
+40
View File
@@ -0,0 +1,40 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Gets the color with fog at a distance from the camera.\n\
*\n\
* @name czm_fog\n\
* @glslFunction\n\
*\n\
* @param {float} distanceToCamera The distance to the camera in meters.\n\
* @param {vec3} color The original color.\n\
* @param {vec3} fogColor The color of the fog.\n\
*\n\
* @returns {vec3} The color adjusted for fog at the distance from the camera.\n\
*/\n\
vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor)\n\
{\n\
float scalar = distanceToCamera * czm_fogDensity;\n\
float fog = 1.0 - exp(-(scalar * scalar));\n\
return mix(color, fogColor, fog);\n\
}\n\
\n\
/**\n\
* Gets the color with fog at a distance from the camera.\n\
*\n\
* @name czm_fog\n\
* @glslFunction\n\
*\n\
* @param {float} distanceToCamera The distance to the camera in meters.\n\
* @param {vec3} color The original color.\n\
* @param {vec3} fogColor The color of the fog.\n\
* @param {float} fogModifierConstant A constant to modify the appearance of fog.\n\
*\n\
* @returns {vec3} The color adjusted for fog at the distance from the camera.\n\
*/\n\
vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor, float fogModifierConstant)\n\
{\n\
float scalar = distanceToCamera * czm_fogDensity;\n\
float fog = 1.0 - exp(-((fogModifierConstant * scalar + fogModifierConstant) * (scalar * (1.0 + fogModifierConstant))));\n\
return mix(color, fogColor, fog);\n\
}\n\
";
@@ -0,0 +1,22 @@
/**
* Converts a color from RGB space to linear space.
*
* @name czm_gammaCorrect
* @glslFunction
*
* @param {vec3} color The color in RGB space.
* @returns {vec3} The color in linear space.
*/
vec3 czm_gammaCorrect(vec3 color) {
#ifdef HDR
color = pow(color, vec3(czm_gamma));
#endif
return color;
}
vec4 czm_gammaCorrect(vec4 color) {
#ifdef HDR
color.rgb = pow(color.rgb, vec3(czm_gamma));
#endif
return color;
}
@@ -0,0 +1,24 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts a color from RGB space to linear space.\n\
*\n\
* @name czm_gammaCorrect\n\
* @glslFunction\n\
*\n\
* @param {vec3} color The color in RGB space.\n\
* @returns {vec3} The color in linear space.\n\
*/\n\
vec3 czm_gammaCorrect(vec3 color) {\n\
#ifdef HDR\n\
color = pow(color, vec3(czm_gamma));\n\
#endif\n\
return color;\n\
}\n\
\n\
vec4 czm_gammaCorrect(vec4 color) {\n\
#ifdef HDR\n\
color.rgb = pow(color.rgb, vec3(czm_gamma));\n\
#endif\n\
return color;\n\
}\n\
";
@@ -0,0 +1,16 @@
/**
* DOC_TBA
*
* @name czm_geodeticSurfaceNormal
* @glslFunction
*
* @param {vec3} positionOnEllipsoid DOC_TBA
* @param {vec3} ellipsoidCenter DOC_TBA
* @param {vec3} oneOverEllipsoidRadiiSquared DOC_TBA
*
* @returns {vec3} DOC_TBA.
*/
vec3 czm_geodeticSurfaceNormal(vec3 positionOnEllipsoid, vec3 ellipsoidCenter, vec3 oneOverEllipsoidRadiiSquared)
{
return normalize((positionOnEllipsoid - ellipsoidCenter) * oneOverEllipsoidRadiiSquared);
}
@@ -0,0 +1,18 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* DOC_TBA\n\
*\n\
* @name czm_geodeticSurfaceNormal\n\
* @glslFunction\n\
*\n\
* @param {vec3} positionOnEllipsoid DOC_TBA\n\
* @param {vec3} ellipsoidCenter DOC_TBA\n\
* @param {vec3} oneOverEllipsoidRadiiSquared DOC_TBA\n\
* \n\
* @returns {vec3} DOC_TBA.\n\
*/\n\
vec3 czm_geodeticSurfaceNormal(vec3 positionOnEllipsoid, vec3 ellipsoidCenter, vec3 oneOverEllipsoidRadiiSquared)\n\
{\n\
return normalize((positionOnEllipsoid - ellipsoidCenter) * oneOverEllipsoidRadiiSquared);\n\
}\n\
";
@@ -0,0 +1,27 @@
/**
* An czm_material with default values. Every material's czm_getMaterial
* should use this default material as a base for the material it returns.
* The default normal value is given by materialInput.normalEC.
*
* @name czm_getDefaultMaterial
* @glslFunction
*
* @param {czm_materialInput} input The input used to construct the default material.
*
* @returns {czm_material} The default material.
*
* @see czm_materialInput
* @see czm_material
* @see czm_getMaterial
*/
czm_material czm_getDefaultMaterial(czm_materialInput materialInput)
{
czm_material material;
material.diffuse = vec3(0.0);
material.specular = 0.0;
material.shininess = 1.0;
material.normal = materialInput.normalEC;
material.emission = vec3(0.0);
material.alpha = 1.0;
return material;
}
@@ -0,0 +1,29 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* An czm_material with default values. Every material's czm_getMaterial\n\
* should use this default material as a base for the material it returns.\n\
* The default normal value is given by materialInput.normalEC.\n\
*\n\
* @name czm_getDefaultMaterial\n\
* @glslFunction\n\
*\n\
* @param {czm_materialInput} input The input used to construct the default material.\n\
*\n\
* @returns {czm_material} The default material.\n\
*\n\
* @see czm_materialInput\n\
* @see czm_material\n\
* @see czm_getMaterial\n\
*/\n\
czm_material czm_getDefaultMaterial(czm_materialInput materialInput)\n\
{\n\
czm_material material;\n\
material.diffuse = vec3(0.0);\n\
material.specular = 0.0;\n\
material.shininess = 1.0;\n\
material.normal = materialInput.normalEC;\n\
material.emission = vec3(0.0);\n\
material.alpha = 1.0;\n\
return material;\n\
}\n\
";
@@ -0,0 +1,22 @@
/**
* Select which direction vector to use for dynamic atmosphere lighting based on an enum value
*
* @name czm_getDynamicAtmosphereLightDirection
* @glslfunction
* @see DynamicAtmosphereLightingType.js
*
* @param {vec3} positionWC the position of the vertex/fragment in world coordinates. This is normalized and returned when dynamic lighting is turned off.
* @param {float} lightEnum The enum value for selecting between light sources.
* @return {vec3} The normalized light direction vector. Depending on the enum value, it is either positionWC, czm_lightDirectionWC or czm_sunDirectionWC
*/
vec3 czm_getDynamicAtmosphereLightDirection(vec3 positionWC, float lightEnum) {
const float NONE = 0.0;
const float SCENE_LIGHT = 1.0;
const float SUNLIGHT = 2.0;
vec3 lightDirection =
positionWC * float(lightEnum == NONE) +
czm_lightDirectionWC * float(lightEnum == SCENE_LIGHT) +
czm_sunDirectionWC * float(lightEnum == SUNLIGHT);
return normalize(lightDirection);
}
@@ -0,0 +1,24 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Select which direction vector to use for dynamic atmosphere lighting based on an enum value\n\
*\n\
* @name czm_getDynamicAtmosphereLightDirection\n\
* @glslfunction\n\
* @see DynamicAtmosphereLightingType.js\n\
*\n\
* @param {vec3} positionWC the position of the vertex/fragment in world coordinates. This is normalized and returned when dynamic lighting is turned off.\n\
* @param {float} lightEnum The enum value for selecting between light sources.\n\
* @return {vec3} The normalized light direction vector. Depending on the enum value, it is either positionWC, czm_lightDirectionWC or czm_sunDirectionWC\n\
*/\n\
vec3 czm_getDynamicAtmosphereLightDirection(vec3 positionWC, float lightEnum) {\n\
const float NONE = 0.0;\n\
const float SCENE_LIGHT = 1.0;\n\
const float SUNLIGHT = 2.0;\n\
\n\
vec3 lightDirection =\n\
positionWC * float(lightEnum == NONE) +\n\
czm_lightDirectionWC * float(lightEnum == SCENE_LIGHT) +\n\
czm_sunDirectionWC * float(lightEnum == SUNLIGHT);\n\
return normalize(lightDirection);\n\
}\n\
";
@@ -0,0 +1,22 @@
/**
* Calculates the intensity of diffusely reflected light.
*
* @name czm_getLambertDiffuse
* @glslFunction
*
* @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.
* @param {vec3} normalEC The surface normal in eye coordinates.
*
* @returns {float} The intensity of the diffuse reflection.
*
* @see czm_phong
*
* @example
* float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC);
* float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200);
* vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity);
*/
float czm_getLambertDiffuse(vec3 lightDirectionEC, vec3 normalEC)
{
return max(dot(lightDirectionEC, normalEC), 0.0);
}
@@ -0,0 +1,24 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Calculates the intensity of diffusely reflected light.\n\
*\n\
* @name czm_getLambertDiffuse\n\
* @glslFunction\n\
*\n\
* @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\n\
* @param {vec3} normalEC The surface normal in eye coordinates.\n\
*\n\
* @returns {float} The intensity of the diffuse reflection.\n\
*\n\
* @see czm_phong\n\
*\n\
* @example\n\
* float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC);\n\
* float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200);\n\
* vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity);\n\
*/\n\
float czm_getLambertDiffuse(vec3 lightDirectionEC, vec3 normalEC)\n\
{\n\
return max(dot(lightDirectionEC, normalEC), 0.0);\n\
}\n\
";
@@ -0,0 +1,29 @@
/**
* Calculates the specular intensity of reflected light.
*
* @name czm_getSpecular
* @glslFunction
*
* @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.
* @param {vec3} toEyeEC Unit vector pointing to the eye position in eye coordinates.
* @param {vec3} normalEC The surface normal in eye coordinates.
* @param {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight.
*
* @returns {float} The intensity of the specular highlight.
*
* @see czm_phong
*
* @example
* float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC);
* float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200);
* vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity);
*/
float czm_getSpecular(vec3 lightDirectionEC, vec3 toEyeEC, vec3 normalEC, float shininess)
{
vec3 toReflectedLight = reflect(-lightDirectionEC, normalEC);
float specular = max(dot(toReflectedLight, toEyeEC), 0.0);
// pow has undefined behavior if both parameters <= 0.
// Prevent this by making sure shininess is at least czm_epsilon2.
return pow(specular, max(shininess, czm_epsilon2));
}
@@ -0,0 +1,31 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Calculates the specular intensity of reflected light.\n\
*\n\
* @name czm_getSpecular\n\
* @glslFunction\n\
*\n\
* @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\n\
* @param {vec3} toEyeEC Unit vector pointing to the eye position in eye coordinates.\n\
* @param {vec3} normalEC The surface normal in eye coordinates.\n\
* @param {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight.\n\
*\n\
* @returns {float} The intensity of the specular highlight.\n\
*\n\
* @see czm_phong\n\
*\n\
* @example\n\
* float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC);\n\
* float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200);\n\
* vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity);\n\
*/\n\
float czm_getSpecular(vec3 lightDirectionEC, vec3 toEyeEC, vec3 normalEC, float shininess)\n\
{\n\
vec3 toReflectedLight = reflect(-lightDirectionEC, normalEC);\n\
float specular = max(dot(toReflectedLight, toEyeEC), 0.0);\n\
\n\
// pow has undefined behavior if both parameters <= 0.\n\
// Prevent this by making sure shininess is at least czm_epsilon2.\n\
return pow(specular, max(shininess, czm_epsilon2));\n\
}\n\
";
@@ -0,0 +1,37 @@
/**
* @private
*/
vec4 czm_getWaterNoise(sampler2D normalMap, vec2 uv, float time, float angleInRadians)
{
float cosAngle = cos(angleInRadians);
float sinAngle = sin(angleInRadians);
// time dependent sampling directions
vec2 s0 = vec2(1.0/17.0, 0.0);
vec2 s1 = vec2(-1.0/29.0, 0.0);
vec2 s2 = vec2(1.0/101.0, 1.0/59.0);
vec2 s3 = vec2(-1.0/109.0, -1.0/57.0);
// rotate sampling direction by specified angle
s0 = vec2((cosAngle * s0.x) - (sinAngle * s0.y), (sinAngle * s0.x) + (cosAngle * s0.y));
s1 = vec2((cosAngle * s1.x) - (sinAngle * s1.y), (sinAngle * s1.x) + (cosAngle * s1.y));
s2 = vec2((cosAngle * s2.x) - (sinAngle * s2.y), (sinAngle * s2.x) + (cosAngle * s2.y));
s3 = vec2((cosAngle * s3.x) - (sinAngle * s3.y), (sinAngle * s3.x) + (cosAngle * s3.y));
vec2 uv0 = (uv/103.0) + (time * s0);
vec2 uv1 = uv/107.0 + (time * s1) + vec2(0.23);
vec2 uv2 = uv/vec2(897.0, 983.0) + (time * s2) + vec2(0.51);
vec2 uv3 = uv/vec2(991.0, 877.0) + (time * s3) + vec2(0.71);
uv0 = fract(uv0);
uv1 = fract(uv1);
uv2 = fract(uv2);
uv3 = fract(uv3);
vec4 noise = (texture(normalMap, uv0)) +
(texture(normalMap, uv1)) +
(texture(normalMap, uv2)) +
(texture(normalMap, uv3));
// average and scale to between -1 and 1
return ((noise / 4.0) - 0.5) * 2.0;
}
@@ -0,0 +1,39 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* @private\n\
*/\n\
vec4 czm_getWaterNoise(sampler2D normalMap, vec2 uv, float time, float angleInRadians)\n\
{\n\
float cosAngle = cos(angleInRadians);\n\
float sinAngle = sin(angleInRadians);\n\
\n\
// time dependent sampling directions\n\
vec2 s0 = vec2(1.0/17.0, 0.0);\n\
vec2 s1 = vec2(-1.0/29.0, 0.0);\n\
vec2 s2 = vec2(1.0/101.0, 1.0/59.0);\n\
vec2 s3 = vec2(-1.0/109.0, -1.0/57.0);\n\
\n\
// rotate sampling direction by specified angle\n\
s0 = vec2((cosAngle * s0.x) - (sinAngle * s0.y), (sinAngle * s0.x) + (cosAngle * s0.y));\n\
s1 = vec2((cosAngle * s1.x) - (sinAngle * s1.y), (sinAngle * s1.x) + (cosAngle * s1.y));\n\
s2 = vec2((cosAngle * s2.x) - (sinAngle * s2.y), (sinAngle * s2.x) + (cosAngle * s2.y));\n\
s3 = vec2((cosAngle * s3.x) - (sinAngle * s3.y), (sinAngle * s3.x) + (cosAngle * s3.y));\n\
\n\
vec2 uv0 = (uv/103.0) + (time * s0);\n\
vec2 uv1 = uv/107.0 + (time * s1) + vec2(0.23);\n\
vec2 uv2 = uv/vec2(897.0, 983.0) + (time * s2) + vec2(0.51);\n\
vec2 uv3 = uv/vec2(991.0, 877.0) + (time * s3) + vec2(0.71);\n\
\n\
uv0 = fract(uv0);\n\
uv1 = fract(uv1);\n\
uv2 = fract(uv2);\n\
uv3 = fract(uv3);\n\
vec4 noise = (texture(normalMap, uv0)) +\n\
(texture(normalMap, uv1)) +\n\
(texture(normalMap, uv2)) +\n\
(texture(normalMap, uv3));\n\
\n\
// average and scale to between -1 and 1\n\
return ((noise / 4.0) - 0.5) * 2.0;\n\
}\n\
";
+30
View File
@@ -0,0 +1,30 @@
/**
* Adjusts the hue of a color.
*
* @name czm_hue
* @glslFunction
*
* @param {vec3} rgb The color.
* @param {float} adjustment The amount to adjust the hue of the color in radians.
*
* @returns {float} The color with the hue adjusted.
*
* @example
* vec3 adjustHue = czm_hue(color, czm_pi); // The same as czm_hue(color, -czm_pi)
*/
vec3 czm_hue(vec3 rgb, float adjustment)
{
const mat3 toYIQ = mat3(0.299, 0.587, 0.114,
0.595716, -0.274453, -0.321263,
0.211456, -0.522591, 0.311135);
const mat3 toRGB = mat3(1.0, 0.9563, 0.6210,
1.0, -0.2721, -0.6474,
1.0, -1.107, 1.7046);
vec3 yiq = toYIQ * rgb;
float hue = atan(yiq.z, yiq.y) + adjustment;
float chroma = sqrt(yiq.z * yiq.z + yiq.y * yiq.y);
vec3 color = vec3(yiq.x, chroma * cos(hue), chroma * sin(hue));
return toRGB * color;
}
+32
View File
@@ -0,0 +1,32 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Adjusts the hue of a color.\n\
* \n\
* @name czm_hue\n\
* @glslFunction\n\
* \n\
* @param {vec3} rgb The color.\n\
* @param {float} adjustment The amount to adjust the hue of the color in radians.\n\
*\n\
* @returns {float} The color with the hue adjusted.\n\
*\n\
* @example\n\
* vec3 adjustHue = czm_hue(color, czm_pi); // The same as czm_hue(color, -czm_pi)\n\
*/\n\
vec3 czm_hue(vec3 rgb, float adjustment)\n\
{\n\
const mat3 toYIQ = mat3(0.299, 0.587, 0.114,\n\
0.595716, -0.274453, -0.321263,\n\
0.211456, -0.522591, 0.311135);\n\
const mat3 toRGB = mat3(1.0, 0.9563, 0.6210,\n\
1.0, -0.2721, -0.6474,\n\
1.0, -1.107, 1.7046);\n\
\n\
vec3 yiq = toYIQ * rgb;\n\
float hue = atan(yiq.z, yiq.y) + adjustment;\n\
float chroma = sqrt(yiq.z * yiq.z + yiq.y * yiq.y);\n\
\n\
vec3 color = vec3(yiq.x, chroma * cos(hue), chroma * sin(hue));\n\
return toRGB * color;\n\
}\n\
";
@@ -0,0 +1,12 @@
/**
* Converts a color in linear space to RGB space.
*
* @name czm_inverseGamma
* @glslFunction
*
* @param {vec3} color The color in linear space.
* @returns {vec3} The color in RGB space.
*/
vec3 czm_inverseGamma(vec3 color) {
return pow(color, vec3(1.0 / czm_gamma));
}
@@ -0,0 +1,14 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Converts a color in linear space to RGB space.\n\
*\n\
* @name czm_inverseGamma\n\
* @glslFunction\n\
*\n\
* @param {vec3} color The color in linear space.\n\
* @returns {vec3} The color in RGB space.\n\
*/\n\
vec3 czm_inverseGamma(vec3 color) {\n\
return pow(color, vec3(1.0 / czm_gamma));\n\
}\n\
";
@@ -0,0 +1,19 @@
/**
* Determines if a time interval is empty.
*
* @name czm_isEmpty
* @glslFunction
*
* @param {czm_raySegment} interval The interval to test.
*
* @returns {bool} <code>true</code> if the time interval is empty; otherwise, <code>false</code>.
*
* @example
* bool b0 = czm_isEmpty(czm_emptyRaySegment); // true
* bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false
* bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0.
*/
bool czm_isEmpty(czm_raySegment interval)
{
return (interval.stop < 0.0);
}
@@ -0,0 +1,21 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Determines if a time interval is empty.\n\
*\n\
* @name czm_isEmpty\n\
* @glslFunction \n\
* \n\
* @param {czm_raySegment} interval The interval to test.\n\
* \n\
* @returns {bool} <code>true</code> if the time interval is empty; otherwise, <code>false</code>.\n\
*\n\
* @example\n\
* bool b0 = czm_isEmpty(czm_emptyRaySegment); // true\n\
* bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false\n\
* bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0.\n\
*/\n\
bool czm_isEmpty(czm_raySegment interval)\n\
{\n\
return (interval.stop < 0.0);\n\
}\n\
";
@@ -0,0 +1,19 @@
/**
* Determines if a time interval is empty.
*
* @name czm_isFull
* @glslFunction
*
* @param {czm_raySegment} interval The interval to test.
*
* @returns {bool} <code>true</code> if the time interval is empty; otherwise, <code>false</code>.
*
* @example
* bool b0 = czm_isEmpty(czm_emptyRaySegment); // true
* bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false
* bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0.
*/
bool czm_isFull(czm_raySegment interval)
{
return (interval.start == 0.0 && interval.stop == czm_infinity);
}
+21
View File
@@ -0,0 +1,21 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Determines if a time interval is empty.\n\
*\n\
* @name czm_isFull\n\
* @glslFunction \n\
* \n\
* @param {czm_raySegment} interval The interval to test.\n\
* \n\
* @returns {bool} <code>true</code> if the time interval is empty; otherwise, <code>false</code>.\n\
*\n\
* @example\n\
* bool b0 = czm_isEmpty(czm_emptyRaySegment); // true\n\
* bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false\n\
* bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0.\n\
*/\n\
bool czm_isFull(czm_raySegment interval)\n\
{\n\
return (interval.start == 0.0 && interval.stop == czm_infinity);\n\
}\n\
";
@@ -0,0 +1,21 @@
/**
* Computes the fraction of a Web Wercator rectangle at which a given geodetic latitude is located.
*
* @name czm_latitudeToWebMercatorFraction
* @glslFunction
*
* @param {float} latitude The geodetic latitude, in radians.
* @param {float} southMercatorY The Web Mercator coordinate of the southern boundary of the rectangle.
* @param {float} oneOverMercatorHeight The total height of the rectangle in Web Mercator coordinates.
*
* @returns {float} The fraction of the rectangle at which the latitude occurs. If the latitude is the southern
* boundary of the rectangle, the return value will be zero. If it is the northern boundary, the return
* value will be 1.0. Latitudes in between are mapped according to the Web Mercator projection.
*/
float czm_latitudeToWebMercatorFraction(float latitude, float southMercatorY, float oneOverMercatorHeight)
{
float sinLatitude = sin(latitude);
float mercatorY = 0.5 * log((1.0 + sinLatitude) / (1.0 - sinLatitude));
return (mercatorY - southMercatorY) * oneOverMercatorHeight;
}
@@ -0,0 +1,23 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Computes the fraction of a Web Wercator rectangle at which a given geodetic latitude is located.\n\
*\n\
* @name czm_latitudeToWebMercatorFraction\n\
* @glslFunction\n\
*\n\
* @param {float} latitude The geodetic latitude, in radians.\n\
* @param {float} southMercatorY The Web Mercator coordinate of the southern boundary of the rectangle.\n\
* @param {float} oneOverMercatorHeight The total height of the rectangle in Web Mercator coordinates.\n\
*\n\
* @returns {float} The fraction of the rectangle at which the latitude occurs. If the latitude is the southern\n\
* boundary of the rectangle, the return value will be zero. If it is the northern boundary, the return\n\
* value will be 1.0. Latitudes in between are mapped according to the Web Mercator projection.\n\
*/ \n\
float czm_latitudeToWebMercatorFraction(float latitude, float southMercatorY, float oneOverMercatorHeight)\n\
{\n\
float sinLatitude = sin(latitude);\n\
float mercatorY = 0.5 * log((1.0 + sinLatitude) / (1.0 - sinLatitude));\n\
\n\
return (mercatorY - southMercatorY) * oneOverMercatorHeight;\n\
}\n\
";
@@ -0,0 +1,14 @@
/**
* Computes distance from an point in 2D to a line in 2D.
*
* @name czm_lineDistance
* @glslFunction
*
* param {vec2} point1 A point along the line.
* param {vec2} point2 A point along the line.
* param {vec2} point A point that may or may not be on the line.
* returns {float} The distance from the point to the line.
*/
float czm_lineDistance(vec2 point1, vec2 point2, vec2 point) {
return abs((point2.y - point1.y) * point.x - (point2.x - point1.x) * point.y + point2.x * point1.y - point2.y * point1.x) / distance(point2, point1);
}
@@ -0,0 +1,16 @@
//This file is automatically rebuilt by the Cesium build process.
export default "/**\n\
* Computes distance from an point in 2D to a line in 2D.\n\
*\n\
* @name czm_lineDistance\n\
* @glslFunction\n\
*\n\
* param {vec2} point1 A point along the line.\n\
* param {vec2} point2 A point along the line.\n\
* param {vec2} point A point that may or may not be on the line.\n\
* returns {float} The distance from the point to the line.\n\
*/\n\
float czm_lineDistance(vec2 point1, vec2 point2, vec2 point) {\n\
return abs((point2.y - point1.y) * point.x - (point2.x - point1.x) * point.y + point2.x * point1.y - point2.y * point1.x) / distance(point2, point1);\n\
}\n\
";

Some files were not shown because too many files have changed in this diff Show More