|
|
|
|
|
|
// |
|
|
|
// Point shadows |
|
|
|
// |
|
|
|
float EvalShadow_PointDepth( ShadowContext shadowContext, float3 positionWS, float3 normalWS, int index, float3 L ) |
|
|
|
float EvalShadow_PointDepth( ShadowContext shadowContext, float3 positionWS, float3 normalWS, int index, float4 L ) |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index]; |
|
|
|
float3 biased_posWS = positionWS + EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
float3 lpos = positionWS + L.xyz * L.w; |
|
|
|
positionWS = biased_posWS; |
|
|
|
int faceIndex = EvalShadow_GetCubeFaceID( lpos - biased_posWS ) + 1; |
|
|
|
int faceIndex = EvalShadow_GetCubeFaceID( L ) + 1; |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index + faceIndex]; |
|
|
|
sd = shadowContext.shadowDatas[index + faceIndex]; |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
// get shadowmap texcoords |
|
|
|
float3 posTC = EvalShadow_GetTexcoords( sd, positionWS ); |
|
|
|
// get the algorithm |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#define EvalShadow_PointDepth_( _samplerType ) \ |
|
|
|
float EvalShadow_PointDepth( ShadowContext shadowContext, uint shadowAlgorithm, Texture2DArray tex, _samplerType samp, float3 positionWS, float3 normalWS, int index, float3 L ) \ |
|
|
|
float EvalShadow_PointDepth( ShadowContext shadowContext, uint shadowAlgorithm, Texture2DArray tex, _samplerType samp, float3 positionWS, float3 normalWS, int index, float4 L ) \ |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index]; \ |
|
|
|
float3 biased_posWS = positionWS + EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
float3 lpos = positionWS + L.xyz * L.w; \ |
|
|
|
positionWS = biased_posWS; \ |
|
|
|
int faceIndex = EvalShadow_GetCubeFaceID( lpos - biased_posWS ) + 1; \ |
|
|
|
int faceIndex = EvalShadow_GetCubeFaceID( L ) + 1; \ |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index + faceIndex]; \ |
|
|
|
sd = shadowContext.shadowDatas[index + faceIndex]; \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
/* get shadowmap texcoords */ \ |
|
|
|
float3 posTC = EvalShadow_GetTexcoords( sd, positionWS ); \ |
|
|
|
/* sample the texture */ \ |
|
|
|
|
|
|
ShadowData sd = shadowContext.shadowDatas[index]; \ |
|
|
|
uint payloadOffset = GetPayloadOffset( sd ); \ |
|
|
|
/* normal based bias */ \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
/* get shadowmap texcoords */ \ |
|
|
|
float3 posTC = EvalShadow_GetTexcoords( sd, positionWS ); \ |
|
|
|
/* sample the texture */ \ |
|
|
|
|
|
|
// |
|
|
|
// Punctual shadows for Point and Spot |
|
|
|
// |
|
|
|
float EvalShadow_PunctualDepth( ShadowContext shadowContext, float3 positionWS, float3 normalWS, int index, float3 L ) |
|
|
|
float EvalShadow_PunctualDepth( ShadowContext shadowContext, float3 positionWS, float3 normalWS, int index, float4 L ) |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index]; |
|
|
|
UnpackShadowType( shadowContext.shadowDatas[index].shadowType, shadowType ); |
|
|
|
UnpackShadowType( sd.shadowType, shadowType ); |
|
|
|
faceIndex = EvalShadow_GetCubeFaceID( L ) + 1; |
|
|
|
float3 biased_posWS = positionWS + EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
float3 lpos = positionWS + L.xyz * L.w; |
|
|
|
positionWS = biased_posWS; |
|
|
|
faceIndex = EvalShadow_GetCubeFaceID( lpos - biased_posWS ) + 1; |
|
|
|
else |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index + faceIndex]; |
|
|
|
sd = shadowContext.shadowDatas[index + faceIndex]; |
|
|
|
// normal based bias |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
// get shadowmap texcoords |
|
|
|
float3 posTC = EvalShadow_GetTexcoords( sd, positionWS ); |
|
|
|
// sample the texture according to the given algorithm |
|
|
|
|
|
|
UnpackShadowType( sd.shadowType, shadowType, shadowAlgorithm ); |
|
|
|
return SampleShadow_SelectAlgorithm( shadowContext, sd, payloadOffset, posTC, sd.bias, slice, shadowAlgorithm, texIdx, sampIdx ); |
|
|
|
} |
|
|
|
return SampleShadow_SelectAlgorithm(shadowContext, sd, payloadOffset, posTC, sd.bias, slice, shadowAlgorithm, texIdx, sampIdx); |
|
|
|
} |
|
|
|
float EvalShadow_PunctualDepth( ShadowContext shadowContext, uint shadowAlgorithm, Texture2DArray tex, _samplerType samp, float3 positionWS, float3 normalWS, int index, float3 L ) \ |
|
|
|
float EvalShadow_PunctualDepth( ShadowContext shadowContext, uint shadowAlgorithm, Texture2DArray tex, _samplerType samp, float3 positionWS, float3 normalWS, int index, float4 L ) \ |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index]; \ |
|
|
|
UnpackShadowType( shadowContext.shadowDatas[index].shadowType, shadowType ); \ |
|
|
|
UnpackShadowType( sd.shadowType, shadowType ); \ |
|
|
|
faceIndex = EvalShadow_GetCubeFaceID( L ) + 1; \ |
|
|
|
float3 biased_posWS = positionWS + EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
float3 lpos = positionWS + L.xyz * L.w; \ |
|
|
|
positionWS = biased_posWS; \ |
|
|
|
faceIndex = EvalShadow_GetCubeFaceID( lpos - biased_posWS ) + 1; \ |
|
|
|
else \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L.xyz ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index + faceIndex]; \ |
|
|
|
sd = shadowContext.shadowDatas[index + faceIndex]; \ |
|
|
|
/* normal based bias */ \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
/* get shadowmap texcoords */ \ |
|
|
|
float3 posTC = EvalShadow_GetTexcoords( sd, positionWS ); \ |
|
|
|
/* sample the texture */ \ |
|
|
|
|
|
|
|
|
|
|
float EvalShadow_CascadedDepth( ShadowContext shadowContext, float3 positionWS, float3 normalWS, int index, float3 L ) |
|
|
|
{ |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index]; |
|
|
|
// normal based bias |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
|
|
|
|
// load the right shadow data for the current face |
|
|
|
float4 dirShadowSplitSpheres[4]; |
|
|
|
uint payloadOffset = EvalShadow_LoadSplitSpheres( shadowContext, index, dirShadowSplitSpheres ); |
|
|
|
|
|
|
|
|
|
|
ShadowData sd = shadowContext.shadowDatas[index + 1 + shadowSplitIndex]; |
|
|
|
// normal based bias |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); |
|
|
|
sd = shadowContext.shadowDatas[index + 1 + shadowSplitIndex]; |
|
|
|
// get shadowmap texcoords |
|
|
|
float3 posTC = EvalShadow_GetTexcoords( sd, positionWS ); |
|
|
|
|
|
|
|
|
|
|
#define EvalShadow_CascadedDepth_( _samplerType ) \ |
|
|
|
float EvalShadow_CascadedDepth( ShadowContext shadowContext, uint shadowAlgorithm, Texture2DArray tex, _samplerType samp, float3 positionWS, float3 normalWS, int index, float3 L ) \ |
|
|
|
{ \ |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index]; \ |
|
|
|
/* normal based bias */ \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
\ |
|
|
|
/* load the right shadow data for the current face */ \ |
|
|
|
float4 dirShadowSplitSpheres[4]; \ |
|
|
|
uint payloadOffset = EvalShadow_LoadSplitSpheres( shadowContext, index, dirShadowSplitSpheres ); \ |
|
|
|
|
|
|
\ |
|
|
|
ShadowData sd = shadowContext.shadowDatas[index + 1 + shadowSplitIndex]; \ |
|
|
|
/* normal based bias */ \ |
|
|
|
positionWS += EvalShadow_NormalBias( normalWS, saturate( dot( normalWS, L ) ), sd.texelSizeRcp.zw, sd.normalBias ); \ |
|
|
|
sd = shadowContext.shadowDatas[index + 1 + shadowSplitIndex]; \ |
|
|
|
/* get shadowmap texcoords */ \ |
|
|
|
float3 posTC = EvalShadow_GetTexcoords( sd, positionWS ); \ |
|
|
|
/* sample the texture */ \ |
|
|
|