PageRenderTime 41ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 96 lines | 77 code | 19 blank | 0 comment | 0 complexity | d0ac84c7215b0afb2959346be87bbe81 MD5 | raw file
Possible License(s): LGPL-2.1
  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. float wave(vec2 v, float t, float f, vec2 d, float s)
  38. {
  39. return (dot(d, v)*f + t*s)*f;
  40. }
  41. void main()
  42. {
  43. //transform vertex
  44. mat4 modelViewProj = modelview_projection_matrix;
  45. vec4 oPosition;
  46. //get view vector
  47. vec3 oEyeVec;
  48. oEyeVec.xyz = position.xyz-eyeVec;
  49. float d = length(oEyeVec.xy);
  50. float ld = min(d, 2560.0);
  51. vec3 lpos = position;
  52. lpos.xy = eyeVec.xy + oEyeVec.xy/d*ld;
  53. view.xyz = oEyeVec;
  54. d = clamp(ld/1536.0-0.5, 0.0, 1.0);
  55. d *= d;
  56. oPosition = vec4(lpos, 1.0);
  57. oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d);
  58. oPosition = modelViewProj * oPosition;
  59. refCoord.xyz = oPosition.xyz + vec3(0,0,0.2);
  60. //get wave position parameter (create sweeping horizontal waves)
  61. vec3 v = lpos;
  62. v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0;
  63. //push position for further horizon effect.
  64. vec4 pos;
  65. pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z);
  66. pos.w = 1.0;
  67. pos = modelview_matrix*pos;
  68. calcAtmospherics(pos.xyz);
  69. //pass wave parameters to pixel shader
  70. vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055;
  71. //get two normal map (detail map) texture coordinates
  72. littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13;
  73. littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1;
  74. view.w = bigWave.y;
  75. refCoord.w = bigWave.x;
  76. gl_Position = oPosition;
  77. }