您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
28 行
1.2 KiB
28 行
1.2 KiB
// Each #kernel tells which function to compile; you can have many kernels
|
|
#pragma kernel DeferredDirectionalShadow
|
|
|
|
#include "ShaderLibrary/Common.hlsl"
|
|
#include "../../ShaderVariables.hlsl"
|
|
#include "../../Lighting/Lighting.hlsl"
|
|
|
|
RWTexture2D<float4> _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.unPositionSS).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);
|
|
}
|