浏览代码

Allow decal projectors with null materials, so that users can still modify projector decals even when HDRP is not set as current pipeline.

/main
Paul Melamed 7 年前
当前提交
daa031aa
共有 2 个文件被更改,包括 26 次插入4 次删除
  1. 11
      com.unity.render-pipelines.high-definition/HDRP/Decal/DecalProjectorComponent.cs
  2. 19
      com.unity.render-pipelines.high-definition/HDRP/Decal/DecalSystem.cs

11
com.unity.render-pipelines.high-definition/HDRP/Decal/DecalProjectorComponent.cs


}
if (m_Handle != null)
{
m_Handle = null;
}
Vector4 uvScaleBias = new Vector4(m_UVScale.x, m_UVScale.y, m_UVBias.x, m_UVBias.y);
m_Handle = DecalSystem.instance.AddDecal(transform, m_DrawDistance, m_FadeScale, uvScaleBias, m_Material);
}

DecalSystem.instance.RemoveDecal(m_Handle);
m_Handle = null;
if (m_Handle != null)
{
DecalSystem.instance.RemoveDecal(m_Handle);
m_Handle = null;
}
}
// Declare the method signature of the delegate to call.

19
com.unity.render-pipelines.high-definition/HDRP/Decal/DecalSystem.cs


public class DecalSystem
{
public const int kInvalidIndex = -1;
public const int kNullMaterialIndex = int.MaxValue;
public class DecalHandle
{
public DecalHandle(int index, int materialID)

{
public void InitializeMaterialValues()
{
if (m_Material == null)
return;
m_Diffuse.m_Texture = m_Material.GetTexture("_BaseColorMap");
m_Normal.m_Texture = m_Material.GetTexture("_NormalMap");
m_Mask.m_Texture = m_Material.GetTexture("_MaskMap");

public DecalSet(Material material)
{
m_Material = material;
m_Material = material;
InitializeMaterialValues();
}

public void UpdateCachedData(Transform transform, float drawDistance, float fadeScale, Vector4 uvScaleBias, DecalHandle handle)
{
if (m_Material == null)
return;
int index = handle.m_Index;
m_CachedDecalToWorld[index] = transform.localToWorldMatrix;

public void BeginCull()
{
if (m_Material == null)
return;
if (m_CullingGroup != null)
{
Debug.LogError("Begin/EndCull() called out of sequence for decal projectors.");

public int QueryCullResults()
{
if (m_Material == null)
return 0;
m_NumResults = m_CullingGroup.QueryIndices(true, m_ResultIndices, 0);
return m_NumResults;
}

public void CreateDrawData()
{
if (m_Material == null)
return;
if (m_NumResults == 0)
return;
// only add if anything in this decal set is visible.

public void EndCull()
{
if (m_Material == null)
return;
if (m_CullingGroup == null)
{
Debug.LogError("Begin/EndCull() called out of sequence for decal projectors.");

public void RenderIntoDBuffer(CommandBuffer cmd)
{
if (m_Material == null)
return;
if (m_NumResults == 0)
return;
int batchIndex = 0;

public DecalHandle AddDecal(Transform transform, float drawDistance, float fadeScale, Vector4 uvScaleBias, Material material)
{
DecalSet decalSet = null;
int key = material.GetInstanceID();
int key = material != null ? material.GetInstanceID() : kNullMaterialIndex;
if (!m_DecalSets.TryGetValue(key, out decalSet))
{
decalSet = new DecalSet(material);

正在加载...
取消
保存