// Each #kernel tells which function to compile; you can have many kernels #pragma kernel DeferredDirectionalShadow #include "CoreRP/ShaderLibrary/Common.hlsl" #include "../ShaderVariables.hlsl" #include "Lighting.hlsl" RWTexture2D _DeferredShadowTextureUAV; float _DirectionalShadowIndex; #define DEFERRED_SHADOW_TILE_SIZE 16 [numthreads(DEFERRED_SHADOW_TILE_SIZE, DEFERRED_SHADOW_TILE_SIZE, 1)] void DeferredDirectionalShadow(uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID) { uint2 pixelCoord = groupId * DEFERRED_SHADOW_TILE_SIZE + groupThreadId; uint2 tileCoord = groupId; PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw, tileCoord); float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.positionSS).x; UpdatePositionInput(depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP, posInput); ShadowContext shadowContext = InitShadowContext(); float shadow = GetDirectionalShadowAttenuation(shadowContext, posInput.positionWS, float3(0.0, 0.0, 0.0), (uint)_DirectionalShadowIndex, float3(0.0, 0.0, 0.0)); _DeferredShadowTextureUAV[pixelCoord] = float4(shadow.xxx, 0.0); }