common-frag-params.glsl.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. export const common_frag_params = `
  2. uniform int uObjectId;
  3. uniform int uInstanceCount;
  4. uniform int uGroupCount;
  5. uniform int uPickType;
  6. uniform int uMarkingType;
  7. #if dClipObjectCount != 0
  8. uniform int uClipObjectType[dClipObjectCount];
  9. uniform bool uClipObjectInvert[dClipObjectCount];
  10. uniform vec3 uClipObjectPosition[dClipObjectCount];
  11. uniform vec4 uClipObjectRotation[dClipObjectCount];
  12. uniform vec3 uClipObjectScale[dClipObjectCount];
  13. #if defined(dClipping)
  14. #if __VERSION__ == 100 || defined(dClippingType_instance) || !defined(dVaryingGroup)
  15. varying float vClipping;
  16. #else
  17. flat in float vClipping;
  18. #endif
  19. #endif
  20. #endif
  21. #if defined(dColorMarker)
  22. uniform vec3 uHighlightColor;
  23. uniform vec3 uSelectColor;
  24. uniform float uHighlightStrength;
  25. uniform float uSelectStrength;
  26. uniform int uMarkerPriority;
  27. #endif
  28. #if defined(dNeedsMarker)
  29. uniform float uMarker;
  30. #if __VERSION__ == 100 || defined(dMarkerType_instance) || !defined(dVaryingGroup)
  31. varying float vMarker;
  32. #else
  33. flat in float vMarker;
  34. #endif
  35. #endif
  36. varying vec3 vModelPosition;
  37. varying vec3 vViewPosition;
  38. uniform vec2 uViewOffset;
  39. uniform float uNear;
  40. uniform float uFar;
  41. uniform float uIsOrtho;
  42. uniform float uFogNear;
  43. uniform float uFogFar;
  44. uniform vec3 uFogColor;
  45. uniform float uAlpha;
  46. uniform float uPickingAlphaThreshold;
  47. uniform bool uTransparentBackground;
  48. uniform bool uDoubleSided;
  49. uniform float uInteriorDarkening;
  50. uniform bool uInteriorColorFlag;
  51. uniform vec3 uInteriorColor;
  52. bool interior;
  53. uniform float uXrayEdgeFalloff;
  54. uniform mat4 uProjection;
  55. uniform int uRenderMask;
  56. uniform bool uMarkingDepthTest;
  57. uniform sampler2D tDepth;
  58. uniform vec2 uDrawingBufferSize;
  59. float getDepthPacked(const in vec2 coords) {
  60. return unpackRGBAToDepth(texture2D(tDepth, coords));
  61. }
  62. float getDepth(const in vec2 coords) {
  63. #ifdef depthTextureSupport
  64. return texture2D(tDepth, coords).r;
  65. #else
  66. return unpackRGBAToDepth(texture2D(tDepth, coords));
  67. #endif
  68. }
  69. float calcDepth(const in vec3 pos) {
  70. vec2 clipZW = pos.z * uProjection[2].zw + uProjection[3].zw;
  71. return 0.5 + 0.5 * clipZW.x / clipZW.y;
  72. }
  73. // "Bump Mapping Unparametrized Surfaces on the GPU" Morten S. Mikkelsen
  74. // https://mmikk.github.io/papers3d/mm_sfgrad_bump.pdf
  75. vec3 perturbNormal(in vec3 position, in vec3 normal, in float height, in float scale) {
  76. vec3 sigmaS = dFdx(position);
  77. vec3 sigmaT = dFdy(position);
  78. vec3 r1 = cross(sigmaT, normal);
  79. vec3 r2 = cross(normal, sigmaS);
  80. float det = dot(sigmaS, r1);
  81. float bs = dFdx(height);
  82. float bt = dFdy(height);
  83. vec3 surfGrad = sign(det) * (bs * r1 + bt * r2);
  84. return normalize(abs(det) * normal - scale * surfGrad);
  85. }
  86. float hash(in float h) {
  87. return fract(sin(h) * 43758.5453123);
  88. }
  89. float noise(in vec3 x) {
  90. vec3 p = floor(x);
  91. vec3 f = fract(x);
  92. f = f * f * (3.0 - 2.0 * f);
  93. float n = p.x + p.y * 157.0 + 113.0 * p.z;
  94. return mix(
  95. mix(mix(hash(n + 0.0), hash(n + 1.0), f.x),
  96. mix(hash(n + 157.0), hash(n + 158.0), f.x), f.y),
  97. mix(mix(hash(n + 113.0), hash(n + 114.0), f.x),
  98. mix(hash(n + 270.0), hash(n + 271.0), f.x), f.y), f.z);
  99. }
  100. float fbm(in vec3 p) {
  101. float f = 0.0;
  102. f += 0.5 * noise(p);
  103. p *= 2.01;
  104. f += 0.25 * noise(p);
  105. p *= 2.02;
  106. f += 0.125 * noise(p);
  107. return f;
  108. }
  109. `;