UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

74 lines (64 loc) • 9.5 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{ForwardLinearDepth as e}from"../views/3d/webgl-engine/core/shaderLibrary/ForwardLinearDepth.glsl.js";import{Offset as r}from"../views/3d/webgl-engine/core/shaderLibrary/Offset.glsl.js";import{isColorOrColorEmission as o}from"../views/3d/webgl-engine/core/shaderLibrary/ShaderOutput.js";import{SliceDraw as i}from"../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js";import{Transform as a}from"../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl.js";import{InstancedDoublePrecision as l}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/InstancedDoublePrecision.glsl.js";import{NormalAttribute as s,NormalType as n}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/NormalAttribute.glsl.js";import{PositionAttribute as t}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/PositionAttribute.glsl.js";import{SymbolColor as d}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/SymbolColor.glsl.js";import{TextureCoordinateAttribute as c}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/TextureCoordinateAttribute.glsl.js";import{VertexColor as m}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/VertexColor.glsl.js";import{VertexNormal as g}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/VertexNormal.glsl.js";import{VerticalOffset as v}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/VerticalOffset.glsl.js";import{DefaultMaterialAuxiliaryPasses as u}from"../views/3d/webgl-engine/core/shaderLibrary/default/DefaultMaterialAuxiliaryPasses.glsl.js";import{ComputeNormalTexture as b}from"../views/3d/webgl-engine/core/shaderLibrary/shading/ComputeNormalTexture.glsl.js";import{EvaluateAmbientOcclusion as w}from"../views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateAmbientOcclusion.glsl.js";import{EvaluateSceneLighting as h,addAmbientBoostFactor as p,addLightingGlobalFactor as f}from"../views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateSceneLighting.glsl.js";import{addMainLightIntensity as x}from"../views/3d/webgl-engine/core/shaderLibrary/shading/MainLighting.glsl.js";import{Normals as y}from"../views/3d/webgl-engine/core/shaderLibrary/shading/Normals.glsl.js";import{PhysicallyBasedRendering as L}from"../views/3d/webgl-engine/core/shaderLibrary/shading/PhysicallyBasedRendering.glsl.js";import{PhysicallyBasedRenderingParameters as C,PBRMode as j}from"../views/3d/webgl-engine/core/shaderLibrary/shading/PhysicallyBasedRenderingParameters.glsl.js";import{ReadShadowMapPass as P,ReadShadowMapDraw as O}from"../views/3d/webgl-engine/core/shaderLibrary/shading/ReadShadowMap.glsl.js";import{terrainDepthTest as N}from"../views/3d/webgl-engine/core/shaderLibrary/shading/TerrainDepthTest.glsl.js";import{colorTextureUV as S,normalTextureUV as T,emissiveTextureUV as A,occlusionTextureUV as V,metallicRoughnessTextureUV as M}from"../views/3d/webgl-engine/core/shaderLibrary/shading/TextureTransformUV.glsl.js";import{VisualVariables as $}from"../views/3d/webgl-engine/core/shaderLibrary/shading/VisualVariables.glsl.js";import{DiscardOrAdjustAlphaPass as D}from"../views/3d/webgl-engine/core/shaderLibrary/util/DiscardOrAdjustAlpha.glsl.js";import{MixExternalColor as E}from"../views/3d/webgl-engine/core/shaderLibrary/util/MixExternalColor.glsl.js";import{addProjViewLocalOrigin as U,addCameraPosition as B}from"../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js";import{Float3PassUniform as I}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{Float4PassUniform as F}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{FloatPassUniform as _}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as R,If as z}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{Texture2DPassUniform as G}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{VertexAttribute as W}from"../views/3d/webgl-engine/lib/VertexAttribute.js";import{outputColorHighlightOID as k}from"../views/3d/webgl-engine/shaders/OutputColorHighlightOID.glsl.js";import{ShaderBuilder as H}from"../views/webgl/ShaderBuilder.js";import{alphaCutoff as q}from"../webscene/support/AlphaCutoff.js";function J(J){const K=new H,{vertex:Q,fragment:X,varyings:Y}=K,{output:Z,normalType:ee,offsetBackfaces:re,instancedColor:oe,spherical:ie,receiveShadows:ae,snowCover:le,pbrMode:se,textureAlphaPremultiplied:ne,instancedDoublePrecision:te,hasVertexColors:de,hasVertexTangents:ce,hasColorTexture:me,hasNormalTexture:ge,hasNormalTextureTransform:ve,hasColorTextureTransform:ue}=J;if(U(Q,J),K.include(t),Y.add("vpos","vec3"),K.include($,J),K.include(l,J),K.include(v,J),K.include(S,J),!o(Z))return K.include(u,J),K;K.include(T,J),K.include(A,J),K.include(V,J),K.include(M,J),B(Q,J),K.include(s,J),K.include(a,J);const be=ee===n.Attribute||ee===n.Compressed;return be&&re&&K.include(r),K.include(b,J),K.include(g,J),oe&&K.attributes.add(W.INSTANCECOLOR,"vec4"),Y.add("vPositionLocal","vec3"),K.include(c,J),K.include(e,J),K.include(d,J),K.include(m,J),Q.uniforms.add(new F("externalColor",(e=>e.externalColor))),Y.add("vcolorExt","vec4"),K.include(N,J),Q.main.add(R` forwardNormalizedVertexColor(); vcolorExt = externalColor; ${z(oe,"vcolorExt *= instanceColor * 0.003921568627451;")} vcolorExt *= vvColor(); vcolorExt *= getSymbolColor(); forwardColorMixMode(); vpos = getVertexInLocalOriginSpace(); vPositionLocal = vpos - view[3].xyz; vpos = subtractOrigin(vpos); ${z(be,"vNormalWorld = dpNormal(vvLocalNormal(normalModel()));")} vpos = addVerticalOffset(vpos, localOrigin); ${z(ce,"vTangent = dpTransformVertexTangent(tangent);")} gl_Position = transformPosition(proj, view, vpos); ${z(be&&re,"gl_Position = offsetBackfacingClipPosition(gl_Position, vpos, vNormalWorld, cameraPosition);")} forwardViewPosDepth((view * vec4(vpos, 1.0)).xyz); forwardLinearDepth(); forwardTextureCoordinates(); forwardColorUV(); forwardNormalUV(); forwardEmissiveUV(); forwardOcclusionUV(); forwardMetallicRoughnessUV(); if (vcolorExt.a < ${R.float(q)}) { gl_Position = vec4(1e38, 1e38, 1e38, 1.0); } `),K.include(h,J),K.include(w,J),K.include(D,J),K.include(te?P:O,J),K.fragment.include(i,J),K.include(k,J),B(X,J),X.uniforms.add(Q.uniforms.get("localOrigin"),new I("ambient",(e=>e.ambient)),new I("diffuse",(e=>e.diffuse)),new _("opacity",(e=>e.opacity)),new _("layerOpacity",(e=>e.layerOpacity))),me&&X.uniforms.add(new G("tex",(e=>e.texture))),K.include(C,J),K.include(L,J),X.include(E),K.include(y,J),p(X),f(X),x(X),X.main.add(R` discardBySlice(vpos); discardByTerrainDepth(); ${me?R` vec4 texColor = texture(tex, ${ue?"colorUV":"vuv0"}); ${z(ne,"texColor.rgb /= texColor.a;")} discardOrAdjustAlpha(texColor);`:R`vec4 texColor = vec4(1.0);`} shadingParams.viewDirection = normalize(vpos - cameraPosition); ${ee===n.ScreenDerivative?R`vec3 normal = screenDerivativeNormal(vPositionLocal);`:R`shadingParams.normalView = vNormalWorld; vec3 normal = shadingNormal(shadingParams);`} applyPBRFactors(); float ssao = evaluateAmbientOcclusionInverse() * getBakedOcclusion(); vec3 posWorld = vpos + localOrigin; float additionalAmbientScale = additionalDirectedAmbientLight(posWorld); float shadow = ${ae?"max(lightingGlobalFactor * (1.0 - additionalAmbientScale), readShadowMap(vpos, linearDepth))":z(ie,"lightingGlobalFactor * (1.0 - additionalAmbientScale)","0.0")}; vec3 matColor = max(ambient, diffuse); vec3 albedo = mixExternalColor(${z(de,"vColor.rgb *")} matColor, texColor.rgb, vcolorExt.rgb, int(colorMixMode)); float opacity_ = layerOpacity * mixExternalOpacity(${z(de,"vColor.a * ")} opacity, texColor.a, vcolorExt.a, int(colorMixMode)); ${ge?`mat3 tangentSpace = computeTangentSpace(${ce?"normal":"normal, vpos, vuv0"});\n vec3 shadingNormal = computeTextureNormal(tangentSpace, ${ve?"normalUV":"vuv0"});`:"vec3 shadingNormal = normal;"} vec3 normalGround = ${ie?"normalize(posWorld);":"vec3(0.0, 0.0, 1.0);"} ${z(le,R` float snow = smoothstep(0.5, 0.55, dot(normal, normalGround)); albedo = mix(albedo, vec3(1), snow); shadingNormal = mix(shadingNormal, normal, snow); ssao = mix(ssao, 1.0, snow);`)} vec3 additionalLight = ssao * mainLightIntensity * additionalAmbientScale * ambientBoostFactor * lightingGlobalFactor; ${se===j.Normal||se===j.Schematic?R` float additionalAmbientIrradiance = additionalAmbientIrradianceFactor * mainLightIntensity[2]; ${z(le,R`mrr = mix(mrr, vec3(0.0, 1.0, 0.04), snow);`)} vec4 emission = ${le?"mix(getEmissions(), vec4(0.0), snow)":"getEmissions()"}; vec3 shadedColor = evaluateSceneLightingPBR(shadingNormal, albedo, shadow, 1.0 - ssao, additionalLight, shadingParams.viewDirection, normalGround, mrr, emission, additionalAmbientIrradiance);`:R`vec3 shadedColor = evaluateSceneLighting(shadingNormal, albedo, shadow, 1.0 - ssao, additionalLight);`} vec4 finalColor = vec4(shadedColor, opacity_); outputColorHighlightOID(finalColor, vpos); `),K}const K=Object.freeze(Object.defineProperty({__proto__:null,build:J},Symbol.toStringTag,{value:"Module"}));export{K as D,J as b};