浏览代码

addressed some PR commenst, started adding metal, smoothnes, height to decals.

/prototype-decals
Paul Melamed 7 年前
当前提交
1f7d870b
共有 5 个文件被更改,包括 48 次插入47 次删除
  1. 36
      ScriptableRenderPipeline/Core/CoreUtils.cs
  2. 46
      ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs
  3. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  4. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl

36
ScriptableRenderPipeline/Core/CoreUtils.cs


QuickSort(arr, pivot + 1, right);
}
}
public static Mesh CreateDecalMesh()
{
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[8];
vertices[0] = new Vector3(-0.5f, -1.0f, -0.5f);
vertices[1] = new Vector3(0.5f, -1.0f, -0.5f);
vertices[2] = new Vector3(0.5f, 0.0f, -0.5f);
vertices[3] = new Vector3(-0.5f, 0.0f, -0.5f);
vertices[4] = new Vector3(-0.5f, -1.0f, 0.5f);
vertices[5] = new Vector3(0.5f, -1.0f, 0.5f);
vertices[6] = new Vector3(0.5f, 0.0f, 0.5f);
vertices[7] = new Vector3(-0.5f, 0.0f, 0.5f);
mesh.vertices = vertices;
int[] triangles = new int[36];
triangles[0] = 0; triangles[1] = 2; triangles[2] = 1;
triangles[3] = 0; triangles[4] = 3; triangles[5] = 2;
triangles[6] = 1; triangles[7] = 6; triangles[8] = 5;
triangles[9] = 1; triangles[10] = 2; triangles[11] = 6;
triangles[12] = 5; triangles[13] = 7; triangles[14] = 4;
triangles[15] = 5; triangles[16] = 6; triangles[17] = 7;
triangles[18] = 4; triangles[19] = 3; triangles[20] = 0;
triangles[21] = 4; triangles[22] = 7; triangles[23] = 3;
triangles[24] = 3; triangles[25] = 6; triangles[26] = 2;
triangles[27] = 3; triangles[28] = 7; triangles[29] = 6;
triangles[30] = 4; triangles[31] = 1; triangles[32] = 5;
triangles[33] = 4; triangles[34] = 0; triangles[35] = 1;
mesh.triangles = triangles;
return mesh;
}
}
}

46
ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs


}
internal HashSet<DecalProjectorComponent> m_Decals = new HashSet<DecalProjectorComponent>();
Mesh m_CubeMesh;
Mesh m_DecalMesh;
CreateCubeMesh();
}
void CreateCubeMesh()
{
m_CubeMesh = new Mesh();
Vector3[] vertices = new Vector3[8];
vertices[0] = new Vector3(-0.5f, -1.0f, -0.5f);
vertices[1] = new Vector3( 0.5f, -1.0f, -0.5f);
vertices[2] = new Vector3( 0.5f, 0.0f, -0.5f);
vertices[3] = new Vector3(-0.5f, 0.0f, -0.5f);
vertices[4] = new Vector3(-0.5f, -1.0f, 0.5f);
vertices[5] = new Vector3( 0.5f, -1.0f, 0.5f);
vertices[6] = new Vector3( 0.5f, 0.0f, 0.5f);
vertices[7] = new Vector3(-0.5f, 0.0f, 0.5f);
m_CubeMesh.vertices = vertices;
int[] triangles = new int[36];
triangles[0] = 0; triangles[1] = 2; triangles[2] = 1;
triangles[3] = 0; triangles[4] = 3; triangles[5] = 2;
triangles[6] = 1; triangles[7] = 6; triangles[8] = 5;
triangles[9] = 1; triangles[10] = 2; triangles[11] = 6;
triangles[12] = 5; triangles[13] = 7; triangles[14] = 4;
triangles[15] = 5; triangles[16] = 6; triangles[17] = 7;
triangles[18] = 4; triangles[19] = 3; triangles[20] = 0;
triangles[21] = 4; triangles[22] = 7; triangles[23] = 3;
triangles[24] = 3; triangles[25] = 6; triangles[26] = 2;
triangles[27] = 3; triangles[28] = 7; triangles[29] = 6;
triangles[30] = 4; triangles[31] = 1; triangles[32] = 5;
triangles[33] = 4; triangles[34] = 0; triangles[35] = 1;
m_CubeMesh.triangles = triangles;
m_DecalMesh = CoreUtils.CreateDecalMesh();
public void AddDecal(DecalProjectorComponent d)
{
// If no decal material assign, don't add it

public void Render(ScriptableRenderContext renderContext, Vector3 cameraPos, CommandBuffer cmd)
{
if (m_CubeMesh == null)
CreateCubeMesh();
if (m_DecalMesh == null)
m_DecalMesh = CoreUtils.CreateDecalMesh();
cmd.DrawMesh(m_CubeMesh, decal.transform.localToWorldMatrix, decal.m_Material, 0, 0, decal.GetPropertyBlock());
cmd.DrawMesh(m_DecalMesh, decal.transform.localToWorldMatrix, decal.m_Material, 0, 0, decal.GetPropertyBlock());
}
}
}

3
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


void RenderDBuffer(Vector3 cameraPos, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
// Currently disabled
return ;
using (new ProfilingSample(cmd, "DBuffer", GetSampler(CustomSamplerId.DBuffer)))
{
CoreUtils.SetRenderTarget(cmd, m_DbufferManager.GetDBuffers(), m_CameraDepthStencilBufferRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);

8
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs


public Vector4 baseColor;
[SurfaceDataAttributes("Normal", true)]
public Vector4 normalWS;
[SurfaceDataAttributes("Metal Smoothness Height", true)]
public Vector4 MSH;
};
[GenerateHLSL(PackingRules.Exact)]

Count = 2
Count = 3
};
//-----------------------------------------------------------------------------

// should this be combined into common class shared with Lit.cs???
static public int GetMaterialDBufferCount() { return (int)DBufferMaterial.Count; }
static RenderTextureFormat[] m_RTFormat = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32};
static RenderTextureReadWrite[] m_RTReadWrite = { RenderTextureReadWrite.sRGB, RenderTextureReadWrite.Linear};
static RenderTextureFormat[] m_RTFormat = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32 };
static RenderTextureReadWrite[] m_RTReadWrite = { RenderTextureReadWrite.sRGB, RenderTextureReadWrite.Linear, RenderTextureReadWrite.Linear};
static public void GetMaterialDBufferDescription(out RenderTextureFormat[] RTFormat, out RenderTextureReadWrite[] RTReadWrite)
{

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl


void AddDecalContribution(uint2 unPositionSS, inout SurfaceData surfaceData)
{
// Currently disabled
#if 0
#if 1
FETCH_DBUFFER(DBuffer, _DBufferTexture, unPositionSS);
DecalSurfaceData decalSurfaceData;
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData);

正在加载...
取消
保存