PageRenderTime 131ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 110 lines | 91 code | 19 blank | 0 comment | 0 complexity | a7b1c19e84ed5bcfc917b1ffb88105e2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file underWaterF.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. #ifdef DEFINE_GL_FRAGCOLOR
  26. out vec4 gl_FragColor;
  27. #endif
  28. uniform sampler2D diffuseMap;
  29. uniform sampler2D bumpMap;
  30. uniform sampler2D screenTex;
  31. uniform sampler2D refTex;
  32. uniform sampler2D screenDepth;
  33. uniform vec4 fogCol;
  34. uniform vec3 lightDir;
  35. uniform vec3 specular;
  36. uniform float lightExp;
  37. uniform vec2 fbScale;
  38. uniform float refScale;
  39. uniform float znear;
  40. uniform float zfar;
  41. uniform float kd;
  42. uniform vec4 waterPlane;
  43. uniform vec3 eyeVec;
  44. uniform vec4 waterFogColor;
  45. uniform float waterFogDensity;
  46. uniform float waterFogKS;
  47. uniform vec2 screenRes;
  48. //bigWave is (refCoord.w, view.w);
  49. VARYING vec4 refCoord;
  50. VARYING vec4 littleWave;
  51. VARYING vec4 view;
  52. vec4 applyWaterFog(vec4 color, vec3 viewVec)
  53. {
  54. //normalize view vector
  55. vec3 view = normalize(viewVec);
  56. float es = -view.z;
  57. //find intersection point with water plane and eye vector
  58. //get eye depth
  59. float e0 = max(-waterPlane.w, 0.0);
  60. //get object depth
  61. float depth = length(viewVec);
  62. //get "thickness" of water
  63. float l = max(depth, 0.1);
  64. float kd = waterFogDensity;
  65. float ks = waterFogKS;
  66. vec4 kc = waterFogColor;
  67. float F = 0.98;
  68. float t1 = -kd * pow(F, ks * e0);
  69. float t2 = kd + ks * es;
  70. float t3 = pow(F, t2*l) - 1.0;
  71. float L = min(t1/t2*t3, 1.0);
  72. float D = pow(0.98, l*kd);
  73. //return vec4(1.0, 0.0, 1.0, 1.0);
  74. return color * D + kc * L;
  75. //depth /= 10.0;
  76. //return vec4(depth,depth,depth,0.0);
  77. }
  78. void main()
  79. {
  80. vec4 color;
  81. //get detail normals
  82. vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
  83. vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
  84. vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
  85. vec3 wavef = normalize(wave1+wave2+wave3);
  86. //figure out distortion vector (ripply)
  87. vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
  88. distort = distort+wavef.xy*refScale;
  89. vec4 fb = texture2D(screenTex, distort);
  90. gl_FragColor = applyWaterFog(fb,view.xyz);
  91. }