Path.glsl.js 6.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{ForwardLinearDepth as e,addNearFar as i}from"../views/3d/webgl-engine/core/shaderLibrary/ForwardLinearDepth.glsl.js";import{ShaderOutput as o}from"../views/3d/webgl-engine/core/shaderLibrary/ShaderOutput.js";import{SliceDraw as a}from"../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js";import{Transform as r}from"../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl.js";import{PathVertexPosition as l}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/PathVertexPosition.glsl.js";import{OutputDepth as s}from"../views/3d/webgl-engine/core/shaderLibrary/output/OutputDepth.glsl.js";import{OutputHighlight as n}from"../views/3d/webgl-engine/core/shaderLibrary/output/OutputHighlight.glsl.js";import{EvaluateAmbientOcclusion as d}from"../views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateAmbientOcclusion.glsl.js";import{EvaluateSceneLighting as t,addAmbientBoostFactor as c,addLightingGlobalFactor as g}from"../views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateSceneLighting.glsl.js";import{addMainLightIntensity as m}from"../views/3d/webgl-engine/core/shaderLibrary/shading/MainLighting.glsl.js";import{multipassTerrainTest as p}from"../views/3d/webgl-engine/core/shaderLibrary/shading/MultipassTerrainTest.glsl.js";import{Normals as v}from"../views/3d/webgl-engine/core/shaderLibrary/shading/Normals.glsl.js";import{NormalUtils as h}from"../views/3d/webgl-engine/core/shaderLibrary/shading/NormalUtils.glsl.js";import{ReadShadowMapDraw as u}from"../views/3d/webgl-engine/core/shaderLibrary/shading/ReadShadowMap.glsl.js";import{ColorConversion as w}from"../views/3d/webgl-engine/core/shaderLibrary/util/ColorConversion.glsl.js";import{addProjViewLocalOrigin as b,addViewNormal as f,addCameraPosition as y}from"../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js";import{Float3PassUniform as j}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{FloatPassUniform as L}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as P}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{ShaderBuilder as S}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{TransparencyPassType as C}from"../views/3d/webgl-engine/lib/TransparencyPassType.js";function F(F){const _=new S,{vertex:M,fragment:O}=_;switch(b(M,F),_.varyings.add("vpos","vec3"),_.include(l,F),F.output!==o.Color&&F.output!==o.Alpha||(_.include(r,F),_.include(u,F),_.include(e,F),_.varyings.add("vnormal","vec3"),_.varyings.add("vcolor","vec4"),F.hasMultipassTerrain&&_.varyings.add("depth","float"),M.code.add(P`
  6. void main() {
  7. vpos = calculateVPos();
  8. vnormal = normalize(localNormal());
  9. ${F.hasMultipassTerrain?"depth = (view * vec4(vpos, 1.0)).z;":""}
  10. gl_Position = transformPosition(proj, view, vpos);
  11. ${F.output===o.Color?"forwardLinearDepth();":""}
  12. vcolor = getColor();
  13. }
  14. `)),_.include(p,F),F.output){case o.Alpha:_.include(a,F),O.uniforms.add(new L("opacity",(e=>e.opacity))),O.code.add(P`
  15. void main() {
  16. discardBySlice(vpos);
  17. ${F.hasMultipassTerrain?"terrainDepthTest(gl_FragCoord, depth);":""}
  18. float combinedOpacity = vcolor.a * opacity;
  19. gl_FragColor = vec4(combinedOpacity);
  20. }
  21. `);break;case o.Color:_.include(a,F),_.include(t,F),_.include(d,F),_.include(u,F),_.include(v,F),y(O,F),c(O),g(O),O.uniforms.add([M.uniforms.get("localOrigin"),new j("ambient",(e=>e.ambient)),new j("diffuse",(e=>e.diffuse)),new j("specular",(e=>e.specular)),new L("opacity",(e=>e.opacity))]),O.include(w),m(O),O.code.add(P`
  22. void main() {
  23. discardBySlice(vpos);
  24. ${F.hasMultipassTerrain?"terrainDepthTest(gl_FragCoord, depth);":""}
  25. shadingParams.viewDirection = normalize(vpos - cameraPosition);
  26. shadingParams.normalView = vnormal;
  27. vec3 normal = shadingNormal(shadingParams);
  28. float ssao = evaluateAmbientOcclusionInverse();
  29. float additionalAmbientScale = additionalDirectedAmbientLight(vpos + localOrigin);
  30. vec3 additionalLight = ssao * mainLightIntensity * additionalAmbientScale * ambientBoostFactor * lightingGlobalFactor;
  31. ${F.receiveShadows?"float shadow = readShadowMap(vpos, linearDepth);":F.spherical?"float shadow = lightingGlobalFactor * (1.0 - additionalAmbientScale);":"float shadow = 0.0;"}
  32. vec3 albedo = vcolor.rgb * max(ambient, diffuse); // combine the old material parameters into a single one
  33. float combinedOpacity = vcolor.a * opacity;
  34. albedo += 0.25 * specular; // don't completely ignore specular for now
  35. vec3 shadedColor = evaluateSceneLighting(normal, albedo, shadow, 1.0 - ssao, additionalLight);
  36. gl_FragColor = vec4(shadedColor, combinedOpacity);
  37. gl_FragColor = highlightSlice(gl_FragColor, vpos);
  38. ${F.transparencyPassType===C.Color?"gl_FragColor = premultiplyAlpha(gl_FragColor);":""}
  39. }
  40. `);break;case o.Depth:case o.Shadow:case o.ShadowHighlight:case o.ShadowExludeHighlight:_.include(r,F),i(_),_.varyings.add("depth","float"),M.code.add(P`void main() {
  41. vpos = calculateVPos();
  42. gl_Position = transformPositionWithDepth(proj, view, vpos, nearFar, depth);
  43. }`),_.include(a,F),_.include(s,F),O.code.add(P`void main() {
  44. discardBySlice(vpos);
  45. outputDepth(depth);
  46. }`);break;case o.Normal:_.include(r,F),_.include(h,F),f(M),_.varyings.add("vnormal","vec3"),M.code.add(P`void main(void) {
  47. vpos = calculateVPos();
  48. vnormal = normalize((viewNormal * vec4(localNormal(), 1.0)).xyz);
  49. gl_Position = transformPosition(proj, view, vpos);
  50. }`),_.include(a,F),O.code.add(P`void main() {
  51. discardBySlice(vpos);
  52. vec3 normal = normalize(vnormal);
  53. if (gl_FrontFacing == false) normal = -normal;
  54. gl_FragColor = vec4(vec3(0.5) + 0.5 * normal, 1.0);
  55. }`);break;case o.Highlight:_.include(r,F),_.include(h,F),_.varyings.add("vnormal","vec3"),M.code.add(P`void main(void) {
  56. vpos = calculateVPos();
  57. gl_Position = transformPosition(proj, view, vpos);
  58. }`),_.include(a,F),_.include(n,F),O.code.add(P`void main() {
  59. discardBySlice(vpos);
  60. outputHighlight();
  61. }`)}return _}const _=Object.freeze(Object.defineProperty({__proto__:null,build:F},Symbol.toStringTag,{value:"Module"}));export{_ as P,F as b};