gaussian-density.frag.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author Michael Krone <michael.krone@uni-tuebingen.de>
  6. */
  7. export const gaussianDensity_frag = `
  8. precision highp float;
  9. varying vec3 vPosition;
  10. varying float vRadiusSqInv;
  11. #if defined(dCalcType_groupId)
  12. #if defined(dGridTexType_2d)
  13. precision highp sampler2D;
  14. uniform sampler2D tMinDistanceTex;
  15. uniform vec3 uGridTexDim;
  16. #elif defined(dGridTexType_3d)
  17. precision highp sampler3D;
  18. uniform sampler3D tMinDistanceTex;
  19. #endif
  20. varying float vGroup;
  21. #endif
  22. #include common
  23. uniform vec3 uGridDim;
  24. uniform vec2 uGridTexScale;
  25. uniform float uCurrentSlice;
  26. uniform float uCurrentX;
  27. uniform float uCurrentY;
  28. uniform float uAlpha;
  29. uniform float uResolution;
  30. uniform float uRadiusFactorInv;
  31. void main() {
  32. vec2 v = gl_FragCoord.xy - vec2(uCurrentX, uCurrentY) - 0.5;
  33. vec3 fragPos = vec3(v.x, v.y, uCurrentSlice);
  34. float dist = distance(fragPos, vPosition) * uResolution;
  35. #if defined(dCalcType_density)
  36. float density = exp(-uAlpha * ((dist * dist) * vRadiusSqInv));
  37. gl_FragColor.a = density * uRadiusFactorInv;
  38. #elif defined(dCalcType_minDistance)
  39. gl_FragColor.a = 1.0 - dist * uRadiusFactorInv;
  40. #elif defined(dCalcType_groupId)
  41. #if defined(dGridTexType_2d)
  42. float minDistance = 1.0 - texture2D(tMinDistanceTex, (gl_FragCoord.xy) / (uGridTexDim.xy / uGridTexScale)).a;
  43. #elif defined(dGridTexType_3d)
  44. float minDistance = 1.0 - texelFetch(tMinDistanceTex, ivec3(gl_FragCoord.xy, uCurrentSlice), 0).a;
  45. #endif
  46. if (dist * uRadiusFactorInv > minDistance + uResolution * 0.05)
  47. discard;
  48. gl_FragColor.rgb = packIntToRGB(vGroup);
  49. #endif
  50. }
  51. `;