1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
|