80 lines
3.1 KiB
Plaintext
80 lines
3.1 KiB
Plaintext
Shader "Hidden/Universal Render Pipeline/ScreenSpaceShadows"
|
|
{
|
|
SubShader
|
|
{
|
|
Tags{ "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"}
|
|
|
|
HLSLINCLUDE
|
|
|
|
//Keep compiler quiet about Shadows.hlsl.
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ImageBasedLighting.hlsl"
|
|
// Core.hlsl for XR dependencies
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
|
|
|
half4 Fragment(Varyings input) : SV_Target
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
|
|
|
#if defined(_SCREEN_SPACE_SHADOW_LOW_RESOLUTION)
|
|
float4 depths = GATHER_RED_TEXTURE2D(_CameraDepthTexture, sampler_PointClamp, input.texcoord.xy);
|
|
#if !defined(UNITY_REVERSED_Z)
|
|
depths = depths * 2.0 - 1.0;
|
|
#endif
|
|
|
|
half shadow = 0;
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
float depth = depths[i];
|
|
float3 wpos = ComputeWorldSpacePosition(input.texcoord.xy, depth, unity_MatrixInvVP);
|
|
float4 coords = TransformWorldToShadowCoord(wpos);
|
|
shadow += SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare, coords.xyz );
|
|
}
|
|
|
|
return shadow * 0.25;
|
|
#else
|
|
|
|
#if UNITY_REVERSED_Z
|
|
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, input.texcoord.xy).r;
|
|
#else
|
|
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, input.texcoord.xy).r;
|
|
deviceDepth = deviceDepth * 2.0 - 1.0;
|
|
#endif
|
|
|
|
//Fetch shadow coordinates for cascade.
|
|
float3 wpos = ComputeWorldSpacePosition(input.texcoord.xy, deviceDepth, unity_MatrixInvVP);
|
|
float4 coords = TransformWorldToShadowCoord(wpos);
|
|
|
|
// Screenspace shadowmap is only used for directional lights which use orthogonal projection.
|
|
half realtimeShadow = MainLightRealtimeShadow(coords);
|
|
|
|
return realtimeShadow;
|
|
#endif
|
|
}
|
|
|
|
ENDHLSL
|
|
|
|
Pass
|
|
{
|
|
Name "ScreenSpaceShadows"
|
|
ZTest Always
|
|
ZWrite Off
|
|
Cull Off
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
|
|
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
|
|
#pragma multi_compile_fragment _ _SCREEN_SPACE_SHADOW_LOW_RESOLUTION
|
|
|
|
#pragma target 5.0
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Fragment
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|