summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class3/windlight
diff options
context:
space:
mode:
authorGraham Linden graham@lindenlab.com <Graham Linden graham@lindenlab.com>2018-02-28 21:46:30 +0000
committerGraham Linden graham@lindenlab.com <Graham Linden graham@lindenlab.com>2018-02-28 21:46:30 +0000
commit72270213f5eebd019b10bdd6ec15020ba3d2ecf5 (patch)
treebe92c250563eedb720940b32cf42e328a49ea6b6 /indra/newview/app_settings/shaders/class3/windlight
parent31017934581437836e847d8fcb5a76489f3baf50 (diff)
Add 3p package for adv atmospherics to autobuild.
Mark legacy atmospherics code with ifdefs. Fix up legacy uplift to include new atmospherics settings.
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/windlight')
-rw-r--r--indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class3/windlight/skyF.glsl54
-rw-r--r--indra/newview/app_settings/shaders/class3/windlight/skyV.glsl121
3 files changed, 34 insertions, 143 deletions
diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl
index c71eaf4b13..d27363a60c 100644
--- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl
+++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl
@@ -33,9 +33,7 @@ in vec3 view_dir;
uniform vec3 cameraPosLocal;
uniform vec3 sun_direction;
-uniform vec2 sun_size;
-uniform sampler2D cloud_noise_texture;
uniform sampler2D transmittance_texture;
uniform sampler3D scattering_texture;
uniform sampler3D mie_scattering_texture;
diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl
index e2a2367626..c71eaf4b13 100644
--- a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl
+++ b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl
@@ -1,5 +1,5 @@
/**
- * @file WLSkyF.glsl
+ * @file advancedAtmoF.glsl
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
@@ -29,37 +29,43 @@ out vec4 frag_color;
#define frag_color gl_FragColor
#endif
-/////////////////////////////////////////////////////////////////////////
-// The fragment shader for the sky
-/////////////////////////////////////////////////////////////////////////
+in vec3 view_dir;
-VARYING vec4 vary_HazeColor;
+uniform vec3 cameraPosLocal;
+uniform vec3 sun_direction;
+uniform vec2 sun_size;
uniform sampler2D cloud_noise_texture;
-uniform vec4 gamma;
+uniform sampler2D transmittance_texture;
+uniform sampler3D scattering_texture;
+uniform sampler3D mie_scattering_texture;
-/// Soft clips the light with a gamma correction
-vec3 scaleSoftClip(vec3 light) {
- //soft clip effect:
- light = 1. - clamp(light, vec3(0.), vec3(1.));
- light = 1. - pow(light, gamma.xxx);
-
- return light;
-}
+vec3 GetSolarLuminance();
+vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance);
+vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance);
+vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance);
void main()
{
- // Potential Fill-rate optimization. Add cloud calculation
- // back in and output alpha of 0 (so that alpha culling kills
- // the fragment) if the sky wouldn't show up because the clouds
- // are fully opaque.
+ vec3 view_direction = normalize(view_dir);
+
+ vec3 camPos = cameraPosLocal;
+ vec3 transmittance;
+ vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance);
- vec4 color;
- color = vary_HazeColor;
- color *= 2.;
+ radiance *= transmittance;
- /// Gamma correct for WL (soft clip effect).
- frag_color.rgb = scaleSoftClip(color.rgb);
- frag_color.a = 1.0;
+ // If the view ray intersects the Sun, add the Sun radiance.
+ if (dot(view_direction, sun_direction) >= sun_size.y)
+ {
+ radiance = radiance + transmittance * GetSolarLuminance();
+ }
+
+ vec3 color = vec3(1.0) - exp(-radiance);
+ color = pow(color, vec3(1.0 / 2.2));
+
+ frag_color.rgb = color;
+
+ frag_color.a = 1.0;
}
diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl
index 3788ddaf2d..52a7595379 100644
--- a/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl
+++ b/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl
@@ -1,5 +1,5 @@
/**
- * @file WLSkyV.glsl
+ * @file advancedAtmoV.glsl
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
@@ -27,130 +27,17 @@ uniform mat4 modelview_projection_matrix;
ATTRIBUTE vec3 position;
-// SKY ////////////////////////////////////////////////////////////////////////
-// The vertex shader for creating the atmospheric sky
-///////////////////////////////////////////////////////////////////////////////
-
-// Output parameters
-VARYING vec4 vary_HazeColor;
-
// Inputs
uniform vec3 camPosLocal;
-uniform vec4 lightnorm;
-uniform vec4 sunlight_color;
-uniform vec4 ambient;
-uniform vec4 blue_horizon;
-uniform vec4 blue_density;
-uniform float haze_horizon;
-uniform float haze_density;
-
-uniform float cloud_shadow;
-uniform float density_multiplier;
-uniform float max_y;
-
-uniform vec4 glow;
-
-uniform vec4 cloud_color;
+out vec3 view_dir;
void main()
{
-
// World / view / projection
gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
- // Get relative position
- vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0);
- //vec3 P = position.xyz + vec3(0,50,0);
-
- // Set altitude
- if (P.y > 0.)
- {
- P *= (max_y / P.y);
- }
- else
- {
- P *= (-32000. / P.y);
- }
-
- // Can normalize then
- vec3 Pn = normalize(P);
- float Plen = length(P);
-
- // Initialize temp variables
- vec4 temp1 = vec4(0.);
- vec4 temp2 = vec4(0.);
- vec4 blue_weight;
- vec4 haze_weight;
- vec4 sunlight = sunlight_color;
- vec4 light_atten;
-
- // Sunlight attenuation effect (hue and brightness) due to atmosphere
- // this is used later for sunlight modulation at various altitudes
- light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y);
-
- // Calculate relative weights
- temp1 = blue_density + haze_density;
- blue_weight = blue_density / temp1;
- haze_weight = haze_density / temp1;
-
- // Compute sunlight from P & lightnorm (for long rays like sky)
- temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y );
- temp2.y = 1. / temp2.y;
- sunlight *= exp( - light_atten * temp2.y);
-
- // Distance
- temp2.z = Plen * density_multiplier;
-
- // Transparency (-> temp1)
- // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati
- // compiler gets confused.
- temp1 = exp(-temp1 * temp2.z);
-
-
- // Compute haze glow
- temp2.x = dot(Pn, lightnorm.xyz);
- temp2.x = 1. - temp2.x;
- // temp2.x is 0 at the sun and increases away from sun
- temp2.x = max(temp2.x, .001);
- // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
- temp2.x *= glow.x;
- // Higher glow.x gives dimmer glow (because next step is 1 / "angle")
- temp2.x = pow(temp2.x, glow.z);
- // glow.z should be negative, so we're doing a sort of (1 / "angle") function
-
- // Add "minimum anti-solar illumination"
- temp2.x += .25;
-
-
- // Haze color above cloud
- vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient)
- + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient)
- );
-
-
- // Increase ambient when there are more clouds
- vec4 tmpAmbient = ambient;
- tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;
-
- // Dim sunlight by cloud shadow percentage
- sunlight *= (1. - cloud_shadow);
-
- // Haze color below cloud
- vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient)
- + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient)
- );
-
- // Final atmosphere additive
- vary_HazeColor *= (1. - temp1);
-
- // Attenuate cloud color by atmosphere
- temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds
-
- // At horizon, blend high altitude sky color towards the darker color below the clouds
- vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1));
-
- // won't compile on mac without this being set
- //vary_AtmosAttenuation = vec3(0.0,0.0,0.0);
+ // this will be normalized in the frag shader...
+ view_dir = position.xyz - camPosLocal.xyz;
}