|
|
|
|
|
|
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 ); |
|
|
|