|
|
|
|
|
|
private static readonly int m_DecalToWorldR = Shader.PropertyToID("_DecalToWorldR"); |
|
|
|
|
|
|
|
public Material m_Material; |
|
|
|
private MaterialPropertyBlock m_PropertyBlock; |
|
|
|
|
|
|
|
// normal space __x to decal space __x
|
|
|
|
// |\ |\
|
|
|
|
// y z z y
|
|
|
|
//
|
|
|
|
private static Matrix4x4 m_NormalToDecal = Matrix4x4.Scale(new Vector3(1.0f, 1.0f, -1.0f)) * Matrix4x4.Rotate(Quaternion.AngleAxis(-90.0f, new Vector3(1, 0, 0))); |
|
|
|
|
|
|
|
public int CullIndex |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
public void Start() |
|
|
|
{ |
|
|
|
m_PropertyBlock = new MaterialPropertyBlock(); |
|
|
|
DecalSystem.instance.AddDecal(this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
DrawGizmo(true); |
|
|
|
// if this object is selected there is a chance the transform was changed so update culling info
|
|
|
|
DecalSystem.instance.UpdateBoundingSphere(this); |
|
|
|
} |
|
|
|
|
|
|
|
public void UpdatePropertyBlock(Vector3 cameraPos) |
|
|
|
{ |
|
|
|
Matrix4x4 CRWStoAWS = new Matrix4x4(); |
|
|
|
if (ShaderConfig.s_CameraRelativeRendering == 1) |
|
|
|
{ |
|
|
|
CRWStoAWS = Matrix4x4.Translate(cameraPos); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
CRWStoAWS = Matrix4x4.identity; |
|
|
|
} |
|
|
|
|
|
|
|
Matrix4x4 final = transform.localToWorldMatrix; |
|
|
|
Matrix4x4 decalToWorldR = Matrix4x4.Rotate(transform.rotation) * m_NormalToDecal; |
|
|
|
Matrix4x4 worldToDecal = Matrix4x4.Translate(new Vector3(0.5f, 0.0f, 0.5f)) * Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f)) * final.inverse; |
|
|
|
if (m_PropertyBlock == null) |
|
|
|
{ |
|
|
|
m_PropertyBlock = new MaterialPropertyBlock(); |
|
|
|
} |
|
|
|
m_PropertyBlock.SetMatrix(m_DecalToWorldR, decalToWorldR); |
|
|
|
m_PropertyBlock.SetMatrix(m_WorldToDecal, worldToDecal * CRWStoAWS); |
|
|
|
} |
|
|
|
|
|
|
|
public MaterialPropertyBlock GetPropertyBlock() |
|
|
|
{ |
|
|
|
return m_PropertyBlock; |
|
|
|
} |
|
|
|
} |
|
|
|
} |