浏览代码

Add a subsurface scattering manager to allocate RT

/main
sebastienlagarde 7 年前
当前提交
b2780d61
共有 6 个文件被更改,包括 81 次插入46 次删除
  1. 32
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 22
      ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs.meta
  4. 51
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
  5. 20
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.cs
  6. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs.meta

32
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine.Rendering;
using System;
using System.Diagnostics;

readonly List<RenderPipelineMaterial> m_MaterialList = new List<RenderPipelineMaterial>();
readonly GBufferManager m_GbufferManager = new GBufferManager();
readonly SubsurfaceScatteringManager m_SSSBufferManager = new SubsurfaceScatteringManager();
// Renderer Bake configuration can vary depends on if shadow mask is enabled or no
RendererConfiguration m_currentRendererConfigurationBakedLighting = HDUtils.k_RendererConfigurationBakedLighting;

cmd.SetComputeVectorArrayParam(m_SubsurfaceScatteringCS, HDShaderIDs._WorldScales, sssParameters.worldScales);
cmd.SetComputeVectorArrayParam(m_SubsurfaceScatteringCS, HDShaderIDs._FilterKernels, sssParameters.filterKernels);
cmd.SetComputeVectorArrayParam(m_SubsurfaceScatteringCS, HDShaderIDs._ShapeParams, sssParameters.shapeParams);
// TODO: abstract this in SSS manager
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._SSSBufferTexture0, m_GbufferManager.GetGBuffers()[0]);
cmd.SetComputeVectorArrayParam(m_SubsurfaceScatteringCS, HDShaderIDs._ShapeParams, sssParameters.shapeParams);
for (int i = 0; i < m_SSSBufferManager.sssBufferCount; ++i)
{
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._SSSBufferTexture[i], m_SSSBufferManager.GetSSSBuffers(i));
}
if (NeedTemporarySubsurfaceBuffer())
{

}
else
{
// TODO: abstract this in SSS manager
cmd.SetGlobalTexture(HDShaderIDs._SSSBufferTexture0, m_GbufferManager.GetGBuffers()[0]);
for (int i = 0; i < m_SSSBufferManager.sssBufferCount; ++i)
{
cmd.SetGlobalTexture(HDShaderIDs._SSSBufferTexture[i], m_SSSBufferManager.GetSSSBuffers(i));
}
cmd.SetGlobalTexture(HDShaderIDs._IrradianceSource, m_CameraSssDiffuseLightingBufferRT); // Cannot set a RT on a material
m_SssVerticalFilterPass.SetVectorArray(HDShaderIDs._WorldScales, sssParameters.worldScales);

cmd.GetTemporaryRT(m_DepthPyramidBuffer, m_DepthPyramidBufferDesc, FilterMode.Trilinear);
// End
// TODO: commented just to test forward SSS until we implement correct manager.
// In forward we need to allocate a target for SSSBuffer0
//if (!m_Asset.globalRenderingSettings.ShouldUseForwardRenderingOnly())
if (!m_Asset.globalRenderingSettings.ShouldUseForwardRenderingOnly())
{
m_SSSBufferManager.InitGBuffers(w, h, m_GbufferManager, cmd);
}
else
{
// We need to allocate target for SSS
m_SSSBufferManager.InitGBuffers(w, h, cmd);
}
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.Depth);
}

22
ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs


