PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 157 lines | 127 code | 30 blank | 0 comment | 0 complexity | 3f9bc5f2b1dd76fae798aa51db2cfec7 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file atmosphericsV.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. // VARYING param funcs
  26. void setSunlitColor(vec3 v);
  27. void setAmblitColor(vec3 v);
  28. void setAdditiveColor(vec3 v);
  29. void setAtmosAttenuation(vec3 v);
  30. void setPositionEye(vec3 v);
  31. vec3 getAdditiveColor();
  32. //VARYING vec4 vary_CloudUVs;
  33. //VARYING float vary_CloudDensity;
  34. // Inputs
  35. uniform vec4 morphFactor;
  36. uniform vec3 camPosLocal;
  37. //uniform vec4 camPosWorld;
  38. uniform vec4 lightnorm;
  39. uniform vec4 sunlight_color;
  40. uniform vec4 ambient;
  41. uniform vec4 blue_horizon;
  42. uniform vec4 blue_density;
  43. uniform vec4 haze_horizon;
  44. uniform vec4 haze_density;
  45. uniform vec4 cloud_shadow;
  46. uniform vec4 density_multiplier;
  47. uniform vec4 distance_multiplier;
  48. uniform vec4 max_y;
  49. uniform vec4 glow;
  50. void calcAtmospherics(vec3 inPositionEye) {
  51. vec3 P = inPositionEye;
  52. setPositionEye(P);
  53. //(TERRAIN) limit altitude
  54. if (P.y > max_y.x) P *= (max_y.x / P.y);
  55. if (P.y < -max_y.x) P *= (-max_y.x / P.y);
  56. vec3 tmpLightnorm = lightnorm.xyz;
  57. vec3 Pn = normalize(P);
  58. float Plen = length(P);
  59. vec4 temp1 = vec4(0);
  60. vec3 temp2 = vec3(0);
  61. vec4 blue_weight;
  62. vec4 haze_weight;
  63. vec4 sunlight = sunlight_color;
  64. vec4 light_atten;
  65. //sunlight attenuation effect (hue and brightness) due to atmosphere
  66. //this is used later for sunlight modulation at various altitudes
  67. light_atten = (blue_density * 1.0 + vec4(haze_density.r) * 0.25) * (density_multiplier.x * max_y.x);
  68. //I had thought blue_density and haze_density should have equal weighting,
  69. //but attenuation due to haze_density tends to seem too strong
  70. temp1 = blue_density + vec4(haze_density.r);
  71. blue_weight = blue_density / temp1;
  72. haze_weight = vec4(haze_density.r) / temp1;
  73. //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain)
  74. temp2.y = max(0.0, tmpLightnorm.y);
  75. temp2.y = 1. / temp2.y;
  76. sunlight *= exp( - light_atten * temp2.y);
  77. // main atmospheric scattering line integral
  78. temp2.z = Plen * density_multiplier.x;
  79. // Transparency (-> temp1)
  80. // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier.x in a variable because the ati
  81. // compiler gets confused.
  82. temp1 = exp(-temp1 * temp2.z * distance_multiplier.x);
  83. //final atmosphere attenuation factor
  84. setAtmosAttenuation(temp1.rgb);
  85. //vary_AtmosAttenuation = distance_multiplier / 10000.;
  86. //vary_AtmosAttenuation = density_multiplier * 100.;
  87. //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.);
  88. //compute haze glow
  89. //(can use temp2.x as temp because we haven't used it yet)
  90. temp2.x = dot(Pn, tmpLightnorm.xyz);
  91. temp2.x = 1. - temp2.x;
  92. //temp2.x is 0 at the sun and increases away from sun
  93. temp2.x = max(temp2.x, .03); //was glow.y
  94. //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
  95. temp2.x *= glow.x;
  96. //higher glow.x gives dimmer glow (because next step is 1 / "angle")
  97. temp2.x = pow(temp2.x, glow.z);
  98. //glow.z should be negative, so we're doing a sort of (1 / "angle") function
  99. //add "minimum anti-solar illumination"
  100. temp2.x += .25;
  101. //increase ambient when there are more clouds
  102. vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow.x * 0.5;
  103. //haze color
  104. setAdditiveColor(
  105. vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow.x) + tmpAmbient)
  106. + (haze_horizon.r * haze_weight) * (sunlight*(1.-cloud_shadow.x) * temp2.x
  107. + tmpAmbient)));
  108. //brightness of surface both sunlight and ambient
  109. setSunlitColor(vec3(sunlight * .5));
  110. setAmblitColor(vec3(tmpAmbient * .25));
  111. setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1));
  112. // vary_SunlitColor = vec3(0);
  113. // vary_AmblitColor = vec3(0);
  114. // vary_AdditiveColor = vec4(Pn, 1.0);
  115. /*
  116. const float cloudShadowScale = 100.;
  117. // Get cloud uvs for shadowing
  118. vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.;
  119. vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale;
  120. // We can take uv1 and multiply it by (TerrainSpan / CloudSpan)
  121. // cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.);
  122. vary_CloudUVs *= (10000./40000.);
  123. // Offset by sun vector * (CloudAltitude / CloudSpan)
  124. vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.);
  125. vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.);
  126. */
  127. }