summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl182
1 files changed, 150 insertions, 32 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index 18a2aeaeaa..356aed9f24 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -24,7 +24,7 @@
*/
#define PBR_USE_ATMOS 1
-#define PBR_USE_GGX_EMS_HACK 0
+#define PBR_USE_IBL 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
@@ -59,6 +59,8 @@
#define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel
#define DEBUG_PBR_KSPEC 0 // Output: K spec
#define DEBUG_PBR_REFLECTION_DIR 0 // Output: reflection dir
+#define DEBUG_PBR_SPEC_IBL 0 // Output: IBL specularity
+#define DEBUG_PBR_SPEC_LEGACY 0 // Output: legacyenv
#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection
#define DEBUG_PBR_FSS_ESS_GGX 0 // Output: FssEssGGX
#define DEBUG_PBR_SPEC 0 // Output: Final spec
@@ -76,6 +78,7 @@
#define DEBUG_PBR_DIFFUSE 0 // Output: diffuse post AO
// Atmospheric Lighting
+#define DEBUG_PBR_AMBENV 0 // Output: ambient environment
#define DEBUG_PBR_AMBOCC 0 // Output: ambient occlusion
#define DEBUG_PBR_DA_RAW 0 // Output: da pre pow()
#define DEBUG_PBR_DA_POW 0 // Output: da post pow()
@@ -84,6 +87,25 @@
#define DEBUG_PBR_SKY_ADDITIVE 0 // Output: additive
#define DEBUG_PBR_SKY_ATTEN 0 // Output: greyscale atten.r
+// Sun
+#define DEBUG_PBR_SUN_FULL_BRIGHT 0 // Sunlit color = <1,1,1>
+#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
+#define DEBUG_PBR_SUN_NH 0 // dot(n,h)
+#define DEBUG_PBR_SUN_NL 0 // dot(n,l)
+#define DEBUG_PBR_SUN_NV 0 // dot(n,v)
+#define DEBUG_PBR_SUN_VH 0 // dot(v,h)
+#define DEBUG_PBR_SUN_REFLECT0 0 // reflect0 only
+#define DEBUG_PBR_SUN_SPEC_FRESNEL 0 // Fresnel
+#define DEBUG_PBR_SUN_SPEC_D 0 // D(h)
+#define DEBUG_PBR_SUN_SPEC_V 0 // V(l,v,h)
+#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_IOR 0 // Output: grayscale IOR
#define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior
#define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior
@@ -133,9 +155,16 @@ uniform vec2 screen_res;
vec3 getNorm(vec2 pos_screen);
vec4 getPositionWithDepth(vec2 pos_screen, float depth);
+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 calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);
+float calcF0(float ior);
+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 getAmbientClamp();
vec2 getGGX( vec2 brdfPoint );
+void initMaterial( vec3 diffuse, vec3 packedORM,
+ out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight );
vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
vec3 scaleSoftClipFrag(vec3 l);
vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten);
@@ -150,18 +179,18 @@ void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3
vec3 linear_to_srgb(vec3 c);
vec3 srgb_to_linear(vec3 c);
+// Debug Utils
+vec3 BRDFDiffuse(vec3 color);
+vec3 fresnelSchlick( vec3 reflect0, vec3 reflect90, float vh);
+float D_GGX( float nh, float alphaRough );
+float V_GGX( float nl, float nv, float alphaRough );
+
#ifdef WATER_FOG
vec4 applyWaterFogView(vec3 pos, vec4 color);
#endif
uniform vec3 view_dir; // PBR
-vec3 calcBaseReflect0(float ior)
-{
- vec3 reflect0 = vec3(pow((ior - 1.0) / (ior + 1.0), 2.0));
- return reflect0;
-}
-
void main()
{
vec2 tc = vary_fragcoord.xy;
@@ -235,17 +264,15 @@ void main()
packedORM = vec3(1,1,1);
#endif
float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics)
- vec3 reflect0 = vec3(0.04); // -> incidence reflectance 0.04
#if HAS_IOR
- reflect0 = calcBaseReflect0(IOR);
+ reflect0 = vec3(calcF0(IOR));
#endif
#if DEBUG_PBR_REFLECT0_BASE
- vec3 debug_reflect0 = reflect0;
+ 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 reflect90 = vec3(0);
vec3 v = -normalize(pos.xyz);
#if DEBUG_PBR_VERT2CAM1
v = vec3(0,0,1);
@@ -263,11 +290,11 @@ void main()
float dotBV = clamp(dot(b,v),0,1);
// Reference: getMetallicRoughnessInfo
- float perceptualRough = packedORM.g;
+ vec3 base = linear_to_srgb(diffuse.rgb);
+ float perceptualRough = max(packedORM.g, 0.1);
float alphaRough = perceptualRough * perceptualRough;
- vec3 colorDiff = mix( diffuse.rgb, vec3(0) , metal);
- reflect0 = mix( reflect0 , diffuse.rgb, metal); // reflect at 0 degrees
- reflect90 = vec3(1); // reflect at 90 degrees
+ vec3 reflect0 = mix(vec3(0.04), base, metal); // incidence reflectance 0.04 -> reflect at 0 degrees
+ vec3 reflect90 = vec3(1); // reflect at 90 degrees
#if DEBUG_PBR_REFLECTANCE
float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b );
#endif
@@ -300,7 +327,12 @@ void main()
kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor);
#endif
vec3 FssEssGGX = kSpec*vScaleBias.x + vScaleBias.y;
+#if DEBUG_PBR_SPEC_IBL
+ vec3 debug_color_spec = specWeight * specLight * FssEssGGX;
+#endif
+#if PBR_USE_IBL
colorSpec += specWeight * specLight * FssEssGGX;
+#endif
// Reference: getIBLRadianceLambertian
vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term
@@ -309,28 +341,109 @@ void main()
vec3 AvgEms = avg * Ems;
vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms);
vec3 kDiffuse = c_diff * (1.0 - FssEssLambert + FmsEms);
+#if PBR_USE_IBL
colorDiffuse += (FmsEms + kDiffuse) * irradiance;
+#endif
#if DEBUG_PBR_DIFFUSE_PRE_AO
vec3 debug_diffuse = colorDiffuse;
#endif
- colorDiffuse *= packedORM.r; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r
+
+ colorDiffuse *= ao; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r
+ colorSpec *= ao;
// Add in sun/moon reflection
- if (metal > 0.0)
+ vec3 h, l;
+ float nh, nl, nv, vh, lightDist;
+ calcHalfVectors(light_dir, n, v, h, l, nh, nl, nv, vh, lightDist);
+
+ if (nl > 0.0 || nv > 0.0)
{
- vec3 r = reflect(pos.xyz, norm.xyz);
- float sa = dot(normalize(r), light_dir.xyz);
- float sun = texture2D(lightFunc, vec2(sa, metal)).r;
- vec3 sunSpec = sunlit * scol * sun;
- colorSpec += sunSpec * metal;
- bloom = dot(sunSpec, sunSpec) / 6;
+#if DEBUG_PBR_SUN_FULL_BRIGHT
+ vec3 sunlit = 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;
+
+ #if DEBUG_PBR_SUN_SPEC_FRESNEL
+ colorDiffuse = vec3(0);
+ colorSpec = fresnelSchlick( reflect0, reflect90, vh );
+ #endif
+ #if DEBUG_PBR_SUN_SPEC_D
+ colorDiffuse = vec3(0);
+ colorSpec = vec3(D_GGX( nh, alphaRough ));
+ #endif
+ #if DEBUG_PBR_SUN_SPEC_V
+ colorDiffuse = vec3(0);
+ colorSpec = vec3(V_GGX( nl, nv, alphaRough ));
+ #endif
+ #if DEBUG_PBR_SUN_SPEC_DF
+ colorDiffuse = vec3(0);
+ colorSpec = fresnelSchlick( reflect0, reflect90, vh );
+ colorSpec *= D_GGX( nh, alphaRough );
+ #endif
+ #if DEBUG_PBR_SUN_SPEC_DV
+ colorDiffuse = vec3(0);
+ colorSpec = vec3(D_GGX( nh, alphaRough ));
+ colorSpec *= vec3(V_GGX( nl, nv, alphaRough ));
+ #endif
+ #if DEBUG_PBR_SUN_SPEC_FV
+ colorDiffuse = vec3(0);
+ colorSpec = fresnelSchlick( reflect0, reflect90, vh );
+ colorSpec *= V_GGX( nl, nv, alphaRough );
+ #endif
+ #if DEBUG_PBR_SUN_SPECULAR
+ colorDiffuse = vec3(0);
+ colorSpec = fresnelSchlick( reflect0, reflect90, vh );
+ colorSpec *= D_GGX( nh, alphaRough );
+ colorSpec *= V_GGX( nl, nv, alphaRough );
+ #endif
+ #if DEBUG_PBR_SUN_SPEC_FUNC
+ colorDiffuse = vec3(0);
+ colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
+ #endif
+
+ #if DEBUG_PBR_SUN_DIFFUSE
+ colorDiffuse = linear_to_srgb(diffuse.rgb);
+ colorSpec = vec3(0);
+ #endif
+ #if DEBUG_PBR_SUN_REFLECT0
+ colorDiffuse = reflect0;
+ colorSpec = vec3(0);
+ #endif
}
+
+ #if DEBUG_PBR_SUN_H
+ colorDiffuse = h*0.5 + 0.5; colorSpec = vec3(0);
+ #endif
+ #if DEBUG_PBR_SUN_L
+ colorDiffuse = l*0.5 + 0.5; colorSpec = vec3(0);
+ #endif
+ #if DEBUG_PBR_SUN_V
+ colorDiffuse = v*0.5 + 0.5; colorSpec = vec3(0);
+ #endif
+ #if DEBUG_PBR_SUN_NH
+ colorDiffuse = colorize_dot(nh); colorSpec = vec3(0);
+ #endif
+ #if DEBUG_PBR_SUN_NL
+ colorDiffuse = colorize_dot(nl); colorSpec = vec3(0);
+ #endif
+ #if DEBUG_PBR_SUN_NV
+ colorDiffuse = colorize_dot(nv); colorSpec = vec3(0);
+ #endif
+ #if DEBUG_PBR_SUN_VH
+ colorDiffuse = colorize_dot(vh); colorSpec = vec3(0);
+ #endif
+
color.rgb = colorDiffuse + colorEmissive + colorSpec;
- vec3 sun_contrib = min(da, scol) * sunlit;
#if PBR_USE_ATMOS
color = linear_to_srgb(color);
- color += 2.0*sun_contrib; // 2x = Undo legacy hack of calcAtmosphericVars() returning sunlight.rgb * 0.5;
color *= atten.r;
color += 2.0*additive;
color = scaleSoftClipFrag(color);
@@ -350,7 +463,7 @@ void main()
color.rgb = diffuse.rgb;
#endif
#if DEBUG_PBR_OCCLUSION
- color.rgb = vec3(packedORM.r);
+ color.rgb = vec3(ao);
#endif
#if DEBUG_PBR_ORM
color.rgb = packedORM;
@@ -468,9 +581,6 @@ void main()
color.rgb = v*0.5 + vec3(0.5);
#endif
- #if DEBUG_PBR_AMBOCC
- color.rgb = vec3(ambocc);
- #endif
#if DEBUG_PBR_DA_RAW
color.rgb = vec3(debug_da);
#endif
@@ -535,7 +645,7 @@ else
if (envIntensity > 0.0)
{ // add environmentmap
//fudge darker
- legacyenv *= 0.5*diffuse.a+0.5;;
+ legacyenv *= 0.5*diffuse.a+0.5;
applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity);
}
@@ -550,12 +660,20 @@ else
color = fogged.rgb;
bloom = fogged.a;
#endif
+ #if DEBUG_PBR_LIGHT_TYPE
+ color.rgb = vec3(0);
+ #endif
// convert to linear as fullscreen lights need to sum in linear colorspace
// and will be gamma (re)corrected downstream...
- //color = vec3(ambocc);
//color = ambenv;
//color.b = diffuse.a;
frag_color.rgb = srgb_to_linear(color.rgb);
}
+#if DEBUG_PBR_AMBOCC
+ frag_color.rgb = vec3(ambocc);
+#endif
+#if DEBUG_PBR_AMBENV
+ frag_color.rgb = ambenv;
+#endif
frag_color.a = bloom;
}