QWater.fp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //===========================================================================
  2. //
  3. // Quake-style Water Shader
  4. // Written by Jason Allen Doucette
  5. // Source: https://www.shadertoy.com/view/MsKXzD
  6. //
  7. //===========================================================================
  8. #define WARPSPEED 2.0
  9. // the amount of shearing (shifting of a single column or row)
  10. // 1.0 = entire screen height offset (to both sides, meaning it's 2.0 in total)
  11. #define XDISTMAG 0.05
  12. #define YDISTMAG 0.05
  13. // cycle multiplier for a given screen height
  14. // 2 * PI = you see a complete sine wave from top .. bottom
  15. #define XSINECYCLES 6.28
  16. #define YSINECYCLES 6.28
  17. void SetupMaterial(inout Material mat)
  18. {
  19. vec2 texCoord = vTexCoord.st;
  20. // the value for the sine has 2 inputs:
  21. // 1. the time, so that it animates.
  22. // 2. the y-row, so that ALL scanlines do not distort equally.
  23. float time = timer * WARPSPEED;
  24. float xAngle = time + texCoord.y * YSINECYCLES;
  25. float yAngle = time + texCoord.x * XSINECYCLES;
  26. vec2 distortOffset =
  27. vec2(sin(xAngle), sin(yAngle)) * // amount of shearing
  28. vec2(XDISTMAG, YDISTMAG); // magnitude adjustment
  29. // shear the coordinates
  30. texCoord += distortOffset;
  31. mat.Base = getTexel(texCoord);
  32. mat.Normal = ApplyNormalMap(texCoord);
  33. #if defined(SPECULAR)
  34. mat.Specular = texture(speculartexture, texCoord).rgb;
  35. mat.Glossiness = uSpecularMaterial.x;
  36. mat.SpecularLevel = uSpecularMaterial.y;
  37. #endif
  38. #if defined(PBR)
  39. mat.Metallic = texture(metallictexture, texCoord).r;
  40. mat.Roughness = texture(roughnesstexture, texCoord).r;
  41. mat.AO = texture(aotexture, texCoord).r;
  42. #endif
  43. mat.Bright = texture(brighttexture, texCoord);
  44. }