Advertisement
Rondeo

Libgdx OpenGL Shader for Water Reflection and blur

Mar 16th, 2023
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform sampler2D u_texture;  // Input texture
  2. uniform float u_time;         // Time since the start of the program
  3. uniform vec2 u_texelSize;     // Texel size of the input texture
  4.  
  5. varying vec2 v_texCoord0;
  6.  
  7. const float blurSize = 5.0;   // Size of the blur kernel
  8.  
  9. void main() {
  10.     vec2 uv = v_texCoord0;
  11.  
  12.     // First pass: horizontal blur
  13.     vec4 sum = vec4(0.0);
  14.     for (float i = -blurSize; i <= blurSize; i++) {
  15.         float offset = i * u_texelSize.x;
  16.         vec4 color = texture2D(u_texture, uv + vec2(offset, 0.0));
  17.         sum += color;
  18.     }
  19.     vec4 horizontalBlur = sum / (2.0 * blurSize + 1.0);
  20.  
  21.     // Second pass: vertical blur
  22.     sum = vec4(0.0);
  23.     for (float i = -blurSize; i <= blurSize; i++) {
  24.         float offset = i * u_texelSize.y;
  25.         vec4 color = texture2D(u_texture, uv + vec2(0.0, offset));
  26.         sum += color;
  27.     }
  28.     vec4 verticalBlur = sum / (2.0 * blurSize + 1.0);
  29.  
  30.     vec4 color = texture2D(u_texture, uv);  // Get input color
  31.     vec4 tintColor = vec4(1, 1, 1, 0.9);
  32.     vec4 tintedColor = color * tintColor;
  33.  
  34.     vec2 center = vec2(0.5, 0.5);
  35.     float distance = length(uv - center);
  36.     float amplitude = 0.01;
  37.     float frequency = 3.0;
  38.     float phase = u_time * frequency;
  39.     vec2 offset = vec2(cos(phase), sin(phase)) * amplitude * (1.0 - distance);
  40.  
  41.     vec4 finalColor = texture2D(u_texture, uv + offset) * tintColor;  // Get color at the offset texture coordinate
  42.     gl_FragColor = mix(finalColor, verticalBlur, 0.5);  // Output the final color, using a 50/50 mix of the offset color and the vertical blur
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement