public void AddDecal(DecalProjectorComponent decal) { // increase array size if no space left if (m_DecalsCount == m_Decals.Length) { DecalProjectorComponent[] newDecals = new DecalProjectorComponent[m_DecalsCount + kDecalBlockSize]; BoundingSphere[] newSpheres = new BoundingSphere[m_DecalsCount + kDecalBlockSize]; Matrix4x4[] newCachedTransforms = new Matrix4x4[m_DecalsCount + kDecalBlockSize]; Matrix4x4[] newCachedNormalToWorld = new Matrix4x4[m_DecalsCount + kDecalBlockSize]; m_ResultIndices = new int[m_DecalsCount + kDecalBlockSize]; m_Decals.CopyTo(newDecals, 0); m_BoundingSpheres.CopyTo(newSpheres, 0); m_CachedTransforms.CopyTo(newCachedTransforms, 0); m_CachedNormalToWorld.CopyTo(newCachedNormalToWorld, 0); m_Decals = newDecals; m_BoundingSpheres = newSpheres; m_CachedTransforms = newCachedTransforms; m_CachedNormalToWorld = newCachedNormalToWorld; } m_Decals[m_DecalsCount] = decal; m_Decals[m_DecalsCount].CullIndex = m_DecalsCount; UpdateBoundingSphere(m_Decals[m_DecalsCount]); m_DecalsCount++; }
public void UpdateCachedData(DecalProjectorComponent decal) { m_CachedDecalToWorld[decal.CullIndex] = decal.transform.localToWorldMatrix; Matrix4x4 decalRotation = Matrix4x4.Rotate(decal.transform.rotation); // z/y axis swap for normal to decal space, Unity is column major float y0 = decalRotation.m01; float y1 = decalRotation.m11; float y2 = decalRotation.m21; decalRotation.m01 = decalRotation.m02; decalRotation.m11 = decalRotation.m12; decalRotation.m21 = decalRotation.m22; decalRotation.m02 = y0; decalRotation.m12 = y1; decalRotation.m22 = y2; m_CachedNormalToWorld[decal.CullIndex] = decalRotation; // draw distance can't be more than global draw distance m_CachedDrawDistances[decal.CullIndex].x = decal.m_DrawDistance < instance.DrawDistance ? decal.m_DrawDistance : instance.DrawDistance; m_CachedDrawDistances[decal.CullIndex].y = decal.m_FadeScale; m_BoundingSpheres[decal.CullIndex] = GetDecalProjectBoundingSphere(m_CachedDecalToWorld[decal.CullIndex]); }
public void AddDecal(DecalProjectorComponent decal) { if (decal.CullIndex != DecalProjectorComponent.kInvalidIndex) //do not add the same decal more than once { return; } // increase array size if no space left if (m_DecalsCount == m_Decals.Length) { DecalProjectorComponent[] newDecals = new DecalProjectorComponent[m_DecalsCount + kDecalBlockSize]; BoundingSphere[] newSpheres = new BoundingSphere[m_DecalsCount + kDecalBlockSize]; m_ResultIndices = new int[m_DecalsCount + kDecalBlockSize]; m_Decals.CopyTo(newDecals, 0); m_BoundingSpheres.CopyTo(newSpheres, 0); m_Decals = newDecals; m_BoundingSpheres = newSpheres; } m_Decals[m_DecalsCount] = decal; m_Decals[m_DecalsCount].CullIndex = m_DecalsCount; UpdateBoundingSphere(m_Decals[m_DecalsCount]); m_DecalsCount++; }
public void AddDecal(DecalProjectorComponent d) { // If no decal material assign, don't add it if (d.m_Material == null) { return; } if (d.m_Material.GetTexture("_BaseColorMap") || d.m_Material.GetTexture("_NormalMap")) { RemoveDecal(d); m_Decals.Add(d); } }
public void UpdateBoundingSphere(DecalProjectorComponent decal) { if (decal.CullIndex == DecalProjectorComponent.kInvalidIndex) // check if we have this decal { return; } DecalSet decalSet = null; int key = decal.m_Material.GetInstanceID(); if (m_DecalSets.TryGetValue(key, out decalSet)) { decalSet.UpdateBoundingSphere(decal); } }
public void RemoveDecal(DecalProjectorComponent decal) { int removeAtIndex = decal.CullIndex; // replace with last decal in the list and update index m_Decals[removeAtIndex] = m_Decals[m_DecalsCount - 1]; // move the last decal in list m_Decals[removeAtIndex].CullIndex = removeAtIndex; m_Decals[m_DecalsCount - 1] = null; // update the bounding spheres array m_BoundingSpheres[removeAtIndex] = m_BoundingSpheres[m_DecalsCount - 1]; m_CachedTransforms[removeAtIndex] = m_CachedTransforms[m_DecalsCount - 1]; m_CachedNormalToWorld[removeAtIndex] = m_CachedNormalToWorld[m_DecalsCount - 1]; m_DecalsCount--; decal.CullIndex = DecalProjectorComponent.kInvalidIndex; }
public void RemoveDecal(DecalProjectorComponent decal) { if (decal.CullIndex == DecalProjectorComponent.kInvalidIndex) // check if we have this decal { return; } DecalSet decalSet = null; int key = decal.m_Material.GetInstanceID(); if (m_DecalSets.TryGetValue(key, out decalSet)) { decalSet.RemoveDecal(decal); if (decalSet.Count == 0) { m_DecalSets.Remove(key); } } }
public void RemoveDecal(DecalProjectorComponent decal) { if (decal.CullIndex == DecalProjectorComponent.kInvalidIndex) //do not remove decal that has not been added { return; } int removeAtIndex = decal.CullIndex; // replace with last decal in the list and update index m_Decals[removeAtIndex] = m_Decals[m_DecalsCount - 1]; // move the last decal in list m_Decals[removeAtIndex].CullIndex = removeAtIndex; m_Decals[m_DecalsCount - 1] = null; // update the bounding spheres array m_BoundingSpheres[removeAtIndex] = m_BoundingSpheres[m_DecalsCount - 1]; m_DecalsCount--; decal.CullIndex = DecalProjectorComponent.kInvalidIndex; }
public void UpdateBoundingSphere(DecalProjectorComponent decal) { m_CachedTransforms[decal.CullIndex] = decal.transform.localToWorldMatrix; Matrix4x4 decalRotation = Matrix4x4.Rotate(decal.transform.rotation); // z/y axis swap for normal to decal space, Unity is column major float y0 = decalRotation.m01; float y1 = decalRotation.m11; float y2 = decalRotation.m21; decalRotation.m01 = decalRotation.m02; decalRotation.m11 = decalRotation.m12; decalRotation.m21 = decalRotation.m22; decalRotation.m02 = y0; decalRotation.m12 = y1; decalRotation.m22 = y2; m_CachedNormalToWorld[decal.CullIndex] = decalRotation; m_BoundingSpheres[decal.CullIndex] = GetDecalProjectBoundingSphere(m_CachedTransforms[decal.CullIndex]); }
public void AddDecal(DecalProjectorComponent decal) { if (decal.CullIndex != DecalProjectorComponent.kInvalidIndex) //do not add the same decal more than once { return; } if (!decal.IsValid()) { return; } DecalSet decalSet = null; int key = decal.m_Material.GetInstanceID(); if (!m_DecalSets.TryGetValue(key, out decalSet)) { decalSet = new DecalSet(decal.m_Material); m_DecalSets.Add(key, decalSet); } decalSet.AddDecal(decal); }
public void RemoveDecal(DecalProjectorComponent d) { m_Decals.Remove(d); }
// update bounding sphere for a single decal public void UpdateBoundingSphere(DecalProjectorComponent decal) { m_BoundingSpheres[decal.CullIndex] = GetDecalProjectBoundingSphere(decal.transform.localToWorldMatrix); }