summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class3/deferred
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred')
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl9
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl5
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl44
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl5
5 files changed, 46 insertions, 19 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl
index 71135786c3..c7c241b76e 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl
@@ -30,7 +30,7 @@
#define DEBUG_ANY_LIGHT_TYPE 0 // Output red light cone
#define DEBUG_PBR_LIGHT_TYPE 0 // Output PBR objects in red
#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in red
-#define DEBUG_POINT_ZERO 0 // Output zero for spotlight
+#define DEBUG_POINT_ZERO 0 // Output zero for point lights
#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
@@ -113,11 +113,10 @@ void main()
vec3 lv =(light [ light_idx ].xyz - pos);
calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);
- if (nl > 0.0)
+ float dist = lightDist / lightSize;
+ if (dist <= 1.0 && nl > 0.0)
{
- float dist = lightDist / lightSize;
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);
@@ -148,7 +147,7 @@ void main()
float lightDist;
calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);
- float fa = light_col[i].a + 1.0;
+ float fa = light_col[i].a;
float dist_atten = calcLegacyDistanceAttenuation(dist, fa);
dist_atten *= noise;
diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl
index a9a2b8dcb4..3efc9c1689 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl
@@ -110,6 +110,7 @@ uniform mat4 inv_proj;
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 colorized_dot(float x);
bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc );
vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v);
@@ -155,9 +156,7 @@ void main()
vec3 n;
vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity);
- 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 (dist_atten <= 0.0)
{
discard;
diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
index 83348077d7..1f5fdde9ca 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
@@ -364,7 +364,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i)
v -= c;
v = env_mat * v;
{
- return texture(irradianceProbes, vec4(v.xyz, refIndex[i].x)).rgb * refParams[i].x;
+ return textureLod(irradianceProbes, vec4(v.xyz, refIndex[i].x), 0).rgb * refParams[i].x;
}
}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index 8a04a8a6a6..e96b39a149 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -27,6 +27,10 @@
#define PBR_USE_IBL 1
#define PBR_USE_SUN 1
+#define PBR_USE_LINEAR_ALBEDO 1
+#define PBR_USE_DEFAULT_IRRADIANCE 0 // PBR: irradiance, skins/default/textures/default_irradiance.png
+#define PBR_USE_IRRADIANCE_HACK 1
+
#define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight
#define DEBUG_PBR_PACK_ORM0 0 // Rough=0, Metal=0
#define DEBUG_PBR_PACK_ORM1 0 // Rough=1, Metal=1
@@ -137,6 +141,9 @@ uniform sampler2DRect diffuseRect;
uniform sampler2DRect specularRect;
uniform sampler2DRect normalMap;
uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
+uniform sampler2D altDiffuseMap; // PBR: irradiance, skins/default/textures/default_irradiance.png
+
+const float M_PI = 3.14159265;
#if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO)
uniform sampler2DRect lightMap;
@@ -209,12 +216,7 @@ void main()
norm.xyz = getNorm(tc);
vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
- float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
-#if DEBUG_PBR_DA_RAW
- float debug_da = da;
-#endif
float light_gamma = 1.0 / 1.3;
- da = pow(da, light_gamma);
vec4 diffuse = texture2DRect(diffuseRect, tc);
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR sRGB Emissive
@@ -297,8 +299,12 @@ void main()
float bv = clamp(dot(b,v),0,1);
// Reference: getMetallicRoughnessInfo
+#if PBR_USE_LINEAR_ALBEDO
+ vec3 base = diffuse.rgb;
+#else
vec3 base = linear_to_srgb(diffuse.rgb);
- float perceptualRough = max(packedORM.g, 0.1);
+#endif
+ float perceptualRough = packedORM.g; // NOTE: do NOT clamp here to be consistent with Blender, Blender is wrong and Substance is right
vec3 c_diff, reflect0, reflect90;
float alphaRough, specWeight;
initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight );
@@ -323,7 +329,14 @@ void main()
#if DEBUG_PBR_IRRADIANCE_RAW
vec3 debug_irradiance = irradiance;
#endif
+
+#if PBR_USE_DEFAULT_IRRADIANCE
+ vec2 iruv = vec2(0.5f + 0.5f * atan(reflectVN.z, reflectVN.x) / M_PI, 1.f - acos(reflectVN.y) / M_PI);
+ irradiance = texture2D(altDiffuseMap, iruv).rgb * ambocc;
+#endif
+#if PBR_USE_IRRADIANCE_HACK
irradiance = max(amblit,irradiance) * ambocc;
+#endif
specLight = srgb_to_linear(specLight);
#if DEBUG_PBR_SPECLIGHT051
specLight = vec3(0,0.5,1.0);
@@ -364,9 +377,17 @@ void main()
#endif
// scol = sun shadow
vec3 intensity = ambocc * sunColor * nl * scol;
+#if PBR_USE_LINEAR_ALBEDO
+ vec3 sunDiffuse = intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
+ vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
+#else
vec3 sunDiffuse = base * intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh);
vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
- bloom = dot(sunSpec, sunSpec) / (scale * scale * scale);
+#endif
+ // Disabling PBR bloom due to two reasons:
+ // 1. The glTF 2.0 Specification does not specify bloom,
+ // 2. As the camera moves there are lots of bloom shimmering.
+ //bloom = dot(sunSpec, sunSpec) / (scale * scale * scale);
#if DEBUG_PBR_SUN_SPEC_FRESNEL
colorDiffuse = vec3(0);
@@ -576,9 +597,11 @@ void main()
#endif
#if DEBUG_PBR_IRRADIANCE_RAW
color.rgb = debug_irradiance;
+ bloom = 0;
#endif
#if DEBUG_PBR_IRRADIANCE
color.rgb = irradiance;
+ bloom = 0;
#endif
#if DEBUG_PBR_KSPEC
color.rgb = kSpec;
@@ -632,10 +655,17 @@ void main()
#if DEBUG_PBR_LIGHT_TYPE
color.rgb = vec3(0);
#endif
+
frag_color.rgb = color.rgb; // PBR is done in linear
}
else
{
+ float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
+#if DEBUG_PBR_DA_RAW
+ float debug_da = da;
+#endif
+ da = pow(da, light_gamma);
+
diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035
sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity);
diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
index 769589eff1..8cdf9e49b4 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
@@ -85,6 +85,7 @@ uniform mat4 inv_proj;
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);
bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc );
vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v);
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity);
@@ -129,9 +130,7 @@ void main()
vec3 n;
vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG()
- 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 (dist_atten <= 0.0)
{
discard;