summaryrefslogtreecommitdiffstats
path: root/UnityStandardCoreMinimal.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-08-06 16:42:42 -0700
committeryum <yum.food.vr@gmail.com>2025-08-06 16:42:42 -0700
commit99d161288bfe2d10c331c97e6b7571f9c884e912 (patch)
tree6ef130c4801de52f697c8d6996d9c4b0fb5f3964 /UnityStandardCoreMinimal.cginc
initial commit
Diffstat (limited to 'UnityStandardCoreMinimal.cginc')
-rw-r--r--UnityStandardCoreMinimal.cginc72
1 files changed, 72 insertions, 0 deletions
diff --git a/UnityStandardCoreMinimal.cginc b/UnityStandardCoreMinimal.cginc
new file mode 100644
index 0000000..8f2135d
--- /dev/null
+++ b/UnityStandardCoreMinimal.cginc
@@ -0,0 +1,72 @@
+#ifndef __UNITY_STANDARD_CORE_MINIMAL_INC
+#define __UNITY_STANDARD_CORE_MINIMAL_INC
+
+#include "filtering.cginc"
+#include "UnityShadowLibrary.cginc"
+
+// Now add the SampleShadowMaskBicubic function
+fixed4 SampleShadowMaskBicubic(float2 uv)
+{
+ #if defined(UNITY_SHADOWMASK) && defined(SHADER_API_D3D11)
+ float width, height;
+ unity_ShadowMask.GetDimensions(width, height);
+ float4 unity_ShadowMask_TexelSize = float4(width, height, 1.0/width, 1.0/height);
+
+ return SampleTexture2DBicubicFilter(unity_ShadowMask, sampler_unity_ShadowMask,
+ uv, unity_ShadowMask_TexelSize);
+ #else
+ // Fallback to regular sampling
+ return UNITY_SAMPLE_TEX2D(unity_ShadowMask, uv);
+ #endif
+}
+
+fixed UnitySampleBakedOcclusionBicubic(float2 lightmapUV, float3 worldPos)
+{
+ #if defined (SHADOWS_SHADOWMASK)
+ #if defined(LIGHTMAP_ON)
+ fixed4 rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy);
+ #else
+ fixed4 rawOcclusionMask = fixed4(1.0, 1.0, 1.0, 1.0);
+ #if UNITY_LIGHT_PROBE_PROXY_VOLUME
+ if (unity_ProbeVolumeParams.x == 1.0)
+ rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos);
+ else
+ rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy);
+ #else
+ rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy);
+ #endif
+ #endif
+ return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector));
+
+ #else
+
+ //In forward dynamic objects can only get baked occlusion from LPPV, light probe occlusion is done on the CPU by attenuating the light color.
+ fixed atten = 1.0f;
+ #if defined(UNITY_INSTANCING_ENABLED) && defined(UNITY_USE_SHCOEFFS_ARRAYS)
+ // ...unless we are doing instancing, and the attenuation is packed into SHC array's .w component.
+ atten = unity_SHC.w;
+ #endif
+
+ #if UNITY_LIGHT_PROBE_PROXY_VOLUME && !defined(LIGHTMAP_ON) && !UNITY_STANDARD_SIMPLE
+ fixed4 rawOcclusionMask = atten.xxxx;
+ if (unity_ProbeVolumeParams.x == 1.0)
+ rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos);
+ return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector));
+ #endif
+
+ return atten;
+ #endif
+}
+
+void GetBakedAttenuation(inout float atten, float2 lightmapUV, float3 worldPos)
+{
+ // Base pass with Lightmap support is responsible for handling ShadowMask / blending here for performance reason
+ #if defined(HANDLE_SHADOWS_BLENDING_IN_GI)
+ half bakedAtten = UnitySampleBakedOcclusionBicubic(lightmapUV.xy, worldPos);
+ float zDist = dot(_WorldSpaceCameraPos - worldPos, UNITY_MATRIX_V[2].xyz);
+ float fadeDist = UnityComputeShadowFadeDistance(worldPos, zDist);
+ atten = UnityMixRealtimeAndBakedShadows(atten, bakedAtten, UnityComputeShadowFade(fadeDist));
+ #endif
+}
+
+#endif // __UNITY_STANDARD_CORE_MINIMAL_INC