PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

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