浏览代码

Added checking the individual shadow fade distance per light to the shadow managers prune function.

/main
uygar 7 年前
当前提交
015180f0
共有 2 个文件被更改,包括 14 次插入13 次删除
  1. 25
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/Shadow.cs
  2. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowUtilities.cs

25
Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/Shadow.cs


ShadowUtils.Unpack( sr.shadowAlgorithm, out algo, out vari, out prec );
CheckDataIntegrity( algo, vari, prec, ref shadowData );
switch( ShadowUtils.ExtractAlgorithm( sr.shadowAlgorithm ) )
switch( algo )
{
case ShadowAlgorithm.VSM:
{

// at this point the array is sorted in order of some importance determined by the prioritize function
requestsGranted.Reserve( shadowRequests.Count() );
totalRequestCount = 0;
Vector3 campos = new Vector3( camera.transform.position.x, camera.transform.position.y, camera.transform.position.z );
ShadowmapBase.ShadowRequest sreq = new ShadowmapBase.ShadowRequest();
uint totalSlots = ResetMaxShadows();

{
int requestIdx = shadowRequests[i];
VisibleLight vl = lights[requestIdx];
bool add = false;
switch( vl.lightType )
{
case LightType.Directional : add = --m_MaxShadows[(int)GPUShadowType.Directional , 0] >= 0; shadowType = GPUShadowType.Directional; facecount = m_ShadowSettings.directionalLightCascadeCount; break;
case LightType.Point : add = --m_MaxShadows[(int)GPUShadowType.Point , 0] >= 0; shadowType = GPUShadowType.Point ; facecount = 6; break;
case LightType.Spot : add = --m_MaxShadows[(int)GPUShadowType.Spot , 0] >= 0; shadowType = GPUShadowType.Spot ; facecount = 1; break;
}
AdditionalLightData ald = vl.light.GetComponent<AdditionalLightData>();
Vector3 lpos = new Vector3( vl.localToWorld.GetColumn( 3 ).x, vl.localToWorld.GetColumn( 3 ).y, vl.localToWorld.GetColumn( 3 ).z );
float distToCam = (campos - lpos).magnitude;
bool add = distToCam < ald.shadowFadeDistance;
// TODO: do the shadow distance logic here
switch( vl.lightType )
{
case LightType.Directional : add = --m_MaxShadows[(int)GPUShadowType.Directional , 0] >= 0; shadowType = GPUShadowType.Directional; facecount = m_ShadowSettings.directionalLightCascadeCount; break;
case LightType.Point : add = --m_MaxShadows[(int)GPUShadowType.Point , 0] >= 0; shadowType = GPUShadowType.Point ; facecount = 6; break;
case LightType.Spot : add = --m_MaxShadows[(int)GPUShadowType.Spot , 0] >= 0; shadowType = GPUShadowType.Spot ; facecount = 1; break;
}
}
if( add )

sreq.shadowType = shadowType;
int sa, sv, sp;
vl.light.GetComponent<AdditionalLightData>().GetShadowAlgorithm( out sa, out sv, out sp );
ald.GetShadowAlgorithm( out sa, out sv, out sp );
sreq.shadowAlgorithm = ShadowUtils.Pack( (ShadowAlgorithm) sa, (ShadowVariant) sv, (ShadowPrecision) sp );
totalRequestCount += (uint) facecount;
requestsGranted.AddUnchecked( sreq );

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowUtilities.cs


public static float Asfloat( int val ) { return System.BitConverter.ToSingle( System.BitConverter.GetBytes( val ), 0 ); }
public static int Asint( float val ) { return System.BitConverter.ToInt32( System.BitConverter.GetBytes( val ), 0 ); }
public static uint Asuint( float val ) { return System.BitConverter.ToUInt32( System.BitConverter.GetBytes( val ), 0 ); }
}
} // end of namespace UnityEngine.Experimental.ScriptableRenderLoop
正在加载...
取消
保存