PageRenderTime 23ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 159 lines | 123 code | 36 blank | 0 comment | 0 complexity | 5cf08164aa7bd6df597aacafccc6ec51 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file WLSkyV.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. // SKY ////////////////////////////////////////////////////////////////////////
  28. // The vertex shader for creating the atmospheric sky
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // Output parameters
  31. VARYING vec4 vary_HazeColor;
  32. // Inputs
  33. uniform vec3 camPosLocal;
  34. uniform vec4 lightnorm;
  35. uniform vec4 sunlight_color;
  36. uniform vec4 ambient;
  37. uniform vec4 blue_horizon;
  38. uniform vec4 blue_density;
  39. uniform vec4 haze_horizon;
  40. uniform vec4 haze_density;
  41. uniform vec4 cloud_shadow;
  42. uniform vec4 density_multiplier;
  43. uniform vec4 max_y;
  44. uniform vec4 glow;
  45. uniform vec4 cloud_color;
  46. uniform vec4 cloud_scale;
  47. void main()
  48. {
  49. // World / view / projection
  50. gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
  51. // Get relative position
  52. vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0);
  53. //vec3 P = position.xyz + vec3(0,50,0);
  54. // Set altitude
  55. if (P.y > 0.)
  56. {
  57. P *= (max_y.x / P.y);
  58. }
  59. else
  60. {
  61. P *= (-32000. / P.y);
  62. }
  63. // Can normalize then
  64. vec3 Pn = normalize(P);
  65. float Plen = length(P);
  66. // Initialize temp variables
  67. vec4 temp1 = vec4(0.);
  68. vec4 temp2 = vec4(0.);
  69. vec4 blue_weight;
  70. vec4 haze_weight;
  71. vec4 sunlight = sunlight_color;
  72. vec4 light_atten;
  73. // Sunlight attenuation effect (hue and brightness) due to atmosphere
  74. // this is used later for sunlight modulation at various altitudes
  75. light_atten = (blue_density * 1.0 + haze_density.x * 0.25) * (density_multiplier.x * max_y.x);
  76. // Calculate relative weights
  77. temp1 = blue_density + haze_density.x;
  78. blue_weight = blue_density / temp1;
  79. haze_weight = haze_density.x / temp1;
  80. // Compute sunlight from P & lightnorm (for long rays like sky)
  81. temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y );
  82. temp2.y = 1. / temp2.y;
  83. sunlight *= exp( - light_atten * temp2.y);
  84. // Distance
  85. temp2.z = Plen * density_multiplier.x;
  86. // Transparency (-> temp1)
  87. // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati
  88. // compiler gets confused.
  89. temp1 = exp(-temp1 * temp2.z);
  90. // Compute haze glow
  91. temp2.x = dot(Pn, lightnorm.xyz);
  92. temp2.x = 1. - temp2.x;
  93. // temp2.x is 0 at the sun and increases away from sun
  94. temp2.x = max(temp2.x, .001);
  95. // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
  96. temp2.x *= glow.x;
  97. // Higher glow.x gives dimmer glow (because next step is 1 / "angle")
  98. temp2.x = pow(temp2.x, glow.z);
  99. // glow.z should be negative, so we're doing a sort of (1 / "angle") function
  100. // Add "minimum anti-solar illumination"
  101. temp2.x += .25;
  102. // Haze color above cloud
  103. vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient)
  104. + (haze_horizon.r * haze_weight) * (sunlight * temp2.x + ambient)
  105. );
  106. // Increase ambient when there are more clouds
  107. vec4 tmpAmbient = ambient;
  108. tmpAmbient += (1. - tmpAmbient) * cloud_shadow.x * 0.5;
  109. // Dim sunlight by cloud shadow percentage
  110. sunlight *= (1. - cloud_shadow.x);
  111. // Haze color below cloud
  112. vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient)
  113. + (haze_horizon.r * haze_weight) * (sunlight * temp2.x + tmpAmbient)
  114. );
  115. // Final atmosphere additive
  116. vary_HazeColor *= (1. - temp1);
  117. // Attenuate cloud color by atmosphere
  118. temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds
  119. // At horizon, blend high altitude sky color towards the darker color below the clouds
  120. vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1));
  121. // won't compile on mac without this being set
  122. //vary_AtmosAttenuation = vec3(0.0,0.0,0.0);
  123. }