// binding code. This needs to be in sync with ShadowContext.hlsl
ShadowContext . BindDel binder = ( ShadowContext sc , CommandBuffer cb , ComputeShader computeShader , int computeKernel ) = >
{
{
if ( computeShader )
{
// bind buffers
cb . SetComputeBufferParam ( computeShader , computeKernel , "_ShadowDatasExp" , s_ShadowDataBuffer ) ;
cb . SetComputeBufferParam ( computeShader , computeKernel , "_ShadowPayloads" , s_ShadowPayloadBuffer ) ;
// bind textures
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_VSM_0" , tex [ 0 ] ) ;
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_VSM_1" , tex [ 1 ] ) ;
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_VSM_2" , tex [ 2 ] ) ;
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_PCF" , tex [ 3 ] ) ;
if ( computeShader )
{
// bind buffers
cb . SetComputeBufferParam ( computeShader , computeKernel , "_ShadowDatasExp" , s_ShadowDataBuffer ) ;
cb . SetComputeBufferParam ( computeShader , computeKernel , "_ShadowPayloads" , s_ShadowPayloadBuffer ) ;
// bind textures
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_VSM_0" , tex [ 0 ] ) ;
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_VSM_1" , tex [ 1 ] ) ;
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_VSM_2" , tex [ 2 ] ) ;
cb . SetComputeTextureParam ( computeShader , computeKernel , "_ShadowmapExp_PCF" , tex [ 3 ] ) ;
else
{
// bind buffers
cb . SetGlobalBuffer ( "_ShadowDatasExp" , s_ShadowDataBuffer ) ;
cb . SetGlobalBuffer ( "_ShadowPayloads" , s_ShadowPayloadBuffer ) ;
// bind textures
cb . SetGlobalTexture ( "_ShadowmapExp_VSM_0" , tex [ 0 ] ) ;
cb . SetGlobalTexture ( "_ShadowmapExp_VSM_1" , tex [ 1 ] ) ;
cb . SetGlobalTexture ( "_ShadowmapExp_VSM_2" , tex [ 2 ] ) ;
cb . SetGlobalTexture ( "_ShadowmapExp_PCF" , tex [ 3 ] ) ;
else
{
// bind buffers
cb . SetGlobalBuffer ( "_ShadowDatasExp" , s_ShadowDataBuffer ) ;
cb . SetGlobalBuffer ( "_ShadowPayloads" , s_ShadowPayloadBuffer ) ;
// bind textures
cb . SetGlobalTexture ( "_ShadowmapExp_VSM_0" , tex [ 0 ] ) ;
cb . SetGlobalTexture ( "_ShadowmapExp_VSM_1" , tex [ 1 ] ) ;
cb . SetGlobalTexture ( "_ShadowmapExp_VSM_2" , tex [ 2 ] ) ;
cb . SetGlobalTexture ( "_ShadowmapExp_PCF" , tex [ 3 ] ) ;
// TODO: Currently samplers are hard coded in ShadowContext.hlsl, so we can't really set them here
} ;
if ( light . light . cookie ! = null )
{
directionalLightData . tileCookie = light . light . cookie . wrapMode = = TextureWrapMode . Repeat ;
directionalLightData . cookieIndex = m_CookieTexArray . FetchSlice ( light . light . cookie ) ;
}
// fix up shadow information
if ( m_TileSettings . enableComputeLightEvaluation & & outputSplitLighting )
{
// The CS is always in the MRT mode. Do not execute the same shader twice.
return ;
// The CS is always in the MRT mode. Do not execute the same shader twice.
return ;
}
// TODO: To reduce GC pressure don't do concat string here
cmd . SetComputeTextureParam ( shadeOpaqueShader , kernel , "_SkyTexture" , skyTexture ? skyTexture : m_DefaultTexture2DArray ) ;
// Set SSS parameters.
cmd . SetComputeIntParam ( shadeOpaqueShader , "_EnableSSSAndTransmission" , Shader . GetGlobalInt ( "_EnableSSSAndTransmission" ) ) ;
cmd . SetComputeIntParam ( shadeOpaqueShader , "_TexturingModeFlags" , Shader . GetGlobalInt ( "_TexturingModeFlags" ) ) ;
cmd . SetComputeIntParam ( shadeOpaqueShader , "_TransmissionFlags" , Shader . GetGlobalInt ( "_TransmissionFlags" ) ) ;
cmd . SetComputeFloatParams ( shadeOpaqueShader , "_ThicknessRemaps" , Shader . GetGlobalFloatArray ( "_ThicknessRemaps" ) ) ;
// We are currently supporting two different SSS mode: Jimenez (with 2-Gaussian profile) and Disney
// We have added the ability to switch between each other for subsurface scattering, but for transmittance this is more tricky as we need to add
// shader variant for forward, gbuffer and deferred shader. We want to avoid this.
// So for transmittance we use Disney profile formulation (that we know is more correct) in both case, and in the case of Jimenez we hack the parameters with 2-Gaussian parameters (Ideally we should fit but haven't find good fit) so it approximately match.
// Note: Jimenez SSS is in cm unit whereas Disney is in mm unit making an inconsistency here to compare model side by side
cmd . SetComputeVectorArrayParam ( shadeOpaqueShader , "_ShapeParams" , Shader . GetGlobalVectorArray ( "_ShapeParams" ) ) ;
cmd . SetComputeIntParam ( shadeOpaqueShader , "_EnableSSSAndTransmission" , Shader . GetGlobalInt ( "_EnableSSSAndTransmission" ) ) ;
cmd . SetComputeIntParam ( shadeOpaqueShader , "_TexturingModeFlags" , Shader . GetGlobalInt ( "_TexturingModeFlags" ) ) ;
cmd . SetComputeIntParam ( shadeOpaqueShader , "_TransmissionFlags" , Shader . GetGlobalInt ( "_TransmissionFlags" ) ) ;
cmd . SetComputeFloatParams ( shadeOpaqueShader , "_ThicknessRemaps" , Shader . GetGlobalFloatArray ( "_ThicknessRemaps" ) ) ;
// We are currently supporting two different SSS mode: Jimenez (with 2-Gaussian profile) and Disney
// We have added the ability to switch between each other for subsurface scattering, but for transmittance this is more tricky as we need to add
// shader variant for forward, gbuffer and deferred shader. We want to avoid this.
// So for transmittance we use Disney profile formulation (that we know is more correct) in both case, and in the case of Jimenez we hack the parameters with 2-Gaussian parameters (Ideally we should fit but haven't find good fit) so it approximately match.
// Note: Jimenez SSS is in cm unit whereas Disney is in mm unit making an inconsistency here to compare model side by side
cmd . SetComputeVectorArrayParam ( shadeOpaqueShader , "_ShapeParams" , Shader . GetGlobalVectorArray ( "_ShapeParams" ) ) ;
cmd . SetComputeVectorArrayParam ( shadeOpaqueShader , "_TransmissionTints" , Shader . GetGlobalVectorArray ( "_TransmissionTints" ) ) ;
cmd . SetComputeTextureParam ( shadeOpaqueShader , kernel , "specularLightingUAV" , colorBuffers [ 0 ] ) ;