summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings
diff options
context:
space:
mode:
authorRye <rye@alchemyviewer.org>2025-11-27 07:52:56 -0500
committerAndrey Kleshchev <117672381+akleshchev@users.noreply.github.com>2026-01-06 18:34:34 +0200
commitb9727dd84124756adacfbce73b5a916a2c0dd891 (patch)
tree33c732b4735de4989733b2acc4cefff53a70d3d8 /indra/newview/app_settings
parentcba36bc1f49990a802892278ca98478edb31eda9 (diff)
Migrate sky/cloud rendering to fragment shader and introduce high precision post process option
Signed-off-by: Rye <rye@alchemyviewer.org>
Diffstat (limited to 'indra/newview/app_settings')
-rw-r--r--indra/newview/app_settings/settings.xml13
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl137
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl126
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/skyF.glsl118
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/skyV.glsl123
5 files changed, 252 insertions, 265 deletions
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 37d1a6653b..674f459193 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -10162,6 +10162,17 @@
<key>Value</key>
<integer>1</integer>
</map>
+ <key>RenderHighPrecisionPostProcess</key>
+ <map>
+ <key>Comment</key>
+ <string>Use 16-bit floating point buffers for post process rendering</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
<key>ReplaySession</key>
<map>
<key>Comment</key>
@@ -13895,7 +13906,7 @@
<key>WLSkyDetail</key>
<map>
<key>Comment</key>
- <string>Controls vertex detail on the WindLight sky. Lower numbers will give better performance and uglier skies.</string>
+ <string>[OBSOLETE]</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl
index 8c51b4a36b..f5200719ae 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl
@@ -30,9 +30,13 @@ out vec4 frag_data[4];
// The fragment shader for the sky
/////////////////////////////////////////////////////////////////////////
-in vec3 vary_CloudColorSun;
-in vec3 vary_CloudColorAmbient;
-in float vary_CloudDensity;
+// In
+in vec3 pos;
+
+in vec2 vary_texcoord0;
+in vec2 vary_texcoord1;
+in vec2 vary_texcoord2;
+in vec2 vary_texcoord3;
uniform sampler2D cloud_noise_texture;
uniform sampler2D cloud_noise_texture_next;
@@ -42,11 +46,26 @@ uniform vec3 cloud_pos_density2;
uniform float cloud_scale;
uniform float cloud_variance;
-in vec2 vary_texcoord0;
-in vec2 vary_texcoord1;
-in vec2 vary_texcoord2;
-in vec2 vary_texcoord3;
-in float altitude_blend_factor;
+uniform vec3 camPosLocal;
+
+uniform vec3 lightnorm;
+uniform vec3 sunlight_color;
+uniform vec3 moonlight_color;
+uniform int sun_up_factor;
+uniform vec3 ambient_color;
+uniform vec3 blue_horizon;
+uniform vec3 blue_density;
+uniform float haze_horizon;
+uniform float haze_density;
+
+uniform float cloud_shadow;
+uniform float density_multiplier;
+uniform float max_y;
+
+uniform vec3 glow;
+uniform float sun_moon_glow_factor;
+
+uniform vec3 cloud_color;
vec4 cloudNoise(vec2 uv)
{
@@ -58,21 +77,111 @@ vec4 cloudNoise(vec2 uv)
void main()
{
+ if (cloud_scale < 0.001)
+ {
+ discard;
+ }
+
// Set variables
vec2 uv1 = vary_texcoord0.xy;
vec2 uv2 = vary_texcoord1.xy;
-
- vec3 cloudColorSun = vary_CloudColorSun;
- vec3 cloudColorAmbient = vary_CloudColorAmbient;
- float cloudDensity = vary_CloudDensity;
vec2 uv3 = vary_texcoord2.xy;
vec2 uv4 = vary_texcoord3.xy;
- if (cloud_scale < 0.001)
+ // Get relative position
+ vec3 rel_pos = pos.xyz - camPosLocal.xyz + vec3(0, 50, 0);
+
+ float altitude_blend_factor = clamp((rel_pos.y + 512.0) / max_y, 0.0, 1.0);
+
+ // Set altitude
+ if (rel_pos.y > 0)
{
- discard;
+ rel_pos *= (max_y / rel_pos.y);
+ }
+ if (rel_pos.y < 0)
+ {
+ altitude_blend_factor = 0; // SL-11589 Fix clouds drooping below horizon
+ rel_pos *= (-32000. / rel_pos.y);
}
+ // Can normalize then
+ vec3 rel_pos_norm = normalize(rel_pos);
+ float rel_pos_len = length(rel_pos);
+
+ // Initialize temp variables
+ vec3 sunlight = sunlight_color;
+ vec3 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 + vec3(haze_density * 0.25)) * (density_multiplier * max_y);
+
+ // Calculate relative weights
+ vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density));
+ vec3 blue_weight = blue_density / combined_haze;
+ vec3 haze_weight = haze_density / combined_haze;
+
+ // Compute sunlight from rel_pos & lightnorm (for long rays like sky)
+ float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y);
+ sunlight *= exp(-light_atten * off_axis);
+
+ // Distance
+ float density_dist = rel_pos_len * density_multiplier;
+
+ // Transparency (-> combined_haze)
+ // ATI Bugfix -- can't store combined_haze*density_dist in a variable because the ati
+ // compiler gets confused.
+ combined_haze = exp(-combined_haze * density_dist);
+
+ // Compute haze glow
+ float haze_glow = 1.0 - dot(rel_pos_norm, lightnorm.xyz);
+ // haze_glow is 0 at the sun and increases away from sun
+ haze_glow = max(haze_glow, .001);
+ // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
+ haze_glow *= glow.x;
+ // Higher glow.x gives dimmer glow (because next step is 1 / "angle")
+ haze_glow = pow(haze_glow, glow.z);
+ // glow.z should be negative, so we're doing a sort of (1 / "angle") function
+
+ haze_glow *= sun_moon_glow_factor;
+
+ // Add "minimum anti-solar illumination"
+ // For sun, add to glow. For moon, remove glow entirely. SL-13768
+ haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25);
+
+ // Increase ambient when there are more clouds
+ vec3 tmpAmbient = ambient_color;
+ tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;
+
+ // Dim sunlight by cloud shadow percentage
+ sunlight *= (1. - cloud_shadow);
+
+ // Haze color below cloud
+ vec3 additiveColorBelowCloud =
+ (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient));
+
+ // CLOUDS
+ sunlight = sunlight_color;
+ off_axis = 1.0 / max(1e-6, lightnorm.y * 2.);
+ sunlight *= exp(-light_atten * off_axis);
+
+ // Cloud color out
+ vec3 cloudColorSun = (sunlight * haze_glow) * cloud_color;
+ vec3 cloudColorAmbient = tmpAmbient * cloud_color;
+
+ // Attenuate cloud color by atmosphere
+ combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds
+ cloudColorSun *= combined_haze;
+ cloudColorAmbient *= combined_haze;
+ vec3 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze);
+
+ // Make a nice cloud density based on the cloud_shadow value that was passed in.
+ float cloudDensity = 2. * (cloud_shadow - 0.25);
+
+ // Combine these to minimize register use
+ cloudColorAmbient += oHazeColorBelowCloud;
+
+ // Cloud Fragment
vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f);
vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
index c019b5606a..89fbe38af0 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
@@ -1,5 +1,5 @@
/**
- * @file WLCloudsV.glsl
+ * @file class1/deferred/cloudsV.glsl
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
@@ -33,38 +33,15 @@ in vec2 texcoord0;
///////////////////////////////////////////////////////////////////////////////
// Output parameters
-out vec3 vary_CloudColorSun;
-out vec3 vary_CloudColorAmbient;
-out float vary_CloudDensity;
+out vec3 pos;
out vec2 vary_texcoord0;
out vec2 vary_texcoord1;
out vec2 vary_texcoord2;
out vec2 vary_texcoord3;
-out float altitude_blend_factor;
// Inputs
-uniform vec3 camPosLocal;
-
uniform vec3 lightnorm;
-uniform vec3 sunlight_color;
-uniform vec3 moonlight_color;
-uniform int sun_up_factor;
-uniform vec3 ambient_color;
-uniform vec3 blue_horizon;
-uniform vec3 blue_density;
-uniform float haze_horizon;
-uniform float haze_density;
-
-uniform float cloud_shadow;
-uniform float density_multiplier;
-uniform float max_y;
-
-uniform vec3 glow;
-uniform float sun_moon_glow_factor;
-
-uniform vec3 cloud_color;
-
uniform float cloud_scale;
// NOTE: Keep these in sync!
@@ -76,6 +53,7 @@ uniform float cloud_scale;
void main()
{
// World / view / projection
+ pos = position.xyz;
gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
// Texture coords
@@ -92,102 +70,4 @@ void main()
vary_texcoord2 = vary_texcoord0 * 16.;
vary_texcoord3 = vary_texcoord1 * 16.;
-
- // Get relative position
- vec3 rel_pos = position.xyz - camPosLocal.xyz + vec3(0, 50, 0);
-
- altitude_blend_factor = clamp((rel_pos.y + 512.0) / max_y, 0.0, 1.0);
-
- // Set altitude
- if (rel_pos.y > 0)
- {
- rel_pos *= (max_y / rel_pos.y);
- }
- if (rel_pos.y < 0)
- {
- altitude_blend_factor = 0; // SL-11589 Fix clouds drooping below horizon
- rel_pos *= (-32000. / rel_pos.y);
- }
-
- // Can normalize then
- vec3 rel_pos_norm = normalize(rel_pos);
- float rel_pos_len = length(rel_pos);
-
- // Initialize temp variables
- vec3 sunlight = sunlight_color;
- vec3 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 + vec3(haze_density * 0.25)) * (density_multiplier * max_y);
-
- // Calculate relative weights
- vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density));
- vec3 blue_weight = blue_density / combined_haze;
- vec3 haze_weight = haze_density / combined_haze;
-
- // Compute sunlight from rel_pos & lightnorm (for long rays like sky)
- float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y);
- sunlight *= exp(-light_atten * off_axis);
-
- // Distance
- float density_dist = rel_pos_len * density_multiplier;
-
- // Transparency (-> combined_haze)
- // ATI Bugfix -- can't store combined_haze*density_dist in a variable because the ati
- // compiler gets confused.
- combined_haze = exp(-combined_haze * density_dist);
-
- // Compute haze glow
- float haze_glow = 1.0 - dot(rel_pos_norm, lightnorm.xyz);
- // haze_glow is 0 at the sun and increases away from sun
- haze_glow = max(haze_glow, .001);
- // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
- haze_glow *= glow.x;
- // Higher glow.x gives dimmer glow (because next step is 1 / "angle")
- haze_glow = pow(haze_glow, glow.z);
- // glow.z should be negative, so we're doing a sort of (1 / "angle") function
-
- haze_glow *= sun_moon_glow_factor;
-
- // Add "minimum anti-solar illumination"
- // For sun, add to glow. For moon, remove glow entirely. SL-13768
- haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25);
-
- // Increase ambient when there are more clouds
- vec3 tmpAmbient = ambient_color;
- tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;
-
- // Dim sunlight by cloud shadow percentage
- sunlight *= (1. - cloud_shadow);
-
- // Haze color below cloud
- vec3 additiveColorBelowCloud =
- (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient));
-
- // CLOUDS
- sunlight = sunlight_color;
- off_axis = 1.0 / max(1e-6, lightnorm.y * 2.);
- sunlight *= exp(-light_atten * off_axis);
-
- // Cloud color out
- vary_CloudColorSun = (sunlight * haze_glow) * cloud_color;
- vary_CloudColorAmbient = tmpAmbient * cloud_color;
-
- // Attenuate cloud color by atmosphere
- combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds
- vary_CloudColorSun *= combined_haze;
- vary_CloudColorAmbient *= combined_haze;
- vec3 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze);
-
- // Make a nice cloud density based on the cloud_shadow value that was passed in.
- vary_CloudDensity = 2. * (cloud_shadow - 0.25);
-
- // Combine these to minimize register use
- vary_CloudColorAmbient += oHazeColorBelowCloud;
-
- // needs this to compile on mac
- //vary_AtmosAttenuation = vec3(0.0,0.0,0.0);
-
- // END CLOUDS
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl
index 7639a5e6fc..b70d1db499 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl
@@ -23,13 +23,14 @@
* $/LicenseInfo$
*/
+// Outputs
+out vec4 frag_data[4];
+
// Inputs
-in vec3 vary_HazeColor;
-in float vary_LightNormPosDot;
+in vec3 pos;
#ifdef HAS_HDRI
in vec4 vary_position;
-in vec3 vary_rel_pos;
uniform float sky_hdr_scale;
uniform float hdri_split_screen;
uniform mat3 env_mat;
@@ -43,7 +44,27 @@ uniform float moisture_level;
uniform float droplet_radius;
uniform float ice_level;
-out vec4 frag_data[4];
+uniform vec3 camPosLocal;
+
+uniform vec3 lightnorm;
+uniform vec3 sunlight_color;
+uniform vec3 moonlight_color;
+uniform int sun_up_factor;
+uniform vec3 ambient_color;
+uniform vec3 blue_horizon;
+uniform vec3 blue_density;
+uniform float haze_horizon;
+uniform float haze_density;
+
+uniform float cloud_shadow;
+uniform float density_multiplier;
+uniform float distance_multiplier;
+uniform float max_y;
+
+uniform vec3 glow;
+uniform float sun_moon_glow_factor;
+
+uniform int cube_snapshot;
vec3 srgb_to_linear(vec3 c);
vec3 linear_to_srgb(vec3 c);
@@ -83,12 +104,25 @@ vec3 halo22(float d)
void main()
{
+ // Get relative position
+ vec3 rel_pos = pos.xyz - camPosLocal.xyz + vec3(0, 50, 0);
+
+ // Adj position vector to clamp altitude
+ if (rel_pos.y > 0.)
+ {
+ rel_pos *= (max_y / rel_pos.y);
+ }
+ if (rel_pos.y < 0.)
+ {
+ rel_pos *= (-32000. / rel_pos.y);
+ }
+
vec3 color;
#ifdef HAS_HDRI
vec3 frag_coord = vary_position.xyz/vary_position.w;
if (-frag_coord.x > ((1.0-hdri_split_screen)*2.0-1.0))
{
- vec3 pos = normalize(vary_rel_pos);
+ vec3 pos = normalize(rel_pos);
pos = env_mat * pos;
vec2 texCoord = vec2(atan(pos.z, pos.x) + PI, acos(pos.y)) / vec2(2.0 * PI, PI);
color = textureLod(environmentMap, texCoord.xy, 0).rgb * sky_hdr_scale;
@@ -99,15 +133,75 @@ void main()
else
#endif
{
- // 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.
+ // Normalized
+ vec3 rel_pos_norm = normalize(rel_pos);
+ float rel_pos_len = length(rel_pos);
+
+ // Grab this value and pass to frag shader for rainbows
+ float rel_pos_lightnorm_dot = dot(rel_pos_norm, lightnorm.xyz);
+
+ // Initialize temp variables
+ vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color * 0.7; //magic 0.7 to match legacy color
+
+ // Sunlight attenuation effect (hue and brightness) due to atmosphere
+ // this is used later for sunlight modulation at various altitudes
+ vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y);
+
+ // Calculate relative weights
+ vec3 combined_haze = max(abs(blue_density) + vec3(abs(haze_density)), vec3(1e-6));
+ vec3 blue_weight = blue_density / combined_haze;
+ vec3 haze_weight = haze_density / combined_haze;
+
+ // Compute sunlight from rel_pos & lightnorm (for long rays like sky)
+ float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y);
+ sunlight *= exp(-light_atten * off_axis);
+
+ // Distance
+ float density_dist = rel_pos_len * density_multiplier;
+
+ // Transparency (-> combined_haze)
+ // ATI Bugfix -- can't store combined_haze*density_dist in a variable because the ati
+ // compiler gets confused.
+ combined_haze = exp(-combined_haze * density_dist);
+
+ // Compute haze glow
+ float haze_glow = 1.0 - rel_pos_lightnorm_dot;
+ // haze_glow is 0 at the sun and increases away from sun
+ haze_glow = max(haze_glow, .001);
+ // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
+ haze_glow *= glow.x;
+ // Higher glow.x gives dimmer glow (because next step is 1 / "angle")
+ haze_glow = pow(haze_glow, glow.z);
+ // glow.z should be negative, so we're doing a sort of (1 / "angle") function
+
+ // Add "minimum anti-solar illumination"
+ // For sun, add to glow. For moon, remove glow entirely. SL-13768
+ haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (sun_moon_glow_factor * (haze_glow + 0.25));
+
+ // Haze color above cloud
+ color = (blue_horizon * blue_weight * (sunlight + ambient_color)
+ + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient_color));
+
+ // Final atmosphere additive
+ color *= (1. - combined_haze);
+
+ // Increase ambient when there are more clouds
+ vec3 ambient = ambient_color + max(vec3(0), (1. - ambient_color)) * cloud_shadow * 0.5;
+
+ // Dim sunlight by cloud shadow percentage
+ sunlight *= max(0.0, (1. - cloud_shadow));
+
+ // Haze color below cloud
+ vec3 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient)
+ + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient));
+
+ // Attenuate cloud color by atmosphere
+ combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds
- color = vary_HazeColor;
+ // At horizon, blend high altitude sky color towards the darker color below the clouds
+ color += (add_below_cloud - color) * (1. - sqrt(combined_haze));
- float rel_pos_lightnorm = vary_LightNormPosDot;
- float optic_d = rel_pos_lightnorm;
+ float optic_d = rel_pos_lightnorm_dot;
vec3 halo_22 = halo22(optic_d);
color.rgb += rainbow(optic_d);
color.rgb += halo_22;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
index ea00d240df..836ad66098 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
@@ -1,5 +1,5 @@
/**
- * @file WLSkyV.glsl
+ * @file class1/deferred/skyV.glsl
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
@@ -32,36 +32,13 @@ in vec3 position;
///////////////////////////////////////////////////////////////////////////////
// Output parameters
-out vec3 vary_HazeColor;
-out float vary_LightNormPosDot;
+out vec3 pos;
#ifdef HAS_HDRI
out vec4 vary_position;
-out vec3 vary_rel_pos;
#endif
// Inputs
-uniform vec3 camPosLocal;
-
-uniform vec3 lightnorm;
-uniform vec3 sunlight_color;
-uniform vec3 moonlight_color;
-uniform int sun_up_factor;
-uniform vec3 ambient_color;
-uniform vec3 blue_horizon;
-uniform vec3 blue_density;
-uniform float haze_horizon;
-uniform float haze_density;
-
-uniform float cloud_shadow;
-uniform float density_multiplier;
-uniform float distance_multiplier;
-uniform float max_y;
-
-uniform vec3 glow;
-uniform float sun_moon_glow_factor;
-
-uniform int cube_snapshot;
// NOTE: Keep these in sync!
// indra\newview\app_settings\shaders\class1\deferred\skyV.glsl
@@ -70,97 +47,13 @@ uniform int cube_snapshot;
void main()
{
// World / view / projection
- vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
-
- gl_Position = pos;
-
- // Get relative position
- vec3 rel_pos = position.xyz - camPosLocal.xyz + vec3(0, 50, 0);
-
-#ifdef HAS_HDRI
- vary_rel_pos = rel_pos;
- vary_position = pos;
-#endif
-
- // Adj position vector to clamp altitude
- if (rel_pos.y > 0.)
- {
- rel_pos *= (max_y / rel_pos.y);
- }
- if (rel_pos.y < 0.)
- {
- rel_pos *= (-32000. / rel_pos.y);
- }
-
- // Normalized
- vec3 rel_pos_norm = normalize(rel_pos);
- float rel_pos_len = length(rel_pos);
-
- // Grab this value and pass to frag shader for rainbows
- float rel_pos_lightnorm_dot = dot(rel_pos_norm, lightnorm.xyz);
- vary_LightNormPosDot = rel_pos_lightnorm_dot;
-
- // Initialize temp variables
- vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color * 0.7; //magic 0.7 to match legacy color
-
- // Sunlight attenuation effect (hue and brightness) due to atmosphere
- // this is used later for sunlight modulation at various altitudes
- vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y);
-
- // Calculate relative weights
- vec3 combined_haze = max(abs(blue_density) + vec3(abs(haze_density)), vec3(1e-6));
- vec3 blue_weight = blue_density / combined_haze;
- vec3 haze_weight = haze_density / combined_haze;
-
- // Compute sunlight from rel_pos & lightnorm (for long rays like sky)
- float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y);
- sunlight *= exp(-light_atten * off_axis);
-
- // Distance
- float density_dist = rel_pos_len * density_multiplier;
-
- // Transparency (-> combined_haze)
- // ATI Bugfix -- can't store combined_haze*density_dist in a variable because the ati
- // compiler gets confused.
- combined_haze = exp(-combined_haze * density_dist);
-
- // Compute haze glow
- float haze_glow = 1.0 - rel_pos_lightnorm_dot;
- // haze_glow is 0 at the sun and increases away from sun
- haze_glow = max(haze_glow, .001);
- // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
- haze_glow *= glow.x;
- // Higher glow.x gives dimmer glow (because next step is 1 / "angle")
- haze_glow = pow(haze_glow, glow.z);
- // glow.z should be negative, so we're doing a sort of (1 / "angle") function
-
- // Add "minimum anti-solar illumination"
- // For sun, add to glow. For moon, remove glow entirely. SL-13768
- haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (sun_moon_glow_factor * (haze_glow + 0.25));
-
- // Haze color above cloud
- vec3 color = (blue_horizon * blue_weight * (sunlight + ambient_color)
- + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient_color));
-
- // Final atmosphere additive
- color *= (1. - combined_haze);
-
- // Increase ambient when there are more clouds
- vec3 ambient = ambient_color + max(vec3(0), (1. - ambient_color)) * cloud_shadow * 0.5;
-
- // Dim sunlight by cloud shadow percentage
- sunlight *= max(0.0, (1. - cloud_shadow));
-
- // Haze color below cloud
- vec3 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient)
- + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient));
+ pos = position.xyz;
- // Attenuate cloud color by atmosphere
- combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds
+ vec4 transformed_pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
- // At horizon, blend high altitude sky color towards the darker color below the clouds
- color += (add_below_cloud - color) * (1. - sqrt(combined_haze));
+ gl_Position = transformed_pos;
- // Haze color above cloud
- vary_HazeColor = color;
+ #ifdef HAS_HDRI
+ vary_position = transformed_pos;
+ #endif
}