PageRenderTime 149ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 190 lines | 148 code | 42 blank | 0 comment | 0 complexity | 299afdf2035a04d65bae746bf389e070 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file WLCloudsV.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. uniform mat4 modelview_projection_matrix;
  26. ATTRIBUTE vec3 position;
  27. ATTRIBUTE vec2 texcoord0;
  28. //////////////////////////////////////////////////////////////////////////
  29. // The vertex shader for creating the atmospheric sky
  30. ///////////////////////////////////////////////////////////////////////////////
  31. // Output parameters
  32. VARYING vec4 vary_CloudColorSun;
  33. VARYING vec4 vary_CloudColorAmbient;
  34. VARYING float vary_CloudDensity;
  35. VARYING vec2 vary_texcoord0;
  36. VARYING vec2 vary_texcoord1;
  37. VARYING vec2 vary_texcoord2;
  38. VARYING vec2 vary_texcoord3;
  39. // Inputs
  40. uniform vec3 camPosLocal;
  41. uniform vec4 lightnorm;
  42. uniform vec4 sunlight_color;
  43. uniform vec4 ambient;
  44. uniform vec4 blue_horizon;
  45. uniform vec4 blue_density;
  46. uniform vec4 haze_horizon;
  47. uniform vec4 haze_density;
  48. uniform vec4 cloud_shadow;
  49. uniform vec4 density_multiplier;
  50. uniform vec4 max_y;
  51. uniform vec4 glow;
  52. uniform vec4 cloud_color;
  53. uniform vec4 cloud_scale;
  54. void main()
  55. {
  56. // World / view / projection
  57. gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
  58. vary_texcoord0 = texcoord0;
  59. // Get relative position
  60. vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0);
  61. // Set altitude
  62. if (P.y > 0.)
  63. {
  64. P *= (max_y.x / P.y);
  65. }
  66. else
  67. {
  68. P *= (-32000. / P.y);
  69. }
  70. // Can normalize then
  71. vec3 Pn = normalize(P);
  72. float Plen = length(P);
  73. // Initialize temp variables
  74. vec4 temp1 = vec4(0.);
  75. vec4 temp2 = vec4(0.);
  76. vec4 blue_weight;
  77. vec4 haze_weight;
  78. vec4 sunlight = sunlight_color;
  79. vec4 light_atten;
  80. // Sunlight attenuation effect (hue and brightness) due to atmosphere
  81. // this is used later for sunlight modulation at various altitudes
  82. light_atten = (blue_density * 1.0 + haze_density.x * 0.25) * (density_multiplier.x * max_y.x);
  83. // Calculate relative weights
  84. temp1 = blue_density + haze_density.x;
  85. blue_weight = blue_density / temp1;
  86. haze_weight = haze_density.x / temp1;
  87. // Compute sunlight from P & lightnorm (for long rays like sky)
  88. temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y );
  89. temp2.y = 1. / temp2.y;
  90. sunlight *= exp( - light_atten * temp2.y);
  91. // Distance
  92. temp2.z = Plen * density_multiplier.x;
  93. // Transparency (-> temp1)
  94. // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati
  95. // compiler gets confused.
  96. temp1 = exp(-temp1 * temp2.z);
  97. // Compute haze glow
  98. temp2.x = dot(Pn, lightnorm.xyz);
  99. temp2.x = 1. - temp2.x;
  100. // temp2.x is 0 at the sun and increases away from sun
  101. temp2.x = max(temp2.x, .001);
  102. // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
  103. temp2.x *= glow.x;
  104. // Higher glow.x gives dimmer glow (because next step is 1 / "angle")
  105. temp2.x = pow(temp2.x, glow.z);
  106. // glow.z should be negative, so we're doing a sort of (1 / "angle") function
  107. // Add "minimum anti-solar illumination"
  108. temp2.x += .25;
  109. // Increase ambient when there are more clouds
  110. vec4 tmpAmbient = ambient;
  111. tmpAmbient += (1. - tmpAmbient) * cloud_shadow.x * 0.5;
  112. // Dim sunlight by cloud shadow percentage
  113. sunlight *= (1. - cloud_shadow.x);
  114. // Haze color below cloud
  115. vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient)
  116. + (haze_horizon.r * haze_weight) * (sunlight * temp2.x + tmpAmbient)
  117. );
  118. // CLOUDS
  119. sunlight = sunlight_color;
  120. temp2.y = max(0., lightnorm.y * 2.);
  121. temp2.y = 1. / temp2.y;
  122. sunlight *= exp( - light_atten * temp2.y);
  123. // Cloud color out
  124. vary_CloudColorSun = (sunlight * temp2.x) * cloud_color;
  125. vary_CloudColorAmbient = tmpAmbient * cloud_color;
  126. // Attenuate cloud color by atmosphere
  127. temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds
  128. vary_CloudColorSun *= temp1;
  129. vary_CloudColorAmbient *= temp1;
  130. vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1);
  131. // Make a nice cloud density based on the cloud_shadow value that was passed in.
  132. vary_CloudDensity = 2. * (cloud_shadow.x - 0.25);
  133. // Texture coords
  134. vary_texcoord0 = texcoord0;
  135. vary_texcoord0.xy -= 0.5;
  136. vary_texcoord0.xy /= cloud_scale.x;
  137. vary_texcoord0.xy += 0.5;
  138. vary_texcoord1 = vary_texcoord0;
  139. vary_texcoord1.x += lightnorm.x * 0.0125;
  140. vary_texcoord1.y += lightnorm.z * 0.0125;
  141. vary_texcoord2 = vary_texcoord0 * 16.;
  142. vary_texcoord3 = vary_texcoord1 * 16.;
  143. // Combine these to minimize register use
  144. vary_CloudColorAmbient += oHazeColorBelowCloud;
  145. // needs this to compile on mac
  146. //vary_AtmosAttenuation = vec3(0.0,0.0,0.0);
  147. // END CLOUDS
  148. }