diff options
| author | yum <yum.food.vr@gmail.com> | 2025-03-07 13:48:04 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-03-07 13:48:04 -0800 |
| commit | 08762a99117fdddb3b48b450d02dd515b3eb78af (patch) | |
| tree | b3c9fc04e08bc7311f81775aedbeea060a6204ac /yum_lighting.cginc | |
| parent | 39f1d5d72d3395b4ee2ee6d0d2304a33674f2092 (diff) | |
Add fallback cubemap feature
Diffstat (limited to 'yum_lighting.cginc')
| -rw-r--r-- | yum_lighting.cginc | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/yum_lighting.cginc b/yum_lighting.cginc index 8570488..759eee6 100644 --- a/yum_lighting.cginc +++ b/yum_lighting.cginc @@ -100,7 +100,7 @@ float3 getDirectLightDirection(v2f i) { }
float GetLodRoughness(float roughness) {
- return (1.0 / UNITY_SPECCUBE_LOD_STEPS) * roughness * (1.7 - 0.7 * roughness);
+ return roughness * (1.7 - 0.7 * roughness);
}
float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir) {
@@ -122,8 +122,24 @@ float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir) { data.boxMin[1] = unity_SpecCube1_BoxMin;
data.probePosition[1] = unity_SpecCube1_ProbePosition;
#endif
- return UnityGI_prefilteredRadiance(data, pbr.roughness_perceptual,
- reflect_dir);
+
+#if defined(_FALLBACK_CUBEMAP)
+ // Check if there's no valid scene cubemap
+ if (!SceneHasReflections() || _Fallback_Cubemap_Force) {
+ // Set up data for fallback sampling similar to Unity's system
+ half3 reflectVector = reflect(-view_dir, pbr.normal);
+
+ #ifdef UNITY_SPECCUBE_BOX_PROJECTION
+ reflectVector = BoxProjectedCubemapDirection(reflectVector, data.worldPos, data.probePosition[0], data.boxMin[0], data.boxMax[0]);
+ #endif
+
+ 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;
+ }
+#endif
+
+ return UnityGI_prefilteredRadiance(data, roughness, reflect_dir);
}
float4 getIndirectDiffuse(v2f i, float4 vertexLightColor) {
|
