PointRenderer.glsl.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{ShaderOutput as e}from"../views/3d/webgl-engine/core/shaderLibrary/ShaderOutputOptions.js";import{SliceDraw as i}from"../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js";import{OutputHighlight as o}from"../views/3d/webgl-engine/core/shaderLibrary/output/OutputHighlight.glsl.js";import{RgbaFloatEncoding as r}from"../views/3d/webgl-engine/core/shaderLibrary/util/RgbaFloatEncoding.glsl.js";import{Float2PassUniform as t}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{Float2Uniform as n}from"../views/3d/webgl-engine/core/shaderModules/Float2Uniform.js";import{Float3Uniform as a}from"../views/3d/webgl-engine/core/shaderModules/Float3Uniform.js";import{glsl as s}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{Matrix4PassUniform as d}from"../views/3d/webgl-engine/core/shaderModules/Matrix4PassUniform.js";import{Matrix4Uniform as l}from"../views/3d/webgl-engine/core/shaderModules/Matrix4Uniform.js";import{ShaderBuilder as c}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{VertexAttribute as p}from"../views/3d/webgl-engine/lib/VertexAttribute.js";function m(m){const f=new c,g=m.output===e.Color,u=m.output===e.Depth,v=m.output===e.Highlight,{vertex:w,fragment:S}=f;return f.extensions.add("GL_OES_standard_derivatives"),f.include(i,m),f.attributes.add(p.POSITION,"vec3"),f.attributes.add(p.COLOR,"vec3"),w.uniforms.add(new l("modelView")),w.uniforms.add(new d("proj",((e,i)=>i.camera.projectionMatrix))),w.uniforms.add(new n("screenMinMaxSize")),w.uniforms.add(new n("pointScale")),w.uniforms.add(new a("clipMin")),w.uniforms.add(new a("clipMax")),u?(w.uniforms.add(new t("nearFar",((e,i)=>i.camera.nearFar))),f.varyings.add("depth","float")):m.output!==e.Highlight&&f.varyings.add("vColor","vec3"),w.code.add(s`
  6. void main(void) {
  7. // Move clipped points outside of clipspace
  8. if (position.x < clipMin.x || position.y < clipMin.y || position.z < clipMin.z ||
  9. position.x > clipMax.x || position.y > clipMax.y || position.z > clipMax.z) {
  10. gl_Position = vec4(0.0,0.0,0.0,2.0);
  11. gl_PointSize = 0.0;
  12. return;
  13. }
  14. if (rejectBySlice(position)) {
  15. gl_Position = vec4(0.0,0.0,0.0,2.0);
  16. gl_PointSize = 0.0;
  17. return;
  18. }
  19. // Position in camera space
  20. vec4 camera = modelView * vec4(position, 1.0);
  21. float pointSize = pointScale.x;
  22. vec4 position = proj * camera;
  23. ${m.drawScreenSize?s`
  24. float clampedScreenSize = pointSize;`:s`
  25. float pointRadius = 0.5 * pointSize;
  26. vec4 cameraOffset = camera + vec4(0.0, pointRadius, 0.0, 0.0);
  27. vec4 positionOffset = proj * cameraOffset;
  28. float radius = abs(positionOffset.y - position.y);
  29. float viewHeight = pointScale.y;
  30. // screen diameter = (2 * r / w) * (h / 2)
  31. float screenPointSize = (radius / position.w) * viewHeight;
  32. float clampedScreenSize = clamp(screenPointSize, screenMinMaxSize.x, screenMinMaxSize.y);
  33. // Shift towards camera, to move rendered point out of terrain i.e. to
  34. // the camera-facing end of the virtual point when considering it as a
  35. // 3D sphere.
  36. camera.xyz -= normalize(camera.xyz) * pointRadius * clampedScreenSize / screenPointSize;
  37. position = proj * camera;`}
  38. gl_PointSize = clampedScreenSize;
  39. gl_Position = position;
  40. ${u?s`depth = (-camera.z - nearFar[0]) / (nearFar[1] - nearFar[0]);`:""}
  41. ${g?s`vColor = color;`:""}
  42. }
  43. `),S.include(r,m),v&&f.include(o),S.code.add(s`
  44. void main(void) {
  45. vec2 vOffset = gl_PointCoord - vec2(0.5, 0.5);
  46. float r2 = dot(vOffset, vOffset);
  47. if (r2 > 0.25) {
  48. discard;
  49. }
  50. ${u?s`gl_FragColor = float2rgba(depth);`:""}
  51. ${v?s`outputHighlight();`:""}
  52. ${g?s`gl_FragColor = vec4(vColor, 1.0);`:""}
  53. }
  54. `),f}const f=Object.freeze(Object.defineProperty({__proto__:null,build:m},Symbol.toStringTag,{value:"Module"}));export{f as P,m as b};