浏览代码
Modified the ShadowContext declaration macro. Only code for slots that are not zero will be generated.
Modified the ShadowContext declaration macro. Only code for slots that are not zero will be generated.
Changed the shadow context declaration so no code for cubemaps will be generated, anymore. Modified the texfetch functions. Instead of returning from the loop the routines only break. This fixes a warning about an uninitialized variable and also leads to fewer instructions generated. Restructured ShadowDispatch.hlsl a little bit to make changing resources and algorithms a bit easier./main
uygar
8 年前
当前提交
1fca69f6
共有 4 个文件被更改,包括 183 次插入 和 105 次删除
-
23Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/Shadow.hlsl
-
4Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowContext.hlsl
-
88Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowDispatch.hlsl
-
173Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowTexFetch.hlsl
|
|||
|
|||
// This file contains various helper declarations for declaring and sampling members of the ShadowContext struct. |
|||
# define SHADOW_DEFINE_SAMPLING_FUNCS( _Tex2DArraySlots, _TexCubeArraySlots ) \ |
|||
float4 SampleCompShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float slice ) { return SAMPLE_TEXTURE2D_ARRAY_SHADOW( ctxt.tex2DArray[texIdx], ctxt.compSamplers[sampIdx], tcs, slice ); } \ |
|||
float4 SampleShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float2 tcs, float slice, float lod = 0.0 ) { return SAMPLE_TEXTURE2D_ARRAY_LOD( ctxt.tex2DArray[texIdx], ctxt.samplers[sampIdx], tcs, slice, lod ); } \ |
|||
float4 SampleCompShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float4 tcs, float cubeIdx ) { return SAMPLE_TEXTURECUBE_ARRAY_SHADOW( ctxt.texCubeArray[texIdx], ctxt.compSamplers[sampIdx], tcs, cubeIdx );} \ |
|||
float4 SampleShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float cubeIdx, float lod = 0.0 ) { return SAMPLE_TEXTURECUBE_ARRAY_LOD( ctxt.texCubeArray[texIdx], ctxt.samplers[sampIdx], tcs, cubeIdx, lod ); } |
|||
|
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_T2DA_COMP( _Tex2DArraySlots , _SamplerCompSlots ) float4 SampleCompShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float slice ) { return SAMPLE_TEXTURE2D_ARRAY_SHADOW( ctxt.tex2DArray[texIdx], ctxt.compSamplers[sampIdx], tcs, slice ); } |
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_T2DA_SAMP( _Tex2DArraySlots , _SamplerSlots ) float4 SampleShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float2 tcs, float slice, float lod = 0.0 ) { return SAMPLE_TEXTURE2D_ARRAY_LOD( ctxt.tex2DArray[texIdx], ctxt.samplers[sampIdx], tcs, slice, lod ); } |
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_TCA_COMP( _TexCubeArraySlots, _SamplerCompSlots ) float4 SampleCompShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float4 tcs, float cubeIdx ) { return SAMPLE_TEXTURECUBE_ARRAY_SHADOW( ctxt.texCubeArray[texIdx], ctxt.compSamplers[sampIdx], tcs, cubeIdx );} |
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_TCA_SAMP( _TexCubeArraySlots, _SamplerSlots ) float4 SampleShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float cubeIdx, float lod = 0.0 ) { return SAMPLE_TEXTURECUBE_ARRAY_LOD( ctxt.texCubeArray[texIdx], ctxt.samplers[sampIdx], tcs, cubeIdx, lod ); } |
|||
|
|||
# define SHADOW_DEFINE_SAMPLING_FUNCS( _Tex2DArraySlots, _TexCubeArraySlots, _SamplerCompSlots, _SamplerSlots ) \ |
|||
\ |
|||
float4 SampleCompShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float slice ) \ |
|||
{ \ |
|||
[unroll] for( uint i = 0; i < _Tex2DArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerCompSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
return SAMPLE_TEXTURE2D_ARRAY_SHADOW( ctxt.tex2DArray[i], ctxt.compSamplers[j], tcs, slice ); \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return 1.0; \ |
|||
} \ |
|||
\ |
|||
float4 SampleShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float2 tcs, float slice, float lod = 0.0 ) \ |
|||
{ \ |
|||
[unroll] for( uint i = 0; i < _Tex2DArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
return SAMPLE_TEXTURE2D_ARRAY_LOD( ctxt.tex2DArray[i], ctxt.samplers[j], tcs, slice, lod ); \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return 1.0; \ |
|||
} \ |
|||
\ |
|||
float4 SampleCompShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float4 tcs, float cubeIdx ) \ |
|||
{ \ |
|||
[unroll] for( uint i = 0; i < _TexCubeArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerCompSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
return SAMPLE_TEXTURECUBE_ARRAY_SHADOW( ctxt.texCubeArray[i], ctxt.compSamplers[j], tcs, cubeIdx ); \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return 1.0; \ |
|||
} \ |
|||
\ |
|||
float4 SampleShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float cubeIdx, float lod = 0.0 ) \ |
|||
{ \ |
|||
[unroll] for( uint i = 0; i < _TexCubeArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
return SAMPLE_TEXTURECUBE_ARRAY_LOD( ctxt.texCubeArray[i], ctxt.samplers[j], tcs, cubeIdx, lod ); \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return 1.0; \ |
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_T2DA_COMP( _Tex2DArraySlots, _SamplerCompSlots ) \ |
|||
float4 SampleCompShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float slice ) \ |
|||
{ \ |
|||
float4 res = 1.0.xxxx; \ |
|||
[unroll] for( uint i = 0; i < _Tex2DArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerCompSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
res = SAMPLE_TEXTURE2D_ARRAY_SHADOW( ctxt.tex2DArray[i], ctxt.compSamplers[j], tcs, slice ); \ |
|||
break; \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return res; \ |
|||
} |
|||
|
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_T2DA_SAMP( _Tex2DArraySlots, _SamplerSlots ) \ |
|||
float4 SampleShadow_T2DA( ShadowContext ctxt, uint texIdx, uint sampIdx, float2 tcs, float slice, float lod = 0.0 ) \ |
|||
{ \ |
|||
float4 res = 1.0.xxxx; \ |
|||
[unroll] for( uint i = 0; i < _Tex2DArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
res = SAMPLE_TEXTURE2D_ARRAY_LOD( ctxt.tex2DArray[i], ctxt.samplers[j], tcs, slice, lod ); \ |
|||
break; \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return res; \ |
|||
} |
|||
|
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_TCA_COMP( _TexCubeArraySlots, _SamplerCompSlots ) \ |
|||
float4 SampleCompShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float4 tcs, float cubeIdx ) \ |
|||
{ \ |
|||
float4 res = 1.0.xxxx; \ |
|||
[unroll] for( uint i = 0; i < _TexCubeArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerCompSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
res = SAMPLE_TEXTURECUBE_ARRAY_SHADOW( ctxt.texCubeArray[i], ctxt.compSamplers[j], tcs, cubeIdx ); \ |
|||
break; \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return res; \ |
|||
} |
|||
|
|||
# define SHADOW_DEFINE_SAMPLING_FUNC_TCA_SAMP( _TexCubeArraySlots, _SamplerSlots ) \ |
|||
float4 SampleShadow_TCA( ShadowContext ctxt, uint texIdx, uint sampIdx, float3 tcs, float cubeIdx, float lod = 0.0 ) \ |
|||
{ \ |
|||
float4 res = 1.0.xxxx; \ |
|||
[unroll] for( uint i = 0; i < _TexCubeArraySlots; i++ ) \ |
|||
{ \ |
|||
[unroll] for( uint j = 0; j < _SamplerSlots; j++ ) \ |
|||
{ \ |
|||
[branch] if( i == texIdx && j == sampIdx ) \ |
|||
{ \ |
|||
res = SAMPLE_TEXTURECUBE_ARRAY_LOD( ctxt.texCubeArray[i], ctxt.samplers[j], tcs, cubeIdx, lod ); \ |
|||
break; \ |
|||
} \ |
|||
} \ |
|||
} \ |
|||
return res; \ |
|||
|
|||
#endif |
|||
#endif // SHADOW_SUPPORTS_DYNAMIC_INDEXING != 0 |
|||
|
|||
|
|||
// helper macro to suppress code generation if _cnt is 0 |
|||
#define SHADOW_CHECK_0( _macro ) |
|||
#define SHADOW_CHECK_1( _macro ) _macro |
|||
#define SHADOW_CHECK_2( _macro ) _macro |
|||
#define SHADOW_CHECK_3( _macro ) _macro |
|||
#define SHADOW_CHECK_4( _macro ) _macro |
|||
#define SHADOW_CHECK_5( _macro ) _macro |
|||
#define SHADOW_CHECK_6( _macro ) _macro |
|||
#define SHADOW_CHECK_7( _macro ) _macro |
|||
#define SHADOW_CHECK_8( _macro ) _macro |
|||
#define SHADOW_CHECK_9( _macro ) _macro |
|||
#define SHADOW_CHECK( _cnt, _macro ) MERGE_NAME( SHADOW_CHECK_ , _cnt ) ( _macro ) |
|||
|
|||
// helper macro to declare texture members for the shadow context. |
|||
#define SHADOWCONTEXT_DECLARE_TEXTURES( _Tex2DArraySlots, _TexCubeArraySlots, _SamplerCompSlots, _SamplerSlots ) \ |
|||
SHADOW_CHECK( _Tex2DArraySlots , Texture2DArray tex2DArray[_Tex2DArraySlots]; ) \ |
|||
SHADOW_CHECK( _TexCubeArraySlots, TextureCubeArray texCubeArray[_Tex2DArraySlots]; ) \ |
|||
SHADOW_CHECK( _SamplerCompSlots , SamplerComparisonState compSamplers[_Tex2DArraySlots]; ) \ |
|||
SHADOW_CHECK( _SamplerSlots , SamplerState samplers[_Tex2DArraySlots]; ) |
|||
// helper macro to declare texture sampling functions for the shadow context. |
|||
#define SHADOW_DEFINE_SAMPLING_FUNCS( _Tex2DArraySlots, _TexCubeArraySlots, _SamplerCompSlots, _SamplerSlots ) \ |
|||
SHADOW_CHECK( _Tex2DArraySlots , SHADOW_CHECK( _SamplerCompSlots, SHADOW_DEFINE_SAMPLING_FUNC_T2DA_COMP( _Tex2DArraySlots, _SamplerCompSlots ) ) ) \ |
|||
SHADOW_CHECK( _Tex2DArraySlots , SHADOW_CHECK( _SamplerSlots , SHADOW_DEFINE_SAMPLING_FUNC_T2DA_SAMP( _Tex2DArraySlots, _SamplerSlots ) ) ) \ |
|||
SHADOW_CHECK( _TexCubeArraySlots, SHADOW_CHECK( _SamplerCompSlots, SHADOW_DEFINE_SAMPLING_FUNC_TCA_COMP(_TexCubeArraySlots, _SamplerCompSlots ) ) ) \ |
|||
SHADOW_CHECK( _TexCubeArraySlots, SHADOW_CHECK( _SamplerSlots , SHADOW_DEFINE_SAMPLING_FUNC_TCA_SAMP(_TexCubeArraySlots, _SamplerSlots ) ) ) |
撰写
预览
正在加载...
取消
保存
Reference in new issue