public static readonly int g_BaseFeatureFlags = Shader.PropertyToID("g_BaseFeatureFlags");
public static readonly int g_TileFeatureFlags = Shader.PropertyToID("g_TileFeatureFlags");
public static readonly int _GBufferTexture0 = Shader.PropertyToID("_GBufferTexture0");
public static readonly int _GBufferTexture1 = Shader.PropertyToID("_GBufferTexture1");
public static readonly int _GBufferTexture2 = Shader.PropertyToID("_GBufferTexture2");
public static readonly int _GBufferTexture3 = Shader.PropertyToID("_GBufferTexture3");
public static readonly int _GBufferTexture4 = Shader.PropertyToID("_GBufferTexture4");
public static readonly int _GBufferTexture5 = Shader.PropertyToID("_GBufferTexture5");
public static readonly int _GBufferTexture6 = Shader.PropertyToID("_GBufferTexture6");
public static readonly int _GBufferTexture7 = Shader.PropertyToID("_GBufferTexture7");
public static readonly int _SSSBufferTexture0 = Shader.PropertyToID("_SSSBufferTexture0");
public static readonly int _SSSBufferTexture1 = Shader.PropertyToID("_SSSBufferTexture1");
public static readonly int _SSSBufferTexture2 = Shader.PropertyToID("_SSSBufferTexture2");
public static readonly int _SSSBufferTexture3 = Shader.PropertyToID("_SSSBufferTexture3");
public static readonly int g_DispatchIndirectBuffer = Shader.PropertyToID("g_DispatchIndirectBuffer");
public static readonly int g_TileList = Shader.PropertyToID("g_TileList");
public static readonly int g_NumTiles = Shader.PropertyToID("g_NumTiles");

Shader.PropertyToID("_GBufferTexture5"),
Shader.PropertyToID("_GBufferTexture6"),
Shader.PropertyToID("_GBufferTexture7")
};
public static readonly int[] _SSSBufferTexture =
{
Shader.PropertyToID("_SSSBufferTexture0"),
Shader.PropertyToID("_SSSBufferTexture1"),
Shader.PropertyToID("_SSSBufferTexture2"),
Shader.PropertyToID("_SSSBufferTexture3"),
};
public static readonly int _VelocityTexture = Shader.PropertyToID("_VelocityTexture");

2
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs.meta


fileFormatVersion: 2
guid: 26e79cea58f13e241ba3ecee1a281ebc
guid: 3cc1ef76b6eee1248b23ec5f6dee0bae
MonoImporter:
externalObjects: {}
serializedVersion: 2

51
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs


using UnityEngine.Rendering;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class SubsurfaceScatteringManager
{
// Currently we only support SSSBuffer with one buffer. If the shader code change, it may require to update the shader manager
public const int k_MaxSSSBuffer = 1;
readonly int m_SSSBuffer0;
readonly RenderTargetIdentifier m_SSSBuffer0RT;
public int sssBufferCount { get; set; }
RenderTargetIdentifier[] m_ColorMRTs;
RenderTargetIdentifier[] m_RTIDs = new RenderTargetIdentifier[k_MaxSSSBuffer];
public SubsurfaceScatteringManager()
{
m_SSSBuffer0RT = new RenderTargetIdentifier(m_SSSBuffer0);
}
// In case of deferred, we must be in sync with SubsurfaceScattering.hlsl and lit.hlsl files and setup the correct buffers
// for SSS
public void InitGBuffers(int width, int height, GBufferManager gbufferManager, CommandBuffer cmd)
{
sssBufferCount = k_MaxSSSBuffer;
m_RTIDs[0] = gbufferManager.GetGBuffers()[0];
}
// In case of full forward we must allocate the render target for forward SSS (or reuse one already existing)
// TODO: Provide a way to reuse a render target
public void InitGBuffers(int width, int height, CommandBuffer cmd)
{
sssBufferCount = k_MaxSSSBuffer;
m_RTIDs[0] = m_SSSBuffer0RT;
cmd.ReleaseTemporaryRT(m_SSSBuffer0);
cmd.GetTemporaryRT(m_SSSBuffer0, width, height, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
}
public RenderTargetIdentifier GetSSSBuffers(int index)
{
Debug.Assert(index < sssBufferCount);
return m_RTIDs[index];
}
}
}

20
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.cs


using UnityEngine.Rendering;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class SubsurfaceScatteringManager
{
public const int k_MaxGbuffer = 2;
public int sssbufferCount { get; set; }
RenderTargetIdentifier[] m_ColorMRTs;
RenderTargetIdentifier[] m_RTIDs = new RenderTargetIdentifier[k_MaxGbuffer];
// public RenderTargetIdentifier SSSBuffer[2];
// public SetSSSBuffer();
}
}

/ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.cs.meta → /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs.meta

正在加载...
取消
保存