/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl

https://bitbucket.org/lindenlab/viewer-beta/ · GLSL · 99 lines · 48 code · 21 blank · 30 comment · 0 complexity · d6a5304653895a180449d59a7dcac1df MD5 · raw file

  1. /**
  2. * @file waterV.glsl
  3. *
  4. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2007, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. uniform mat4 modelview_matrix;
  26. uniform mat4 modelview_projection_matrix;
  27. ATTRIBUTE vec3 position;
  28. void calcAtmospherics(vec3 inPositionEye);
  29. uniform vec2 d1;
  30. uniform vec2 d2;
  31. uniform float time;
  32. uniform vec3 eyeVec;
  33. uniform float waterHeight;
  34. VARYING vec4 refCoord;
  35. VARYING vec4 littleWave;
  36. VARYING vec4 view;
  37. VARYING vec4 vary_position;
  38. float wave(vec2 v, float t, float f, vec2 d, float s)
  39. {
  40. return (dot(d, v)*f + t*s)*f;
  41. }
  42. void main()
  43. {
  44. //transform vertex
  45. vec4 pos = vec4(position.xyz, 1.0);
  46. mat4 modelViewProj = modelview_projection_matrix;
  47. vec4 oPosition;
  48. //get view vector
  49. vec3 oEyeVec;
  50. oEyeVec.xyz = pos.xyz-eyeVec;
  51. float d = length(oEyeVec.xy);
  52. float ld = min(d, 2560.0);
  53. pos.xy = eyeVec.xy + oEyeVec.xy/d*ld;
  54. view.xyz = oEyeVec;
  55. d = clamp(ld/1536.0-0.5, 0.0, 1.0);
  56. d *= d;
  57. oPosition = vec4(position, 1.0);
  58. oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d);
  59. vary_position = modelview_matrix * oPosition;
  60. oPosition = modelViewProj * oPosition;
  61. refCoord.xyz = oPosition.xyz + vec3(0,0,0.2);
  62. //get wave position parameter (create sweeping horizontal waves)
  63. vec3 v = pos.xyz;
  64. v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0;
  65. //push position for further horizon effect.
  66. pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z);
  67. pos.w = 1.0;
  68. pos = modelview_matrix*pos;
  69. calcAtmospherics(pos.xyz);
  70. //pass wave parameters to pixel shader
  71. vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055;
  72. //get two normal map (detail map) texture coordinates
  73. littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13;
  74. littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1;
  75. view.w = bigWave.y;
  76. refCoord.w = bigWave.x;
  77. gl_Position = oPosition;
  78. }