PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 74 lines | 56 code | 18 blank | 0 comment | 0 complexity | 5e859600284378b77fef504557e91351 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file waterFogF.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 vec4 lightnorm;
  26. uniform vec4 waterPlane;
  27. uniform vec4 waterFogColor;
  28. uniform float waterFogDensity;
  29. uniform float waterFogKS;
  30. vec3 getPositionEye();
  31. vec4 applyWaterFog(vec4 color)
  32. {
  33. //normalize view vector
  34. vec3 view = normalize(getPositionEye());
  35. float es = -(dot(view, waterPlane.xyz));
  36. //find intersection point with water plane and eye vector
  37. //get eye depth
  38. float e0 = max(-waterPlane.w, 0.0);
  39. vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0);
  40. //get object depth
  41. float depth = length(getPositionEye() - int_v);
  42. //get "thickness" of water
  43. float l = max(depth, 0.1);
  44. float kd = waterFogDensity;
  45. float ks = waterFogKS;
  46. vec4 kc = waterFogColor;
  47. float F = 0.98;
  48. float t1 = -kd * pow(F, ks * e0);
  49. float t2 = kd + ks * es;
  50. float t3 = pow(F, t2*l) - 1.0;
  51. float L = min(t1/t2*t3, 1.0);
  52. float D = pow(0.98, l*kd);
  53. color.rgb = color.rgb * D + kc.rgb * L;
  54. color.a = kc.a + color.a;
  55. return color;
  56. }