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

/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 102 lines | 84 code | 18 blank | 0 comment | 0 complexity | c187219f2aa540f28674f8f939d40f98 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file WLCloudsF.glsl
  3. *
  4. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2005, 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. /////////////////////////////////////////////////////////////////////////
  29. // The fragment shader for the sky
  30. /////////////////////////////////////////////////////////////////////////
  31. VARYING vec4 vary_CloudColorSun;
  32. VARYING vec4 vary_CloudColorAmbient;
  33. VARYING float vary_CloudDensity;
  34. VARYING vec2 vary_texcoord0;
  35. VARYING vec2 vary_texcoord1;
  36. VARYING vec2 vary_texcoord2;
  37. VARYING vec2 vary_texcoord3;
  38. uniform sampler2D cloud_noise_texture;
  39. uniform vec4 cloud_pos_density1;
  40. uniform vec4 cloud_pos_density2;
  41. uniform vec4 gamma;
  42. /// Soft clips the light with a gamma correction
  43. vec3 scaleSoftClip(vec3 light) {
  44. //soft clip effect:
  45. light = 1. - clamp(light, vec3(0.), vec3(1.));
  46. light = 1. - pow(light, gamma.xxx);
  47. return light;
  48. }
  49. void main()
  50. {
  51. // Set variables
  52. vec2 uv1 = vary_texcoord0.xy;
  53. vec2 uv2 = vary_texcoord1.xy;
  54. vec4 cloudColorSun = vary_CloudColorSun;
  55. vec4 cloudColorAmbient = vary_CloudColorAmbient;
  56. float cloudDensity = vary_CloudDensity;
  57. vec2 uv3 = vary_texcoord2.xy;
  58. vec2 uv4 = vary_texcoord3.xy;
  59. // Offset texture coords
  60. uv1 += cloud_pos_density1.xy; //large texture, visible density
  61. uv2 += cloud_pos_density1.xy; //large texture, self shadow
  62. uv3 += cloud_pos_density2.xy; //small texture, visible density
  63. uv4 += cloud_pos_density2.xy; //small texture, self shadow
  64. // Compute alpha1, the main cloud opacity
  65. float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z;
  66. alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.);
  67. // And smooth
  68. alpha1 = 1. - alpha1 * alpha1;
  69. alpha1 = 1. - alpha1 * alpha1;
  70. // Compute alpha2, for self shadowing effect
  71. // (1 - alpha2) will later be used as percentage of incoming sunlight
  72. float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5);
  73. alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.);
  74. // And smooth
  75. alpha2 = 1. - alpha2;
  76. alpha2 = 1. - alpha2 * alpha2;
  77. // Combine
  78. vec4 color;
  79. color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient);
  80. color *= 2.;
  81. /// Gamma correct for WL (soft clip effect).
  82. gl_FragColor.rgb = scaleSoftClip(color.rgb);
  83. gl_FragColor.a = alpha1;
  84. }