diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class3')
5 files changed, 205 insertions, 46 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 399948459b..d8e1bba5d8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -27,7 +27,10 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_PBR_LIGHT_TYPE 0 +#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 #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -115,7 +118,7 @@ void main() } #if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0,0.5,0); colorSpec = vec3(0); + colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0); #endif final_color = colorDiffuse + colorSpec; } @@ -175,8 +178,18 @@ void main() } } } + #if DEBUG_LEG_LIGHT_TYPE + final_color.rgb = vec3(0.5,0,0.0); + #endif } +#if DEBUG_POINT_ZERO + final_color = vec3(0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0.3333,0,0); +#endif + frag_color.rgb = final_color; frag_color.a = 0.0; #endif // LOCAL_LIGHT_KILL diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index fdbeb34116..a9a2b8dcb4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -28,8 +28,9 @@ /*[EXTRA_CODE_HERE]*/ +#define DEBUG_ANY_LIGHT_TYPE 0 // Output blue light cone +#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in blue #define DEBUG_PBR_LIGHT_TYPE 0 // Ouput gray if PBR multiSpot lights object -#define DEBUG_PBR_SPOT_ZERO 0 // Output zero for spotlight #define DEBUG_PBR_SPOT 0 #define DEBUG_PBR_SPOT_DIFFUSE 0 // PBR diffuse lit #define DEBUG_PBR_SPOT_SPECULAR 0 // PBR spec lit @@ -44,6 +45,7 @@ #define DEBUG_SPOT_NL 0 // monochome area effected by light #define DEBUG_SPOT_SPEC_POS 0 #define DEBUG_SPOT_REFLECTION 0 // color: pos reflected along n +#define DEBUG_SPOT_ZERO 0 // Output zero for spotlight #define DEBUG_PBR_LIGHT_H 0 // Half vector #define DEBUG_PBR_LIHGT_L 0 // Light vector @@ -108,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); +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); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); @@ -119,13 +122,6 @@ void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 vec3 srgb_to_linear(vec3 cs); vec4 texture2DLodSpecular(vec2 tc, float lod); -vec3 colorized_dot(float x) -{ - if (x > 0.0) return vec3( 0, x, 0 ); - if (x < 0.0) return vec3( x, 0, 0 ); - return vec3( 0, 0, 1 ); -} - vec4 getPosition(vec2 pos_screen); void main() @@ -238,7 +234,7 @@ void main() } #if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0.5); colorSpec = vec3(0); + colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0); #endif #if DEBUG_PBR_LIGHT_H @@ -324,6 +320,9 @@ void main() amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); final_color += diffuse.rgb * amb_rgb; +#if DEBUG_LEG_LIGHT_TYPE + final_color = vec3(0,0,0.5); +#endif } if (spec.a > 0.0) @@ -418,7 +417,10 @@ void main() final_color = reflect(normalize(pos), n); #endif #if DEBUG_SPOT_ZERO - final_color = vec3(0); + final_color = vec3(0,0,0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0,0,0.3333); #endif //not sure why, but this line prevents MATBUG-194 diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 42d7407456..a1298a8409 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -27,7 +27,10 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_PBR_LIGHT_TYPE 0 +#define DEBUG_ANY_LIGHT_TYPE 0 // Output magenta light cone +#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in green +#define DEBUG_PBR_LIGHT_TYPE 0 // Show PBR objects in blue +#define DEBUG_POINT_ZERO 0 // Output zero for point light #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -156,8 +159,19 @@ void main() { discard; } + +#if DEBUG_LEG_LIGHT_TYPE + final_color.rgb = vec3(0,0.25,0); +#endif } +#if DEBUG_POINT_ZERO + final_color = vec3(0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0.25,0,0.25); +#endif + frag_color.rgb = final_color; frag_color.a = 0.0; } 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; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index d82baf0804..41e40a07e7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -28,12 +28,15 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_PBR_LIGHT_TYPE 0 +#define DEBUG_ANY_LIGHT_TYPE 0 // Output green light cone +#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in green +#define DEBUG_PBR_LIGHT_TYPE 0 // Show PBR objects in green #define DEBUG_PBR_SPOT 0 #define DEBUG_PBR_SPOT_DIFFUSE 0 #define DEBUG_PBR_SPOT_SPECULAR 0 #define DEBUG_SPOT_NL 0 // monochome area effected by light +#define DEBUG_SPOT_ZERO 0 // Output zero for spotlight #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -223,6 +226,9 @@ void main() vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); final_color += diffuse.rgb*amb_rgb; + #if DEBUG_LEG_LIGHT_TYPE + final_color = vec3(0,0.5,0); + #endif } if (spec.a > 0.0) @@ -278,6 +284,12 @@ void main() #if DEBUG_SPOT_NL final_color = vec3(nl); #endif +#if DEBUG_SPOT_ZERO + final_color = vec3(0,0,0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0,0.3333,0); +#endif //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); |