diff options
| -rwxr-xr-x | 3ner.shader | 26 | ||||
| -rw-r--r-- | filamented.cginc | 4 | ||||
| -rwxr-xr-x | globals.cginc | 2 | ||||
| -rwxr-xr-x | lighting.cginc | 32 |
4 files changed, 31 insertions, 33 deletions
diff --git a/3ner.shader b/3ner.shader index 183dec1..68b947b 100755 --- a/3ner.shader +++ b/3ner.shader @@ -38,6 +38,18 @@ Shader "yum_food/3ner" _Metallic("Metallic", Range(0, 1)) = 0 _Glossiness("Smoothness", Range(0, 1)) = 0.5 + [HideInInspector] m_start_IBL("Image-based lighting", Float) = 0 + _Exposure_Occlusion("Exposure Occlusion", Range(0.001, 10)) = 0.2 + + //ifex _Bent_Normals_Enabled==0 + [HideInInspector] m_start_Bent_Normals("Bent Normals", Float) = 0 + [ThryToggle(_BENT_NORMALS)] _Bent_Normals_Enabled("Enable", Float) = 0 + [Normal] _Bent_Normals_Map("Bent Normals", 2D) = "white" {} + _Bent_Normals_Strength("Bent Normals Strength", Range(0, 10)) = 1 + [HideInInspector] m_end_Bent_Normals("Bent Normals", Float) = 0 + //endex + [HideInInspector] m_end_IBL("Image-based lighting", Float) = 0 + //ifex _Emissions_Enabled==0 [HideInInspector] m_start_Emissions("Emissions", Float) = 0 [ThryToggle(_EMISSIONS)] _Emissions_Enabled("Enable", Float) = 0 @@ -615,15 +627,15 @@ Shader "yum_food/3ner" //ifex _Brightness_Clamp_Enabled==0 [HideInInspector] m_start_Brightness_Clamp("Brightness Clamp", Float) = 0 [ThryToggle(_BRIGHTNESS_CLAMP)] _Brightness_Clamp_Enabled("Enable", Float) = 0 - _Brightness_Clamp_Min("Min", Range(0, 1)) = 0.05 - _Brightness_Clamp_Max("Max", Range(0, 10)) = 10 + [DoNotLock] _Brightness_Clamp_Min("Min", Range(0, 1)) = 0.05 + [DoNotLock] _Brightness_Clamp_Max("Max", Range(0, 10)) = 10 [HideInInspector] m_end_Brightness_Clamp("Brightness Clamp", Float) = 0 //endex //ifex _Wrapped_Lighting_Enabled==0 [HideInInspector] m_start_Wrapped_Lighting("Wrapped Lighting", Float) = 0 [ThryToggle(_WRAPPED_LIGHTING)] _Wrapped_Lighting_Enabled("Enable", Float) = 0 - _Wrapped_Lighting_Amount("Amount", Range(0, 1)) = 0.5 + [DoNotLock] _Wrapped_Lighting_Amount("Amount", Range(0, 1)) = 0.5 [HideInInspector] m_end_Wrapped_Lighting("Wrapped Lighting", Float) = 0 //endex @@ -636,14 +648,6 @@ Shader "yum_food/3ner" [HideInInspector] m_end_Outlines("Outlines", Float) = 0 //endex - //ifex _Bent_Normals_Enabled==0 - [HideInInspector] m_start_Bent_Normals("Bent Normals", Float) = 0 - [ThryToggle(_BENT_NORMALS)] _Bent_Normals_Enabled("Enable", Float) = 0 - [Normal] _Bent_Normals_Map("Bent Normals", 2D) = "white" {} - _Bent_Normals_Strength("Bent Normals Strength", Range(0, 10)) = 1 - [HideInInspector] m_end_Bent_Normals("Bent Normals", Float) = 0 - //endex - //ifex _Glitter_Enabled==0 [HideInInspector] m_start_Glitter("Glitter", Float) = 0 [ThryToggle(_GLITTER)] _Glitter_Enabled("Enable", Float) = 0 diff --git a/filamented.cginc b/filamented.cginc index 6d34123..63552c2 100644 --- a/filamented.cginc +++ b/filamented.cginc @@ -301,7 +301,7 @@ inline half3 UnityGI_prefilteredRadiance(const UnityGIInput data, const float pe return specular; } -#if defined(_AMBIENT_OCCLUSION) || defined(_BENT_NORMALS) +#if defined(_BENT_NORMALS) // Oat and Sander 2007, "Ambient Aperture Lighting" // Jimenez et al. 2016, "Practical Realtime Strategies for Accurate Indirect Occlusion" float sphericalCapsIntersection(float cosCap1, float cosCap2, float cosDistance) { @@ -321,6 +321,7 @@ float sphericalCapsIntersection(float cosCap1, float cosCap2, float cosDistance) float area = -2.0 * x2 * x + 3.0 * x2; return area * (1.0 - max(cosCap1, cosCap2)); } +#endif // _BENT_NORMALS float computeSpecularAO(float NoV, float visibility, float roughness, float3 bent_normal, float3 reflect_dir) { #if defined(_BENT_NORMALS) @@ -334,6 +335,5 @@ float computeSpecularAO(float NoV, float visibility, float roughness, float3 ben return saturate(pow(NoV + visibility, exp2(-16.0 * roughness - 1.0)) - 1.0 + visibility); #endif } -#endif // _AMBIENT_OCCLUSION || _BENT_NORMALS #endif // __FILAMENTED_INC diff --git a/globals.cginc b/globals.cginc index 0de9812..6d54720 100755 --- a/globals.cginc +++ b/globals.cginc @@ -29,6 +29,8 @@ float4 _MetallicGlossMap_ST; float _Glossiness; float _Metallic; +float _Exposure_Occlusion; + texture2D _DFG_LUT; float _Specular_AA_Variance; float _Specular_AA_Threshold; diff --git a/lighting.cginc b/lighting.cginc index 9ea2052..2e3a79b 100755 --- a/lighting.cginc +++ b/lighting.cginc @@ -34,9 +34,10 @@ float4 getDirectLightColorIntensity() { return float4(_LightColor0.xyz, _LightColor0.w); } -float3 getIndirectSpecular(v2f i, float perceptual_roughness, float3 view_dir, float3 reflect_dir) { +float3 getIndirectSpecular(v2f i, float perceptual_roughness, float3 view_dir, float3 reflect_dir, float3 indirect_diffuse) { UnityGIInput data = InitialiseUnityGIInput(i.worldPos, view_dir); float3 env_refl = UnityGI_prefilteredRadiance(data, perceptual_roughness, reflect_dir); + return env_refl; } @@ -173,35 +174,26 @@ float getAO(v2f i) { } float getSpecularAO(v2f i, Pbr pbr, LightData data, float3 reflect_dir) { - float spec_ao = 1; -#if defined(_AMBIENT_OCCLUSION) || defined(_BENT_NORMALS) float ao_vis = 1.0; #if defined(_AMBIENT_OCCLUSION) ao_vis = data.common.ao; #endif + + // Exposure occlusion: derive specular AO from diffuse irradiance magnitude. + // When IBL diffuse goes dark, attenuate specular to avoid implausible + // reflections. Based on filamented's IrradianceToExposureOcclusion. + float exposure_ao = saturate(length(data.indirect.diffuse) / _Exposure_Occlusion); + ao_vis *= exposure_ao; + #if defined(_BENT_NORMALS) float3 spec_ao_normal = pbr.bent_normal; #else float3 spec_ao_normal = pbr.normal; #endif - spec_ao = computeSpecularAO(data.common.NoV, ao_vis, pbr.roughness, spec_ao_normal, -data.indirect.dir); + float spec_ao = computeSpecularAO(data.common.NoV, ao_vis, pbr.roughness, spec_ao_normal, -data.indirect.dir); #if defined(_BENT_NORMALS) spec_ao = saturate(lerp(1.0, spec_ao, _Bent_Normals_Strength)); #endif -#endif - - // Didn't see a big difference in testbed, so commented out. - // Bent normals get us most of what we want. -#if 0 - // Horizon fading - // https://marmosetco.tumblr.com/post/81245981087 - // The goal is to attenuate anything which points into the mesh. - // TODO expose fade strength as a parameter. - float horizon_fade_str = 1.3; - float horizon_fade = saturate(1.0f + horizon_fade_str * dot(pbr.normal, -reflect_dir)); - horizon_fade *= horizon_fade; - spec_ao *= horizon_fade; -#endif return spec_ao; } @@ -259,13 +251,13 @@ void GetLighting(v2f i, Pbr pbr, out LightData data) { data.indirect.double_LoV = saturate(2.0f * indirect_LoV * indirect_LoV - 1.0f); data.indirect.diffuse = getIndirectDiffuse(i, pbr, data); - data.indirect.specular = getIndirectSpecular(i, pbr.roughness_perceptual, view_dir, data.indirect.dir); + data.indirect.specular = getIndirectSpecular(i, pbr.roughness_perceptual, view_dir, data.indirect.dir, data.indirect.diffuse); data.common.ao = getAO(i); data.common.spec_ao = getSpecularAO(i, pbr, data, reflect_dir); #if defined(_CLEARCOAT) - data.indirect.specular_cc = getIndirectSpecular(i, pbr.cc_roughness_perceptual, view_dir, dir_cc); + data.indirect.specular_cc = getIndirectSpecular(i, pbr.cc_roughness_perceptual, view_dir, dir_cc, data.indirect.diffuse); #if defined(_CLEARCOAT_MASK) float cc_mask = _Clearcoat_Mask.Sample(bilinear_clamp_s, i.uv01.xy).r; data.indirect.specular_cc *= cc_mask; |
