@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
61 lines (52 loc) • 4.07 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{DecodeSymbolColor as o}from"./DecodeSymbolColor.glsl.js";import{TextureBackedBufferModule as e}from"../../../core/shaderLibrary/TextureBackedBuffer.glsl.js";import{Float4DrawUniform as r}from"../../../core/shaderModules/Float4DrawUniform.js";import{FloatDrawUniform as t}from"../../../core/shaderModules/FloatDrawUniform.js";import{glsl as d,If as n}from"../../../core/shaderModules/glsl.js";import{IntegerDrawUniform as a}from"../../../core/shaderModules/IntegerDrawUniform.js";import{Texture2DUintDrawUniform as l}from"../../../core/shaderModules/Texture2DUintDrawUniform.js";import{olidEnabled as i}from"../../../effects/geometry/olidUtils.js";import{componentDataLayout as s,componentDataOlidLayout as c}from"../../../materials/DefaultLayouts.js";function u(o,e){switch(e.componentDataType){case 1:return p(o,e);case 0:return M(o,e);case 2:return;default:e.componentDataType}}const m=(o,e)=>"emissiveSourceMode"===o||"emissiveStrength"===o?e.hasEmission:"olidColor"!==o||9===e.output,f=new l("componentTextureBuffer",o=>o.textureBackedBuffer?.texture),v=new e({layout:s,itemIndexAttribute:"componentIndex",bufferUniform:f,fieldFilter:m}),C=new e({layout:c,itemIndexAttribute:"componentIndex",bufferUniform:f,fieldFilter:m});function x(){return i()?C:v}function p(e,r){const{vertex:t,fragment:a}=e,{output:l,hasEmission:i}=r,s=9===l,{getTextureAttribute:c,TextureBackedBufferModule:u}=x();e.include(u,r),e.attributes.add("componentIndex","uint"),e.varyings.add("vExternalColorMixMode","mediump float"),e.varyings.add("vExternalColor","vec4"),s&&e.varyings.add("vObjectAndLayerIdColor","vec4"),i&&(e.varyings.add("emissiveStrength","float"),e.varyings.add("emissiveSource","int")),e.include(o),t.code.add(d`
float readElevationOffset() {
return ${c("elevationOffset")};
}
void forwardEmissiveStrength() {
${n(i,d`emissiveStrength = ${c("emissiveStrength")};
emissiveSource = ${c("emissiveSourceMode")} == 0u ? 0 : 1;`)}
}
void forwardObjectAndLayerIdColor() {
${n(s,d`vObjectAndLayerIdColor = vec4(${c("olidColor")})/255.0;`)}
}
void decodeColorAndCastShadow(uvec4 colorAndCastShadowEncoded, out vec4 color, out bool castShadow) {
uvec4 componentColor = colorAndCastShadowEncoded;
castShadow = bool(componentColor.b & 1u);
componentColor.b = componentColor.b & 254u;
color = vec4(componentColor);
}
vec4 forwardExternalColor(out bool castShadows) {
vec4 componentColor;
decodeColorAndCastShadow(${c("colorAndCastShadows")}, componentColor, castShadows);
int decodedColorMixMode;
vExternalColor = decodeSymbolColor(componentColor, decodedColorMixMode) * 0.003921568627451; // = 1/255;
vExternalColorMixMode = float(decodedColorMixMode) + 0.5; // add 0.5 to avoid interpolation artifacts
return vExternalColor;
}
`),a.code.add(d`
void readExternalColor(out vec4 externalColor, out int externalColorMixMode) {
externalColor = vExternalColor;
externalColorMixMode = int(vExternalColorMixMode);
}
void outputObjectAndLayerIdColor() {
${s?d`fragColor = vObjectAndLayerIdColor;`:""}
}
`)}function M(o,e){const{vertex:l,fragment:i}=o;o.varyings.add("vExternalColor","vec4"),i.uniforms.add(new t("emissiveStrength",o=>o.componentParameters.emissiveStrength)),l.uniforms.add(new r("externalColor",o=>o.componentParameters.externalColor)).code.add(d`float readElevationOffset() {
return 0.0;
}
void forwardObjectAndLayerIdColor() {}
void forwardEmissiveStrength() {}
vec4 forwardExternalColor(out bool castShadows) {
vExternalColor = externalColor;
castShadows = true;
return externalColor;
}`);const s=9===e.output;i.uniforms.add(new a("externalColorMixMode",o=>o.componentParameters.externalColorMixMode)).code.add(d`
void readExternalColor(out vec4 color, out int colorMixMode) {
color = vExternalColor;
colorMixMode = externalColorMixMode;
}
void outputObjectAndLayerIdColor() {
${n(s,"fragColor = vec4(0, 0, 0, 0);")}
}
`)}export{u as ComponentData};