浏览代码

Added new parameters to control the edge leak fixup.

Agreessiveness of the fixup can be controled, and the reference vector can either be set to the normal if available or the view vector.
/main
uygar 7 年前
当前提交
74b782e2
共有 5 个文件被更改,包括 24 次插入8 次删除
  1. 17
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/ShadowAlgorithms.hlsl
  2. 3
      ScriptableRenderPipeline/Core/CoreRP/Shadow/AdditionalShadowData.cs
  3. 6
      ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs
  4. 1
      ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBase.cs
  5. 5
      ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBase.cs.hlsl

17
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/ShadowAlgorithms.hlsl


return (asint( flag ) & 2) ? 1.0 : 0.0;
}
real3 EvalShadow_ReceiverBiasWeightPos( real3 positionWS, real3 normalWS, real3 L, real worldTexelSize )
bool EvalShadow_ReceiverBiasWeightUseNormalFlag( float flag )
{
return (asint( flag ) & 4) ? true : false;
}
real3 EvalShadow_ReceiverBiasWeightPos( real3 positionWS, real3 normalWS, real3 L, real worldTexelSize, real tolerance, bool useNormal )
return positionWS + L * worldTexelSize;
return positionWS + L * worldTexelSize * tolerance;
return positionWS + normalWS * worldTexelSize;
return positionWS + (useNormal ? normalWS : L) * worldTexelSize * tolerance;
#endif
}

[branch]
if( shadowAlgorithm <= GPUSHADOWALGORITHM_PCF_TENT_7X7 )
{
real3 pos = EvalShadow_ReceiverBiasWeightPos( positionWS, normalWS, L, EvalShadow_WorldTexelSize( sd, L_dist, perspProj ) );
real3 pos = EvalShadow_ReceiverBiasWeightPos( positionWS, normalWS, L, EvalShadow_WorldTexelSize( sd, L_dist, perspProj ), sd.edgeTolerance, EvalShadow_ReceiverBiasWeightUseNormalFlag( sd.nrmlBias.w ) );
real3 tcs = EvalShadow_GetTexcoords( sd, pos, perspProj );
weight = SampleCompShadow_T2DA( shadowContext, texIdx, sampIdx, tcs, slice ).x;
}

real EvalShadow_ReceiverBiasWeight( ShadowData sd, Texture2DArray tex, SamplerComparisonState samp, real3 positionWS, real3 normalWS, real3 L, real L_dist, real slice, bool perspProj )
{
real3 pos = EvalShadow_ReceiverBiasWeightPos( positionWS, normalWS, L, EvalShadow_WorldTexelSize( sd, L_dist, perspProj ) );
real3 pos = EvalShadow_ReceiverBiasWeightPos( positionWS, normalWS, L, EvalShadow_WorldTexelSize( sd, L_dist, perspProj ), sd.edgeTolerance, EvalShadow_ReceiverBiasWeightUseNormalFlag( sd.nrmlBias.w ) );
return lerp( 1.0, SAMPLE_TEXTURE2D_ARRAY_SHADOW( tex, samp, EvalShadow_GetTexcoords( sd, pos, perspProj ), slice ).x, EvalShadow_ReceiverBiasWeightFlag( sd.nrmlBias.w ) );
}

#else // SHADOW_USE_VIEW_BIAS_SCALING != 0
real EvalShadow_ReceiverBiasWeight( ShadowContext shadowContext, uint shadowAlgorithm, ShadowData sd, uint texIdx, uint sampIdx, real3 positionWS, real3 normalWS, real3 L, real L_dist, real slice, bool perspProj ) { return 1.0; }
real EvalShadow_ReceiverBiasWeight( ShadowData sd, Texture2DArray tex, SamplerComparisonState samp, real3 positionWS, real3 normalWS, real3 L, real L_dist, real slice, bool perspProj ) { return 1.0; }
real EvalShadow_ReceiverBiasWeight(ShadowData sd, Texture2DArray tex, SamplerState samp, real3 positionWS, real3 normalWS, real3 L, real L_dist, real slice, bool perspProj) { return 1.0; }
real EvalShadow_ReceiverBiasWeight (ShadowData sd, Texture2DArray tex, SamplerState samp, real3 positionWS, real3 normalWS, real3 L, real L_dist, real slice, bool perspProj ) { return 1.0; }
#endif // SHADOW_USE_VIEW_BIAS_SCALING != 0
// receiver bias either using the normal to weight normal and view biases, or just light view biasing

3
ScriptableRenderPipeline/Core/CoreRP/Shadow/AdditionalShadowData.cs


public float nrmlBiasScale = 1.0f;
public bool sampleBiasScale = true;
public bool edgeLeakFixup = true;
public bool edgeToleranceNrml = true;
[Range(0.0F, 1.0F)]
public float edgeTolerance = 1.0f;
// shadow related parameters

6
ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs


// extract texel size in world space
int flags = 0;
flags |= asd.sampleBiasScale ? (1 << 0) : 0;
flags |= asd.edgeLeakFixup ? (1 << 1) : 0;
flags |= asd.sampleBiasScale ? (1 << 0) : 0;
flags |= asd.edgeLeakFixup ? (1 << 1) : 0;
flags |= asd.edgeToleranceNrml ? (1 << 2) : 0;
sd.edgeTolerance = asd.edgeTolerance;
sd.viewBias = new Vector4( asd.viewBiasMin, asd.viewBiasMax, asd.viewBiasScale, 2.0f / ce.current.proj.m00 / ce.current.viewport.width * 1.4142135623730950488016887242097f );
sd.nrmlBias = new Vector4( asd.nrmlBiasMin, asd.nrmlBiasMax, asd.nrmlBiasScale, ShadowUtils.Asfloat( flags ) );

1
ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBase.cs


public uint id; // packed texture id, sampler id and slice idx
public uint shadowType; // determines the shadow algorithm, i.e. which map to sample and how to interpret the data
public uint payloadOffset; // if this shadow type requires additional data it can be fetched from a global Buffer<uint> at payloadOffset.
public float edgeTolerance; // specifies the offset along either the normal or view vector used for calculating the edge leak fixup
public Vector4 viewBias; // x = min, y = max, z = scale, w = shadowmap texel size in world space at distance 1 from light
public Vector4 nrmlBias; // x = min, y = max, z = scale, w = enable/disable sample biasing

5
ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBase.cs.hlsl


uint id;
uint shadowType;
uint payloadOffset;
float edgeTolerance;
float4 viewBias;
float4 nrmlBias;
};

uint GetPayloadOffset(ShadowData value)
{
return value.payloadOffset;
}
float GetEdgeTolerance(ShadowData value)
{
return value.edgeTolerance;
}
float4 GetViewBias(ShadowData value)
{

正在加载...
取消
保存