summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--2ner.shader4
-rw-r--r--features.cginc4
-rw-r--r--math.cginc6
-rw-r--r--yum_brdf.cginc4
-rw-r--r--yum_lighting.cginc13
5 files changed, 23 insertions, 8 deletions
diff --git a/2ner.shader b/2ner.shader
index 42fc187..1dc1bdc 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -74,7 +74,6 @@ Shader "yum_food/2ner"
[HideInInspector] m_reflectionOptions("Reflections", Float) = 0
[HideInInspector] m_start_Metallic("Metallics", Float) = 0
[ThryToggle(_METALLICS)]_Metallics_Enabled("Enable", Float) = 0
- _MetallicMask("Metallic Mask", 2D) = "white" {}
_Metallic("Metallic", Range(0, 1)) = 0
_Smoothness("Smoothness", Range(0, 1)) = 0
_MetallicGlossMap("Metallic gloss map", 2D) = "white" {}
@@ -880,6 +879,9 @@ Shader "yum_food/2ner"
[MaterialToggle] _Fallback_Cubemap_Force("Force", Float) = 0
_Fallback_Cubemap("Cubemap", Cube) = "" {}
_Fallback_Cubemap_Brightness("Brightness", Float) = 1.0
+ [HideInInspector] m_start_Fallback_Cubemap_Limit_Metallic("Limit override to metallic", Float) = 0
+ [ThryToggle(_FALLBACK_CUBEMAP_LIMIT_METALLIC)] _Fallback_Cubemap_Limit_Metallic("Enable", Float) = 0
+ [HideInInspector] m_end_Fallback_Cubemap_Limit_Metallic("Limit override to metallic", Float) = 0
[HideInInspector] m_end_Fallback_Cubemap("Fallback Cubemap", Float) = 0
//endex
//ifex _Receive_Shadows_Enabled==0
diff --git a/features.cginc b/features.cginc
index b753f31..766d1cd 100644
--- a/features.cginc
+++ b/features.cginc
@@ -26,6 +26,10 @@
#pragma shader_feature_local _FALLBACK_CUBEMAP
//endex
+//ifex _Fallback_Cubemap_Limit_Metallic_Enabled==0
+#pragma shader_feature_local _FALLBACK_CUBEMAP_LIMIT_METALLIC
+//endex
+
//ifex _Wrapped_Lighting_Enabled==0
#pragma shader_feature_local _WRAPPED_LIGHTING
//endex
diff --git a/math.cginc b/math.cginc
index bccb206..6c48a2c 100644
--- a/math.cginc
+++ b/math.cginc
@@ -16,10 +16,10 @@ float pow5(float x)
}
float wrapNoL(float NoL, float k) {
-#if 0
+#if 1
// https://www.iro.umontreal.ca/~derek/files/jgt_wrap_final.pdf
return pow(max(1E-4, (NoL + k) / (1 + k)), 1 + k);
-#else
+#else
float k_sq = k * k;
float b = max(0, lerp(NoL, 1.0, k));
float p = -6.0 * k_sq + 5.0 * k + 1.0;
@@ -27,7 +27,7 @@ float wrapNoL(float NoL, float k) {
float F = pow(b, p);
// Approximate integral of NoL with respect to theta
- float I = 0.7856 * k_sq - 0.2148 * k + 1.0;
+ float I = (0.7856 * k_sq - 0.2148 * k) + 1.0;
float G = F / max(I, 1E-6);
diff --git a/yum_brdf.cginc b/yum_brdf.cginc
index 8b0d659..9e44626 100644
--- a/yum_brdf.cginc
+++ b/yum_brdf.cginc
@@ -82,9 +82,9 @@ float4 YumBRDF(v2f i, const YumLighting light, YumPbr pbr) {
#if defined(_MATERIAL_TYPE_CLOTH_SUBSURFACE)
// No need to multiply by NoL when using subsurface scattering
- direct_cloth = (Fd + Fr * NoL_wrapped_d) * light.direct * _Cloth_Direct_Multiplier;
+ direct_cloth = (Fd + Fr * NoL) * light.direct * _Cloth_Direct_Multiplier;
#else
- direct_cloth = (Fd + Fr) * NoL_wrapped_d * light.direct * _Cloth_Direct_Multiplier;
+ direct_cloth = (Fd + Fr) * NoL * light.direct * _Cloth_Direct_Multiplier;
#endif
}
#endif
diff --git a/yum_lighting.cginc b/yum_lighting.cginc
index 3af5654..b2a7952 100644
--- a/yum_lighting.cginc
+++ b/yum_lighting.cginc
@@ -124,8 +124,11 @@ float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir, float diffuse_lum
data.probePosition[1] = unity_SpecCube1_ProbePosition;
#endif
+ const float3 env_refl = UnityGI_prefilteredRadiance(data, roughness, reflect_dir);
+
#if defined(_FALLBACK_CUBEMAP)
// Check if there's no valid scene cubemap
+ float3 canned_refl = env_refl;
if (!SceneHasReflections() || _Fallback_Cubemap_Force) {
// Set up data for fallback sampling similar to Unity's system
half3 reflectVector = reflect(-view_dir, pbr.normal);
@@ -136,11 +139,17 @@ float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir, float diffuse_lum
half mip = roughness * UNITY_SPECCUBE_LOD_STEPS;
float4 envSample = UNITY_SAMPLE_TEXCUBE_LOD(_Fallback_Cubemap, reflectVector, mip);
- return DecodeHDR(envSample, _Fallback_Cubemap_HDR) * _Fallback_Cubemap_Brightness * diffuse_luminance;
+ canned_refl = DecodeHDR(envSample, _Fallback_Cubemap_HDR) * _Fallback_Cubemap_Brightness * diffuse_luminance;
}
#endif
- return UnityGI_prefilteredRadiance(data, roughness, reflect_dir);
+#if defined(_FALLBACK_CUBEMAP_LIMIT_METALLIC)
+ return lerp(env_refl, canned_refl, pbr.metallic);
+#elif defined(_FALLBACK_CUBEMAP)
+ return canned_refl;
+#else
+ return env_refl;
+#endif
}
float3 yumSH9(float4 n) {