@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
69 lines (60 loc) • 4.55 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{neverReached as o}from"../../../../../../../core/compilerUtils.js";import{packFloatRGBA as e}from"../../../../../../../core/floatRGBA.js";import{DecodeSymbolColor as r}from"./DecodeSymbolColor.glsl.js";import{ShaderOutput as t}from"../../../../core/shaderLibrary/ShaderOutput.js";import{RgbaFloatEncoding as n}from"../../../../core/shaderLibrary/util/RgbaFloatEncoding.glsl.js";import{Float4DrawUniform as a}from"../../../../core/shaderModules/Float4DrawUniform.js";import{glsl as d,If as l}from"../../../../core/shaderModules/glsl.js";import{IntegerDrawUniform as c}from"../../../../core/shaderModules/IntegerDrawUniform.js";import{Texture2DDrawUniform as i}from"../../../../core/shaderModules/Texture2DDrawUniform.js";import{olidEnabled as s}from"../../../../effects/geometry/olidUtils.js";import{VertexAttribute as x}from"../../../../lib/VertexAttribute.js";var C;!function(o){o[o.Uniform=0]="Uniform",o[o.Varying=1]="Varying",o[o.COUNT=2]="COUNT"}(C||(C={}));const m=429496.7296;function f(o,r){e(o/m*.5+.5,r)}function u(e,r){switch(r.componentData){case C.Varying:return v(e,r);case C.Uniform:return p(e,r);case C.COUNT:return;default:o(r.componentData)}}function v(o,e){const{vertex:a,fragment:l}=o;a.include(n),a.uniforms.add(new i("componentColorTex",(o=>o.componentParameters.texture.texture))),o.attributes.add(x.COMPONENTINDEX,"float"),o.varyings.add("vExternalColorMixMode","mediump float"),o.varyings.add("vExternalColor","vec4");const c=e.output===t.ObjectAndLayerIdColor;c&&o.varyings.add("vObjectAndLayerIdColor","vec4"),o.include(r),a.constants.add("stride","float",s()?3:2),a.code.add(d`vec2 getComponentTextureCoordinates(float componentIndex, float typeOffset) {
float index = componentIndex * stride + typeOffset;
float texSize = float(textureSize(componentColorTex, 0).x);
float coordX = mod(index, texSize);
float coordY = floor(index / texSize);
return vec2(coordX, coordY) + 0.5;
}`),a.code.add(d`
vec4 _readComponentColor() {
vec2 textureCoordinates = getComponentTextureCoordinates(componentIndex, 0.0);
return texelFetch(componentColorTex, ivec2(textureCoordinates), 0);
}
float readElevationOffset() {
vec2 textureCoordinates = getComponentTextureCoordinates(componentIndex, 1.0);
vec4 encodedElevation = texelFetch(componentColorTex, ivec2(textureCoordinates), 0);
return uninterpolatedRGBAToFloat(encodedElevation) * ${d.float(m)};
}
${c?d`
void forwardObjectAndLayerIdColor() {
vec2 textureCoordinates = getComponentTextureCoordinates(componentIndex, 2.0);
vObjectAndLayerIdColor = texelFetch(componentColorTex, ivec2(textureCoordinates), 0);
}`:d`void forwardObjectAndLayerIdColor() {}`}
vec4 forwardExternalColor(out bool castShadows) {
vec4 componentColor = _readComponentColor() * 255.0;
float shadowFlag = mod(componentColor.b * 255.0, 2.0);
componentColor.b -= shadowFlag;
castShadows = shadowFlag >= 1.0;
int decodedColorMixMode;
vExternalColor = decodeSymbolColor(componentColor, decodedColorMixMode) * 0.003921568627451; // = 1/255;
vExternalColorMixMode = float(decodedColorMixMode) + 0.5; // add 0.5 to avoid interpolation artifacts
return vExternalColor;
}
`),l.code.add(d`
void readExternalColor(out vec4 externalColor, out int externalColorMixMode) {
externalColor = vExternalColor;
externalColorMixMode = int(vExternalColorMixMode);
}
void outputObjectAndLayerIdColor() {
${c?d`fragColor = vObjectAndLayerIdColor;`:""}
}
`)}function p(o,e){const{vertex:r,fragment:n}=o;o.varyings.add("vExternalColor","vec4"),r.uniforms.add(new a("externalColor",(o=>o.componentParameters.externalColor))).code.add(d`float readElevationOffset() {
return 0.0;
}
void forwardObjectAndLayerIdColor() {}
vec4 forwardExternalColor(out bool castShadows) {
vExternalColor = externalColor;
castShadows = true;
return externalColor;
}`);const i=e.output===t.ObjectAndLayerIdColor;n.uniforms.add(new c("externalColorMixMode",(o=>o.componentParameters.externalColorMixMode))).code.add(d`
void readExternalColor(out vec4 color, out int colorMixMode) {
color = vExternalColor;
colorMixMode = externalColorMixMode;
}
void outputObjectAndLayerIdColor() {
${l(i,"fragColor = vec4(0, 0, 0, 0);")}
}
`)}export{u as ComponentData,C as ComponentDataType,f as encodeElevationOffset,m as maxElevationOffset};