yum-archive/2ner
A toon shader for Unity's BIRP.
git clone https://git.yummers.dev/yum-archive/2ner
478cb4e
master
1#ifndef __UNITY_STANDARD_CORE_MINIMAL_INC 2#define __UNITY_STANDARD_CORE_MINIMAL_INC 3 4#include "SharedFilteringLib.hlsl" 5#include "UnityShadowLibrary.cginc" 6 7// Now add the SampleShadowMaskBicubic function 8fixed4 SampleShadowMaskBicubic(float2 uv) 9{ 10 #if defined(UNITY_SHADOWMASK) && defined(SHADER_API_D3D11) 11 float width, height; 12 unity_ShadowMask.GetDimensions(width, height); 13 float4 unity_ShadowMask_TexelSize = float4(width, height, 1.0/width, 1.0/height); 14 15 return SampleTexture2DBicubicFilter(unity_ShadowMask, sampler_unity_ShadowMask, 16 uv, unity_ShadowMask_TexelSize); 17 #else 18 // Fallback to regular sampling 19 return UNITY_SAMPLE_TEX2D(unity_ShadowMask, uv); 20 #endif 21} 22 23fixed UnitySampleBakedOcclusionBicubic(float2 lightmapUV, float3 worldPos) 24{ 25 #if defined (SHADOWS_SHADOWMASK) 26 #if defined(LIGHTMAP_ON) 27 fixed4 rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); 28 #else 29 fixed4 rawOcclusionMask = fixed4(1.0, 1.0, 1.0, 1.0); 30 #if UNITY_LIGHT_PROBE_PROXY_VOLUME 31 if (unity_ProbeVolumeParams.x == 1.0) 32 rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos); 33 else 34 rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); 35 #else 36 rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); 37 #endif 38 #endif 39 return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector)); 40 41 #else 42 43 //In forward dynamic objects can only get baked occlusion from LPPV, light probe occlusion is done on the CPU by attenuating the light color. 44 fixed atten = 1.0f; 45 #if defined(UNITY_INSTANCING_ENABLED) && defined(UNITY_USE_SHCOEFFS_ARRAYS) 46 // ...unless we are doing instancing, and the attenuation is packed into SHC array's .w component. 47 atten = unity_SHC.w; 48 #endif 49 50 #if UNITY_LIGHT_PROBE_PROXY_VOLUME && !defined(LIGHTMAP_ON) && !UNITY_STANDARD_SIMPLE 51 fixed4 rawOcclusionMask = atten.xxxx; 52 if (unity_ProbeVolumeParams.x == 1.0) 53 rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos); 54 return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector)); 55 #endif 56 57 return atten; 58 #endif 59} 60 61void GetBakedAttenuation(inout float atten, float2 lightmapUV, float3 worldPos) 62{ 63 // Base pass with Lightmap support is responsible for handling ShadowMask / blending here for performance reason 64 #if defined(HANDLE_SHADOWS_BLENDING_IN_GI) 65 half bakedAtten = UnitySampleBakedOcclusionBicubic(lightmapUV.xy, worldPos); 66 float zDist = dot(_WorldSpaceCameraPos - worldPos, UNITY_MATRIX_V[2].xyz); 67 float fadeDist = UnityComputeShadowFadeDistance(worldPos, zDist); 68 atten = UnityMixRealtimeAndBakedShadows(atten, bakedAtten, UnityComputeShadowFade(fadeDist)); 69 #endif 70} 71 72#endif // __UNITY_STANDARD_CORE_MINIMAL_INC