Skip to content
Snippets Groups Projects
Commit f887f658 authored by David Parks's avatar David Parks
Browse files

SL-18190 WIP - Linear space atmospherics take 2

parent a63fcfc9
No related branches found
No related tags found
No related merge requests found
...@@ -370,9 +370,7 @@ vec3 pbrIbl(vec3 diffuseColor, ...@@ -370,9 +370,7 @@ vec3 pbrIbl(vec3 diffuseColor,
vec3 diffuse = diffuseLight * diffuseColor; vec3 diffuse = diffuseLight * diffuseColor;
vec3 specular = specularLight * (specularColor * brdf.x + brdf.y); vec3 specular = specularLight * (specularColor * brdf.x + brdf.y);
//specular *= 1.5; return (diffuse + specular) * ao * 0.5; //reduce by half to place in appropriate color space for atmospherics
return (diffuse + specular) * ao;
} }
// Encapsulate the various inputs used by the various functions in the shading equation // Encapsulate the various inputs used by the various functions in the shading equation
......
...@@ -196,7 +196,7 @@ void main() ...@@ -196,7 +196,7 @@ void main()
vec3 irradiance = vec3(0); vec3 irradiance = vec3(0);
vec3 radiance = vec3(0); vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss);
irradiance = max(amblit,irradiance); irradiance = max(amblit*2.0,irradiance);
vec3 f0 = vec3(0.04); vec3 f0 = vec3(0.04);
...@@ -212,6 +212,9 @@ void main() ...@@ -212,6 +212,9 @@ void main()
color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, light_dir) * sunlit*2.75 * scol; color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, light_dir) * sunlit*2.75 * scol;
color += colorEmissive; color += colorEmissive;
color = atmosFragLightingLinear(color, additive, atten);
color = scaleSoftClipFragLinear(color);
vec3 light = vec3(0); vec3 light = vec3(0);
// Punctual lights // Punctual lights
...@@ -227,8 +230,6 @@ void main() ...@@ -227,8 +230,6 @@ void main()
color.rgb += light.rgb; color.rgb += light.rgb;
color = atmosFragLightingLinear(color, additive, atten);
color = scaleSoftClipFragLinear(color);
frag_color = vec4(color.rgb,albedo.a * vertex_color.a); frag_color = vec4(color.rgb,albedo.a * vertex_color.a);
} }
...@@ -52,7 +52,7 @@ vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) ...@@ -52,7 +52,7 @@ vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten)
light *= atten.r; light *= atten.r;
light += additive; light += additive;
return light; return light*2.0;
} }
vec3 atmosLighting(vec3 light) vec3 atmosLighting(vec3 light)
......
...@@ -22,15 +22,24 @@ ...@@ -22,15 +22,24 @@
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
vec3 srgb_to_linear(vec3 col);
uniform vec4 lightnorm; uniform vec4 lightnorm;
uniform vec4 sunlight_color; uniform vec4 sunlight_color;
vec3 sunlight_linear = srgb_to_linear(sunlight_color.rgb);
uniform vec4 moonlight_color; uniform vec4 moonlight_color;
vec3 moonlight_linear = srgb_to_linear(moonlight_color.rgb);
uniform int sun_up_factor; uniform int sun_up_factor;
uniform vec4 ambient_color; uniform vec4 ambient_color;
vec3 ambient_linear = srgb_to_linear(ambient_color.rgb);
uniform vec4 blue_horizon; uniform vec4 blue_horizon;
vec3 blue_horizon_linear = srgb_to_linear(blue_horizon.rgb);
uniform vec4 blue_density; uniform vec4 blue_density;
vec3 blue_density_linear = srgb_to_linear(blue_density.rgb);
uniform float haze_horizon; uniform float haze_horizon;
uniform float haze_density; uniform float haze_density;
vec3 haze_density_linear = srgb_to_linear(vec3(haze_density));
uniform float cloud_shadow; uniform float cloud_shadow;
uniform float density_multiplier; uniform float density_multiplier;
uniform float distance_multiplier; uniform float distance_multiplier;
...@@ -41,8 +50,6 @@ uniform mat3 ssao_effect_mat; ...@@ -41,8 +50,6 @@ uniform mat3 ssao_effect_mat;
uniform int no_atmo; uniform int no_atmo;
uniform float sun_moon_glow_factor; uniform float sun_moon_glow_factor;
vec3 srgb_to_linear(vec3 col);
float getAmbientClamp() { return 1.0f; } float getAmbientClamp() { return 1.0f; }
// return colors in sRGB space // return colors in sRGB space
...@@ -136,13 +143,96 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou ...@@ -136,13 +143,96 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou
additive *= vec3(1.0 - combined_haze); additive *= vec3(1.0 - combined_haze);
} }
// return colors in linear space // return colors in linear space
void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive,
out vec3 atten, bool use_ao) out vec3 atten, bool use_ao)
{ {
calcAtmosphericVars(inPositionEye, light_dir, ambFactor, sunlit, amblit, additive, atten, use_ao); #if 0
calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false);
sunlit = srgb_to_linear(sunlit)*2.25; sunlit = srgb_to_linear(sunlit)*2.25;
amblit = srgb_to_linear(amblit)*0.15; amblit = srgb_to_linear(amblit)*0.15;
additive = srgb_to_linear(additive); additive = srgb_to_linear(additive);
atten = srgb_to_linear(atten); atten = srgb_to_linear(atten);
#else
vec3 rel_pos = inPositionEye;
//(TERRAIN) limit altitude
if (abs(rel_pos.y) > max_y) rel_pos *= (max_y / rel_pos.y);
vec3 rel_pos_norm = normalize(rel_pos);
float rel_pos_len = length(rel_pos);
vec3 sunlight = (sun_up_factor == 1) ? sunlight_linear : moonlight_linear;
// sunlight attenuation effect (hue and brightness) due to atmosphere
// this is used later for sunlight modulation at various altitudes
vec3 light_atten = (blue_density_linear + (haze_density_linear * 0.25)) * (density_multiplier * max_y);
// I had thought blue_density and haze_density should have equal weighting,
// but attenuation due to haze_density tends to seem too strong
vec3 combined_haze_linear = blue_density_linear + haze_density_linear;
vec3 combined_haze = blue_density.rgb + vec3(haze_density);
vec3 blue_weight = blue_density_linear / combined_haze_linear;
vec3 haze_weight = haze_density_linear / combined_haze_linear;
//(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain)
float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y);
sunlight *= exp(-light_atten * above_horizon_factor); // for sun [horizon..overhead] this maps to an exp curve [0..1]
// main atmospheric scattering line integral
float density_dist = rel_pos_len * density_multiplier;
// Transparency (-> combined_haze)
// ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati
// compiler gets confused.
combined_haze = exp(-combined_haze * density_dist * distance_multiplier);
combined_haze_linear = exp(-combined_haze_linear * density_dist * distance_multiplier);
// final atmosphere attenuation factor
atten = combined_haze.rgb;
// compute haze glow
float haze_glow = dot(rel_pos_norm, lightnorm.xyz);
// dampen sun additive contrib when not facing it...
// SL-13539: This "if" clause causes an "additive" white artifact at roughly 77 degreees.
// if (length(light_dir) > 0.01)
haze_glow *= max(0.0f, dot(light_dir, rel_pos_norm));
haze_glow = 1. - haze_glow;
// 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"
haze_glow += .25;
haze_glow *= sun_moon_glow_factor;
vec3 amb_color = ambient_linear;
// increase ambient when there are more clouds
vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5;
// Similar/Shared Algorithms:
// indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings()
// indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars()
// haze color
vec3 cs = sunlight.rgb * (1. - cloud_shadow);
additive = (blue_horizon_linear.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb);
// brightness of surface both sunlight and ambient
sunlit = sunlight.rgb;
amblit = tmpAmbient.rgb;
additive *= vec3(1.0 - combined_haze_linear);
sunlit *= 0.8;
amblit *= 0.05;
additive *= 0.25;
#endif
} }
...@@ -551,7 +551,7 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no ...@@ -551,7 +551,7 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no
fresnel *= spec.a; fresnel *= spec.a;
glossenv *= spec.rgb*fresnel; glossenv *= spec.rgb*fresnel;
glossenv *= vec3(1.0) - color; // fake energy conservation glossenv *= vec3(1.0) - color; // fake energy conservation
color.rgb += glossenv; color.rgb += glossenv*0.5;
} }
void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity)
...@@ -562,6 +562,6 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no ...@@ -562,6 +562,6 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no
fresnel *= fresnel; fresnel *= fresnel;
fresnel = min(fresnel+envIntensity, 1.0); fresnel = min(fresnel+envIntensity, 1.0);
reflected_color *= (envIntensity*fresnel); reflected_color *= (envIntensity*fresnel);
color = mix(color.rgb, reflected_color, envIntensity); color = mix(color.rgb, reflected_color*0.5, envIntensity);
} }
...@@ -140,8 +140,7 @@ void main() ...@@ -140,8 +140,7 @@ void main()
vec3 glossenv; vec3 glossenv;
vec3 legacyenv; vec3 legacyenv;
bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))
if (hasPBR)
{ {
norm.xyz = getNorm(tc); norm.xyz = getNorm(tc);
vec3 orm = texture2DRect(specularRect, tc).rgb; vec3 orm = texture2DRect(specularRect, tc).rgb;
...@@ -157,7 +156,7 @@ void main() ...@@ -157,7 +156,7 @@ void main()
vec3 radiance = vec3(0); vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss);
irradiance = max(amblit*ao,irradiance); irradiance = max(amblit*2.0*ao,irradiance);
vec3 f0 = vec3(0.04); vec3 f0 = vec3(0.04);
vec3 baseColor = diffuse.rgb; vec3 baseColor = diffuse.rgb;
...@@ -170,13 +169,19 @@ void main() ...@@ -170,13 +169,19 @@ void main()
vec3 v = -normalize(pos.xyz); vec3 v = -normalize(pos.xyz);
float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0);
color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness);
color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*2.75 * scol; color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*2.75 * scol;
color.rgb += colorEmissive; color.rgb += colorEmissive;
color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness);
color = atmosFragLightingLinear(color, additive, atten); color = atmosFragLightingLinear(color, additive, atten);
color = scaleSoftClipFragLinear(color); color = scaleSoftClipFragLinear(color);
} }
else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS))
{
//should only be true of WL sky, just port over diffuse value
color = srgb_to_linear(diffuse.rgb);
}
else else
{ {
// legacy shaders are still writng sRGB to gbuffer // legacy shaders are still writng sRGB to gbuffer
...@@ -223,12 +228,10 @@ void main() ...@@ -223,12 +228,10 @@ void main()
if (envIntensity > 0.0) if (envIntensity > 0.0)
{ // add environment map { // add environment map
applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity);
}
if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS))
{
color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a);
color = scaleSoftClipFragLinear(color);
} }
color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a);
color = scaleSoftClipFragLinear(color);
} }
#ifdef WATER_FOG #ifdef WATER_FOG
......
...@@ -43,7 +43,7 @@ void LLReflectionMap::update(U32 resolution, U32 face) ...@@ -43,7 +43,7 @@ void LLReflectionMap::update(U32 resolution, U32 face)
mLastUpdateTime = gFrameTimeSeconds; mLastUpdateTime = gFrameTimeSeconds;
llassert(mCubeArray.notNull()); llassert(mCubeArray.notNull());
llassert(mCubeIndex != -1); llassert(mCubeIndex != -1);
llassert(LLPipeline::sRenderDeferred); //llassert(LLPipeline::sRenderDeferred);
// make sure we don't walk off the edge of the render target // make sure we don't walk off the edge of the render target
while (resolution > gPipeline.mRT->deferredScreen.getWidth() || while (resolution > gPipeline.mRT->deferredScreen.getWidth() ||
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment