Guest User

Untitled

a guest
Jul 23rd, 2026
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. const vertShader = `
  2. precision highp float;
  3. attribute vec3 aPosition;
  4. attribute vec2 aTexCoord;
  5. varying vec2 vTexCoord;
  6.  
  7. void main() {
  8. vTexCoord = aTexCoord;
  9. vec4 positionVec4 = vec4(aPosition, 1.0);
  10. positionVec4.xy = positionVec4.xy * 2.0 - 1.0;
  11. gl_Position = positionVec4;
  12. }
  13. `;
  14.  
  15. const fragShader = `
  16. precision highp float;
  17. varying vec2 vTexCoord;
  18. uniform vec2 u_resolution;
  19. uniform float u_time;
  20.  
  21. // 2D Random pseudo-number generator
  22. vec2 random2(vec2 st){
  23. st = vec2(dot(st,vec2(127.1,311.7)), dot(st,vec2(269.5,183.3)));
  24. return -1.0 + 2.0*fract(sin(st)*43758.5453123);
  25. }
  26.  
  27. // 2D Noise function
  28. float noise(vec2 st) {
  29. vec2 i = floor(st);
  30. vec2 f = fract(st);
  31. vec2 u = f*f*(3.0-2.0*f);
  32. return mix( mix( dot( random2(i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),
  33. dot( random2(i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),
  34. mix( dot( random2(i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),
  35. dot( random2(i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);
  36. }
  37.  
  38. // Fractional Brownian Motion (fBm) with a "ridge" modifier for web-like cracks
  39. float ridgeFBM(vec2 uv) {
  40. float total = 0.0;
  41. float amp = 0.6;
  42. float freq = 2.0;
  43.  
  44. // Diagonal flow matrix
  45. mat2 m = mat2( 0.80, 0.60, -0.60, 0.80 );
  46.  
  47. for(int i = 0; i < 5; i++) {
  48. // Calculate noise and invert it to get sharp ridges
  49. float n = noise(uv * freq + u_time * 0.15);
  50. n = 1.0 - abs(n); // sharp ridges
  51. n = n * n; // sharpen falloff, makes lines thinner
  52.  
  53. total += n * amp;
  54.  
  55. uv = m * uv; // rotate for organic diagonal variation
  56. freq *= 2.0;
  57. amp *= 0.5;
  58. }
  59. return total;
  60. }
  61.  
  62. // Smooth undulating noise for the underlying water/bed geometry
  63. float smoothFBM(vec2 uv) {
  64. float total = 0.0;
  65. float amp = 0.5;
  66. float freq = 1.0;
  67. for(int i = 0; i < 3; i++) {
  68. total += noise(uv * freq - u_time * 0.05) * amp;
  69. freq *= 2.0;
  70. amp *= 0.5;
  71. }
  72. return total;
  73. }
  74.  
  75. void main() {
  76. vec2 uv = gl_FragCoord.xy / u_resolution.xy;
  77.  
  78. // Correct aspect ratio
  79. uv.x *= u_resolution.x / u_resolution.y;
  80.  
  81. // Apply global diagonal rotation to the coordinates
  82. // to match the top-left to bottom-right flow in the video
  83. float angle = 0.785398; // ~45 degrees
  84. mat2 rot = mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
  85. vec2 rotatedUV = rot * uv;
  86.  
  87. // Stretch the UVs slightly on one axis to create long striations
  88. rotatedUV.x *= 0.5;
  89. rotatedUV.y *= 1.5;
  90.  
  91. // Generate patterns
  92. float smoothVolume = smoothFBM(rotatedUV * 1.5);
  93. float ridges = ridgeFBM(rotatedUV * 1.2);
  94.  
  95. // Color Palette based on the video (Deep dark greens to pale teal)
  96. vec3 darkGreen = vec3(0.04, 0.14, 0.13);
  97. vec3 midGreen = vec3(0.09, 0.28, 0.26);
  98. vec3 lightTeal = vec3(0.2, 0.45, 0.42);
  99. vec3 brightCaustic = vec3(0.5, 0.7, 0.65);
  100.  
  101. // Light gradient across the screen (light source top left)
  102. float gradientLight = smoothstep(1.5, -0.5, uv.x + uv.y);
  103.  
  104. // Mix base colors using the smooth background noise
  105. vec3 color = mix(darkGreen, midGreen, smoothVolume + 0.5);
  106.  
  107. // Add light direction gradient
  108. color = mix(color, lightTeal, gradientLight * 0.5 * (smoothVolume + 0.5));
  109.  
  110. // Overlay the sharp ridged caustics
  111. // The ridges are multiplied by the gradient light so they fade out into the dark shadows
  112. float causticMask = smoothstep(0.1, 1.2, ridges) * (gradientLight + 0.2);
  113. color = mix(color, brightCaustic, causticMask * 0.8);
  114.  
  115. gl_FragColor = vec4(color, 1.0);
  116. }
  117. `;
  118.  
  119. let organicShader;
  120.  
  121. function setup() {
  122. createCanvas(windowWidth, windowHeight, WEBGL);
  123. organicShader = createShader(vertShader, fragShader);
  124. noStroke();
  125. }
  126.  
  127. function draw() {
  128. shader(organicShader);
  129.  
  130. // Send uniforms (variables) to the shader
  131. organicShader.setUniform('u_resolution', [width, height]);
  132. organicShader.setUniform('u_time', millis() / 1000.0);
  133.  
  134. // Draw a rectangle over the whole canvas to display the shader
  135. rect(0, 0, width, height);
  136. }
  137.  
  138. function windowResized() {
  139. resizeCanvas(windowWidth, windowHeight);
  140. }
Advertisement
Add Comment
Please, Sign In to add comment