private const int kDrawIndexedBatchSize = 2 5 0 ;
// cube mesh bounds for decal
static Vector4 kMin = new Vector4 ( - 0.5f , - 1. 0f, - 0.5f , 1.0f ) ;
static Vector4 kMax = new Vector4 ( 0.5f , 0.0 f , 0.5f , 1.0f ) ;
static Vector4 kMin = new Vector4 ( - 0.5f , - 0.5 f , - 0.5f , 1.0f ) ;
static Vector4 kMax = new Vector4 ( 0.5f , 0.5 f , 0.5f , 1.0f ) ;
static public Mesh m_DecalMesh = null ;
return res ;
}
public void UpdateCachedData ( Transform transform , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , DecalHandle handle )
public void UpdateCachedData ( Transform transform , Matrix4x4 sizeOffset , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , DecalHandle handle )
m_CachedDecalToWorld [ index ] = transform . localToWorldMatrix ;
m_CachedDecalToWorld [ index ] = transform . localToWorldMatrix * sizeOffset ;
Matrix4x4 decalRotation = Matrix4x4 . Rotate ( transform . rotation ) ;
// z/y axis swap for normal to decal space, Unity is column major
m_BoundingSpheres [ index ] = GetDecalProjectBoundingSphere ( m_CachedDecalToWorld [ index ] ) ;
}
public DecalHandle AddDecal ( Transform transform , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , int materialID )
public DecalHandle AddDecal ( Transform transform , Matrix4x4 sizeOffset , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , int materialID )
{
// increase array size if no space left
if ( m_DecalsCount = = m_Handles . Length )
DecalHandle decalHandle = new DecalHandle ( m_DecalsCount , materialID ) ;
m_Handles [ m_DecalsCount ] = decalHandle ;
UpdateCachedData ( transform , drawDistance , fadeScale , uvScaleBias , affectsTransparency , decalHandle ) ;
UpdateCachedData ( transform , sizeOffset , drawDistance , fadeScale , uvScaleBias , affectsTransparency , decalHandle ) ;
m_DecalsCount + + ;
return decalHandle ;
}
var influenceX = decalToWorld . GetColumn ( 0 ) * 0.5f ;
var influenceY = decalToWorld . GetColumn ( 1 ) * 0.5f ;
var influenceZ = decalToWorld . GetColumn ( 2 ) * 0.5f ;
var pos = decalToWorld . GetColumn ( 3 ) - influenceY ; // decal cube mesh pivot is at 0,0,0, with bottom face at -1 on the y plane
var pos = decalToWorld . GetColumn ( 3 ) ;
Vector3 influenceExtents = new Vector3 ( ) ;
influenceExtents . x = influenceX . magnitude ;
TextureScaleBias m_Mask = new TextureScaleBias ( ) ;
}
public DecalHandle AddDecal ( Transform transform , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , Material material )
public DecalHandle AddDecal ( Transform transform , Matrix4x4 sizeOffset , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , Material material )
{
DecalSet decalSet = null ;
int key = material ! = null ? material . GetInstanceID ( ) : kNullMaterialIndex ;
m_DecalSets . Add ( key , decalSet ) ;
}
return decalSet . AddDecal ( transform , drawDistance , fadeScale , uvScaleBias , affectsTransparency , key ) ;
return decalSet . AddDecal ( transform , sizeOffset , drawDistance , fadeScale , uvScaleBias , affectsTransparency , key ) ;
}
public void RemoveDecal ( DecalHandle handle )
}
}
public void UpdateCachedData ( Transform transform , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , DecalHandle handle )
public void UpdateCachedData ( Transform transform , Matrix4x4 sizeOffset , float drawDistance , float fadeScale , Vector4 uvScaleBias , bool affectsTransparency , DecalHandle handle )
{
if ( ! DecalHandle . IsValid ( handle ) )
return ;
if ( m_DecalSets . TryGetValue ( key , out decalSet ) )
{
decalSet . UpdateCachedData ( transform , drawDistance , fadeScale , uvScaleBias , affectsTransparency , handle ) ;
decalSet . UpdateCachedData ( transform , sizeOffset , drawDistance , fadeScale , uvScaleBias , affectsTransparency , handle ) ;
}
}