Water.vert 1.1 KB

123456789101112131415161718192021222324252627282930
  1. #include "Uniforms.vert"
  2. #include "Transform.vert"
  3. #include "ScreenPos.vert"
  4. varying vec4 vScreenPos;
  5. varying vec2 vReflectUV;
  6. varying vec2 vWaterUV;
  7. varying vec3 vNormal;
  8. varying vec4 vEyeVec;
  9. uniform vec2 cNoiseSpeed;
  10. uniform float cNoiseTiling;
  11. void main()
  12. {
  13. mat4 modelMatrix = iModelMatrix;
  14. vec3 worldPos = GetWorldPos(modelMatrix);
  15. gl_Position = GetClipPos(worldPos);
  16. vScreenPos = GetScreenPos(gl_Position);
  17. // GetQuadTexCoord() returns a vec2 that is OK for quad rendering; multiply it with output W
  18. // coordinate to make it work with arbitrary meshes such as the water plane (perform divide in pixel shader)
  19. // Also because the quadTexCoord is based on the clip position, and Y is flipped when rendering to a texture
  20. // on OpenGL, must flip again to cancel it out
  21. vReflectUV = GetQuadTexCoord(gl_Position);
  22. vReflectUV.y = 1.0 - vReflectUV.y;
  23. vReflectUV *= gl_Position.w;
  24. vWaterUV = iTexCoord * cNoiseTiling + cElapsedTime * cNoiseSpeed;
  25. vNormal = GetWorldNormal(modelMatrix);
  26. vEyeVec = vec4(cCameraPos - worldPos, GetDepth(gl_Position));
  27. }