summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl19
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl20
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl25
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl76
4 files changed, 85 insertions, 55 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
index 8ecdafa167..777021cd53 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
@@ -44,9 +44,18 @@ uniform mat4 inv_proj;
uniform vec2 screen_res;
const float M_PI = 3.14159265;
+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
@@ -437,12 +446,12 @@ void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3
// When roughness is zero blender shows a tiny specular
float perceptualRough = max(packedORM.g, 0.1);
- alphaRough = perceptualRough * perceptualRough;
+ alphaRough = perceptualRough * perceptualRough;
}
vec3 BRDFDiffuse(vec3 color)
{
- return color / M_PI;
+ return color * ONE_OVER_PI;
}
vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh )
@@ -452,8 +461,8 @@ vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeigh
vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRough, float specWeight, float vh, float nl, float nv, float nh )
{
- vec3 fresnel = fresnelSchlick( reflect0, reflect90, vh );
- float vis = V_GGX( nl, nv, alphaRough );
- float d = D_GGX( nh, alphaRough );
+ vec3 fresnel = fresnelSchlick( reflect0, reflect90, vh ); // Fresnel
+ float vis = V_GGX( nl, nv, alphaRough ); // Visibility
+ float d = D_GGX( nh, alphaRough ); // Distribution
return specWeight * fresnel * vis * d;
}
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;
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index 356aed9f24..8ee8210fb8 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -25,6 +25,7 @@
#define PBR_USE_ATMOS 1
#define PBR_USE_IBL 1
+#define PBR_USE_SUN 1
#define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight
#define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0
@@ -68,7 +69,7 @@
// IBL Diffuse
#define DEBUG_PBR_DIFFUSE_C 0 // Output: diffuse non metal mix
#define DEBUG_PBR_IRRADIANCE_RAW 0 // Output: Diffuse Irradiance pre-mix
-#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance
+#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance, NOTE: SSAO is factored in
#define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert
#define DEBUG_PBR_EMS 0 // Output: Ems = (1 - BRDF Scale + BRDF Bias)
#define DEBUG_PBR_AVG 0 // Output: Avg
@@ -89,6 +90,10 @@
// Sun
#define DEBUG_PBR_SUN_FULL_BRIGHT 0 // Sunlit color = <1,1,1>
+#define DEBUG_PBR_SUN_OUT_DIFFUSE 0 // Final sun diffuse : intensity * nl * diffuse
+#define DEBUG_PBR_SUN_OUT_SPECULAR 0 // Final sun specular: intensity * nl * specular
+#define DEBUG_PBR_SUN_LAMBERT 0 // BRDF Diffuse: Lambertian Diffuse color
+#define DEBUG_PBR_SUN_LAMBERT_NL 0 // BRDF Diffuse: nl * Lambertian Diffuse color
#define DEBUG_PBR_SUN_H 0 // Half Vector
#define DEBUG_PBR_SUN_L 0 // Light Vector
#define DEBUG_PBR_SUN_V 0 // Surface to Light Vector
@@ -103,8 +108,8 @@
#define DEBUG_PBR_SUN_SPEC_DF 0 // D() * F()
#define DEBUG_PBR_SUN_SPEC_DV 0 // D() * V()
#define DEBUG_PBR_SUN_SPEC_FV 0 // F() * V()
-#define DEBUG_PBR_SUN_SPECULAR 0 // D() * F() * V()
-#define DEBUG_PBR_SUN_SPEC_FUNC 0 // D() * F() * V()
+#define DEBUG_PBR_SUN_SPEC_DFV 0 // D() * F() * V()
+#define DEBUG_PBR_SUN_SPEC_NL_DFV 0 // nl * D() * F() * V()
#define DEBUG_PBR_IOR 0 // Output: grayscale IOR
#define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior
@@ -264,15 +269,11 @@ void main()
packedORM = vec3(1,1,1);
#endif
float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics)
-#if HAS_IOR
- reflect0 = vec3(calcF0(IOR));
-#endif
#if DEBUG_PBR_REFLECT0_BASE
vec3 debug_reflect0 = vec3(calcF0(IOR));
#endif
float ao = packedORM.r;
float metal = packedORM.b;
- vec3 c_diff = mix(diffuse.rgb,vec3(0),metal);
vec3 v = -normalize(pos.xyz);
#if DEBUG_PBR_VERT2CAM1
v = vec3(0,0,1);
@@ -292,15 +293,14 @@ void main()
// Reference: getMetallicRoughnessInfo
vec3 base = linear_to_srgb(diffuse.rgb);
float perceptualRough = max(packedORM.g, 0.1);
- float alphaRough = perceptualRough * perceptualRough;
- vec3 reflect0 = mix(vec3(0.04), base, metal); // incidence reflectance 0.04 -> reflect at 0 degrees
- vec3 reflect90 = vec3(1); // reflect at 90 degrees
+ vec3 c_diff, reflect0, reflect90;
+ float alphaRough, specWeight;
+ initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight );
#if DEBUG_PBR_REFLECTANCE
float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b );
#endif
// Common to RadianceGGX and RadianceLambertian
- float specWeight = 1.0;
vec2 brdfPoint = clamp(vec2(dotNV, perceptualRough), vec2(0,0), vec2(1,1));
vec2 vScaleBias = getGGX( brdfPoint); // Environment BRDF: scale and bias applied to reflect0
vec3 fresnelR = max(vec3(1.0 - perceptualRough), reflect0) - reflect0; // roughness dependent fresnel
@@ -358,66 +358,96 @@ void main()
if (nl > 0.0 || nv > 0.0)
{
+ vec3 sunColor = sunlit * 2.0; // Midday should have strong sunlight
#if DEBUG_PBR_SUN_FULL_BRIGHT
- vec3 sunlit = vec3(1);
+ sunColor = vec3(1);
#endif
- vec3 c_diff, reflect0, reflect90;
- initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight );
-
// scol = sun shadow
- vec3 intensity = ambocc * sunlit * nl * scol;
- colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
- colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
- bloom = dot(colorSpec, colorSpec) / 8.0;
+ vec3 intensity = ambocc * sunColor * nl * scol;
+ vec3 sunDiffuse = intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
+ vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
+ bloom = dot(sunSpec, sunSpec) / 8.0;
#if DEBUG_PBR_SUN_SPEC_FRESNEL
colorDiffuse = vec3(0);
colorSpec = fresnelSchlick( reflect0, reflect90, vh );
+ bloom = 0;
#endif
#if DEBUG_PBR_SUN_SPEC_D
colorDiffuse = vec3(0);
colorSpec = vec3(D_GGX( nh, alphaRough ));
+ bloom = 0;
#endif
#if DEBUG_PBR_SUN_SPEC_V
colorDiffuse = vec3(0);
colorSpec = vec3(V_GGX( nl, nv, alphaRough ));
+ bloom = 0;
#endif
#if DEBUG_PBR_SUN_SPEC_DF
colorDiffuse = vec3(0);
colorSpec = fresnelSchlick( reflect0, reflect90, vh );
colorSpec *= D_GGX( nh, alphaRough );
+ bloom = 0;
#endif
#if DEBUG_PBR_SUN_SPEC_DV
colorDiffuse = vec3(0);
colorSpec = vec3(D_GGX( nh, alphaRough ));
colorSpec *= vec3(V_GGX( nl, nv, alphaRough ));
+ bloom = 0;
#endif
#if DEBUG_PBR_SUN_SPEC_FV
colorDiffuse = vec3(0);
colorSpec = fresnelSchlick( reflect0, reflect90, vh );
colorSpec *= V_GGX( nl, nv, alphaRough );
+ bloom = 0;
#endif
- #if DEBUG_PBR_SUN_SPECULAR
+ #if DEBUG_PBR_SUN_SPEC_DFV
colorDiffuse = vec3(0);
colorSpec = fresnelSchlick( reflect0, reflect90, vh );
colorSpec *= D_GGX( nh, alphaRough );
colorSpec *= V_GGX( nl, nv, alphaRough );
+ bloom = 0;
#endif
- #if DEBUG_PBR_SUN_SPEC_FUNC
+ #if DEBUG_PBR_SUN_SPEC_NL_DFV
colorDiffuse = vec3(0);
colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
#endif
+ #if DEBUG_PBR_SUN_FINAL
+ colorDiffuse = nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
+ colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
+ #endif
- #if DEBUG_PBR_SUN_DIFFUSE
- colorDiffuse = linear_to_srgb(diffuse.rgb);
+ #if DEBUG_PBR_SUN_OUT_DIFFUSE
+ colorDiffuse = linear_to_srgb(sunDiffuse);
+ colorSpec = vec3(0);
+ bloom = 0.0;
+ #endif
+ #if DEBUG_PBR_SUN_OUT_SPECULAR
+ colorDiffuse = linear_to_srgb(sunSpec);
colorSpec = vec3(0);
#endif
#if DEBUG_PBR_SUN_REFLECT0
colorDiffuse = reflect0;
colorSpec = vec3(0);
#endif
+
+#if PBR_USE_SUN
+ colorDiffuse += sunDiffuse;
+ colorSpec += sunSpec;
+#endif
}
+#if DEBUG_PBR_SUN_LAMBERT
+ colorDiffuse = BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
+ colorSpec = vec3(0);
+ bloom = 0;
+#endif
+#if DEBUG_PBR_SUN_LAMBERT_NL
+ colorDiffuse = nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
+ colorSpec = vec3(0);
+ bloom = 0;
+#endif
+
#if DEBUG_PBR_SUN_H
colorDiffuse = h*0.5 + 0.5; colorSpec = vec3(0);
#endif