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

/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl

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