|
|
|
|
|
|
// Core\CoreRP\ShaderLibrary\UnityInstancing.hlsl
|
|
|
|
// #if defined(SHADER_API_VULKAN) && defined(SHADER_API_MOBILE)
|
|
|
|
// #define UNITY_INSTANCED_ARRAY_SIZE 250
|
|
|
|
private const int kDrawIndexedBatchSize = 250; |
|
|
|
private const int kDrawIndexedBatchSize = 250; |
|
|
|
|
|
|
|
// cube mesh bounds for decal
|
|
|
|
static Vector4 kMin = new Vector4(-0.5f, -1.0f, -0.5f, 1.0f); |
|
|
|
|
|
|
m_DiffuseTexture = m_Material.GetTexture("_BaseColorMap"); |
|
|
|
m_NormalTexture = m_Material.GetTexture("_NormalMap"); |
|
|
|
m_MaskTexture = m_Material.GetTexture("_MaskMap"); |
|
|
|
m_Blend = m_Material.GetFloat("_DecalBlend"); |
|
|
|
m_Blend = m_Material.GetFloat("_DecalBlend"); |
|
|
|
} |
|
|
|
|
|
|
|
public DecalSet(Material material) |
|
|
|
|
|
|
normalToWorldBatch[instanceCount].m23 = m_NormalTexIndex; |
|
|
|
normalToWorldBatch[instanceCount].m33 = m_MaskTexIndex; |
|
|
|
|
|
|
|
|
|
|
|
// clustered forward data
|
|
|
|
m_DecalDatas[m_DecalDatasCount].worldToDecal = decalToWorldBatch[instanceCount].inverse; |
|
|
|
|
|
|
|
// clustered forward data
|
|
|
|
m_DecalDatas[m_DecalDatasCount].worldToDecal = decalToWorldBatch[instanceCount].inverse; |
|
|
|
|
|
|
|
|
|
|
|
instanceCount++; |
|
|
|
if (instanceCount == kDrawIndexedBatchSize) |
|
|
|
{ |
|
|
|
|
|
|
InitializeMaterialValues(); // refresh in case they changed in the UI
|
|
|
|
UpdateTextureCache(cmd); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void RenderIntoDBuffer(CommandBuffer cmd) |
|
|
|
{ |
|
|
|
if(m_NumResults == 0) |
|
|
|
|
|
|
{ |
|
|
|
m_PropertyBlock.SetMatrixArray(HDShaderIDs._NormalToWorldID, m_NormalToWorld[batchIndex]); |
|
|
|
cmd.DrawMeshInstanced(m_DecalMesh, 0, KeyMaterial, 0, m_DecalToWorld[batchIndex], totalToDraw, m_PropertyBlock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Material KeyMaterial |
|
|
|
{ |
|
|
|
get |
|
|
|
|
|
|
private int m_NormalTexIndex = -1; |
|
|
|
private int m_MaskTexIndex = -1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void AddDecal(DecalProjectorComponent decal) |
|
|
|
{ |
|
|
|
if (decal.CullIndex != DecalProjectorComponent.kInvalidIndex) //do not add the same decal more than once
|
|
|
|
|
|
|
foreach (var pair in m_DecalSets) |
|
|
|
{ |
|
|
|
pair.Value.RenderIntoDBuffer(cmd); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void SetAtlas(CommandBuffer cmd) |
|
|
|
|
|
|
|
|
|
|
public void CreateDrawData() |
|
|
|
{ |
|
|
|
m_DecalDatasCount = 0; |
|
|
|
m_DecalDatasCount = 0; |
|
|
|
// reallocate if needed
|
|
|
|
if (m_DecalsVisibleThisFrame > m_DecalDatas.Length) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
pair.Value.CreateDrawData(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void Cleanup() |
|
|
|
{ |
|
|
|
m_DecalAtlas.Release(); |
|
|
|
CoreUtils.Destroy(m_DecalMesh); |
|
|
|
} |
|
|
|
} |
|
|
|
} |