summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorPtolemy <ptolemy@lindenlab.com>2022-08-24 17:21:32 -0700
committerPtolemy <ptolemy@lindenlab.com>2022-08-24 17:21:32 -0700
commitbecdf08d0f79a1a676fdc51d5c889dbab5954832 (patch)
treee0c14fb1b59cd1e23fa2a81c31030f8518944eab /indra
parent5b7d8b61e0720aee1ef6c7d6e44ada87ca556d54 (diff)
SL-17702: PBR: Use legacy attenuation for point lights
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl8
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl20
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl25
3 files changed, 26 insertions, 27 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
index d1b9418ee9..a49713afce 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
@@ -48,6 +48,14 @@ const float ONE_OVER_PI = 0.3183098861;
vec3 srgb_to_linear(vec3 cs);
+float calcLegacyDistanceAttenuation(float distance, float falloff)
+{
+ float dist_atten = 1.0 - clamp((distance + falloff)/(1.0 + falloff), 0.0, 1.0);
+ dist_atten *= dist_atten;
+ dist_atten *= 2.0;
+ return dist_atten;
+}
+
// In:
// lv unnormalized surface to light vector
// n normal of the surface
diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl
index d8e1bba5d8..98a03c2aaa 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl
@@ -60,6 +60,7 @@ VARYING vec4 vary_fragcoord;
vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh );
vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh );
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
+float calcLegacyDistanceAttenuation(float distance, float falloff);
vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance);
vec4 getPosition(vec2 pos_screen);
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity);
@@ -108,12 +109,11 @@ void main()
if (nl > 0.0)
{
float dist = lightDist / lightSize;
- float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff);
- dist_atten *= dist_atten;
- dist_atten *= 2.0;
- vec3 intensity = dist_atten * getLightIntensityPoint(lightColor, lightSize, lightDist);
- colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
- colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
+ float dist_atten = calcLegacyDistanceAttenuation(dist, falloff);
+
+ vec3 intensity = dist_atten * nl * lightColor;
+ colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
+ colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
}
}
@@ -146,13 +146,7 @@ void main()
calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);
float fa = light_col[i].a + 1.0;
- float dist_atten = clamp(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 0.0, 1.0);
- dist_atten *= dist_atten;
-
- // Tweak falloff slightly to match pre-EEP attenuation
- // NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit
- dist_atten *= 2.0;
-
+ float dist_atten = calcLegacyDistanceAttenuation(dist, fa);
dist_atten *= noise;
float lit = nl * dist_atten;
diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl
index a1298a8409..d65a53b6d3 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl
@@ -65,6 +65,7 @@ uniform vec4 viewport;
vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh );
vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh );
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
+float calcLegacyDistanceAttenuation(float distance, float falloff);
vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance);
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity);
vec4 getPosition(vec2 pos_screen);
@@ -91,10 +92,12 @@ void main()
float nh, nl, nv, vh, lightDist;
calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);
+ if (lightDist >= size)
+ {
+ discard;
+ }
float dist = lightDist / size;
- float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff);
- dist_atten *= dist_atten;
- dist_atten *= 2.0;
+ float dist_atten = calcLegacyDistanceAttenuation(dist, falloff);
if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))
{
@@ -102,6 +105,8 @@ void main()
vec3 colorSpec = vec3(0);
vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl
vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
+ float lightSize = size;
+ vec3 lightColor = color;
vec3 c_diff, reflect0, reflect90;
float alphaRough, specWeight;
@@ -109,26 +114,18 @@ void main()
if (nl > 0.0)
{
- vec3 intensity = dist_atten * getLightIntensityPoint(color, size, lightDist);
- colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
- colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
+ vec3 intensity = dist_atten * nl * lightColor; // Legacy attenuation
+ colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
+ colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
}
#if DEBUG_PBR_LIGHT_TYPE
colorDiffuse = vec3(0,0,0.5); colorSpec = vec3(0);
#endif
-
final_color = colorDiffuse + colorSpec;
}
else
{
- float dist = lightDist;
- if (dist >= size)
- {
- discard;
- }
- dist /= size;
-
if (nl < 0.0)
{
discard;