waterpp.frag 644 B

1234567891011121314151617181920
  1. void main()
  2. {
  3. if (waterFactor > 0)
  4. {
  5. float tau = 6.28318530717958647692;
  6. vec2 texSize = textureSize(InputTexture, 0);
  7. // offset the pixel location by this amount, a sine wave to create a wobble effect
  8. vec2 waterOffset = vec2(waterFactor * sin(tau * TexCoord.y + timer * 0.05), waterFactor * sin(tau * TexCoord.x + timer * 0.05));
  9. vec2 coord = TexCoord + waterOffset;
  10. // return black if the resulting coord isn't on screen
  11. vec4 color = (coord.x > 0 && coord.x < 1 && coord.y > 0 && coord.y < 1) ?
  12. texture(InputTexture, coord) : vec4(0, 0, 0, 0);
  13. FragColor = color;
  14. }
  15. else FragColor = texture(InputTexture, TexCoord);
  16. }