浏览代码

Merge all pyramid code into a single file

/feature-ScreenSpaceProjection
Frédéric Vauchelles 7 年前
当前提交
8fc3f919
共有 9 个文件被更改,包括 224 次插入315 次删除
  1. 74
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs.meta
  3. 209
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs
  4. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/DepthPyramid.cs.meta
  5. 96
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/ColorPyramid.cs
  6. 110
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/DepthPyramid.cs
  7. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/PyramidUtils.cs
  8. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/PyramidUtils.cs.meta
  9. 0
      /ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs.meta

74
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


RendererConfiguration m_currentRendererConfigurationBakedLighting = HDUtils.k_RendererConfigurationBakedLighting;
Material m_CopyStencilForNoLighting;
GPUCopy m_GPUCopy;
DepthPyramid m_DepthPyramid;
ColorPyramid m_ColorPyramid;
BufferPyramid m_BufferPyramid;
IBLFilterGGX m_IBLFilterGGX = null;

m_Asset = asset;
m_GPUCopy = new GPUCopy(asset.renderPipelineResources.copyChannelCS);
m_DepthPyramid = new DepthPyramid(
m_BufferPyramid = new BufferPyramid(
asset.renderPipelineResources.gaussianPyramidCS,
HDShaderIDs._GaussianPyramidColorMips,
m_ColorPyramid = new ColorPyramid(
asset.renderPipelineResources.gaussianPyramidCS,
HDShaderIDs._GaussianPyramidColorMips);
EncodeBC6H.DefaultInstance = EncodeBC6H.DefaultInstance ?? new EncodeBC6H(asset.renderPipelineResources.encodeBC6HCS);

}
using (new ProfilingSample(cmd, "Gaussian Pyramid Color", CustomSamplerId.GaussianPyramidColor.GetSampler()))
m_ColorPyramid.RenderPyramidColor(hdCamera, cmd, renderContext, m_CameraColorBufferRT, m_GaussianPyramidColorBufferRT);
m_BufferPyramid.RenderColorPyramid(hdCamera, cmd, renderContext, m_CameraColorBufferRT, m_GaussianPyramidColorBufferRT);
var size = new Vector4(m_ColorPyramid.renderTextureDescriptor.width, m_ColorPyramid.renderTextureDescriptor.height, m_ColorPyramid.usedMipMapCount, 0);
var size = new Vector4(m_BufferPyramid.colorRenderTextureDescriptor.width, m_BufferPyramid.colorRenderTextureDescriptor.height, m_BufferPyramid.colorUsedMipMapCount, 0);
PushFullScreenDebugTextureMip(cmd, m_GaussianPyramidColorBufferRT, m_ColorPyramid.usedMipMapCount, m_ColorPyramid.renderTextureDescriptor, hdCamera, isPreRefraction ? FullScreenDebugMode.PreRefractionColorPyramid : FullScreenDebugMode.FinalColorPyramid);
PushFullScreenDebugTextureMip(cmd, m_GaussianPyramidColorBufferRT, m_BufferPyramid.colorUsedMipMapCount, m_BufferPyramid.colorRenderTextureDescriptor, hdCamera, isPreRefraction ? FullScreenDebugMode.PreRefractionColorPyramid : FullScreenDebugMode.FinalColorPyramid);
}
void RenderPyramidDepth(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)

using (new ProfilingSample(cmd, "Pyramid Depth", CustomSamplerId.PyramidDepth.GetSampler()))
m_DepthPyramid.RenderPyramidDepth(hdCamera, cmd, renderContext, GetDepthTexture(), m_DepthPyramidBufferRT);
m_BufferPyramid.RenderDepthPyramid(hdCamera, cmd, renderContext, GetDepthTexture(), m_DepthPyramidBufferRT);
var depthSize = new Vector4(m_DepthPyramid.renderTextureDescriptor.width, m_DepthPyramid.renderTextureDescriptor.height, m_DepthPyramid.usedMipMapCount, 0);
var depthSize = new Vector4(m_BufferPyramid.depthRenderTextureDescriptor.width, m_BufferPyramid.depthRenderTextureDescriptor.height, m_BufferPyramid.depthUsedMipMapCount, 0);
PushFullScreenDebugDepthMip(cmd, m_DepthPyramidBufferRT, m_DepthPyramid.usedMipMapCount, m_DepthPyramid.renderTextureDescriptor, hdCamera, debugMode);
PushFullScreenDebugDepthMip(cmd, m_DepthPyramidBufferRT, m_BufferPyramid.depthUsedMipMapCount, m_BufferPyramid.depthRenderTextureDescriptor, hdCamera, debugMode);
cmd.SetGlobalTexture(HDShaderIDs._PyramidDepthTexture, m_DepthPyramidBuffer);
}

}
// Color and depth pyramids
m_ColorPyramid.Initialize(hdCamera, m_FrameSettings.enableStereo);
m_BufferPyramid.Initialize(hdCamera, m_FrameSettings.enableStereo);
cmd.GetTemporaryRT(m_GaussianPyramidColorBuffer, m_ColorPyramid.renderTextureDescriptor, FilterMode.Trilinear);
cmd.GetTemporaryRT(m_GaussianPyramidColorBuffer, m_BufferPyramid.colorRenderTextureDescriptor, FilterMode.Trilinear);
m_DepthPyramid.Initialize(hdCamera, m_FrameSettings.enableStereo);
m_BufferPyramid.Initialize(hdCamera, m_FrameSettings.enableStereo);
cmd.GetTemporaryRT(m_DepthPyramidBuffer, m_DepthPyramid.renderTextureDescriptor, FilterMode.Trilinear);
cmd.GetTemporaryRT(m_DepthPyramidBuffer, m_BufferPyramid.depthRenderTextureDescriptor, FilterMode.Trilinear);
// End
if (!m_FrameSettings.enableForwardRenderingOnly)

}
// END TEMP
}
}
static int CalculatePyramidSize(int w, int h)
{
return Mathf.ClosestPowerOfTwo(Mathf.Min(w, h));
}
static int GetPyramidSize(RenderTextureDescriptor pyramidDesc)
{
// The monoscopic pyramid texture has both the width and height
// matching, so the pyramid size could be either dimension.
// However, with stereo double-wide rendering, we will arrange
// two pyramid textures next to each other inside the double-wide
// texture. The whole texture width will no longer be representative
// of the pyramid size, but the height still corresponds to the pyramid.
return pyramidDesc.height;
}
public enum PyramidType
{
Color = 0,
Depth = 1
}
static RenderTextureDescriptor BuildPyramidDescriptor(HDCamera hdCamera, PyramidType pyramidType, bool stereoEnabled)
{
var desc = hdCamera.renderTextureDesc;
desc.colorFormat = (pyramidType == PyramidType.Color) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.RFloat;
desc.depthBufferBits = 0;
desc.useMipMap = true;
desc.autoGenerateMips = false;
desc.msaaSamples = 1; // These are approximation textures, they don't need MSAA
// for stereo double-wide, each half of the texture will represent a single eye's pyramid
//var widthModifier = 1;
//if (stereoEnabled && (desc.dimension != TextureDimension.Tex2DArray))
// widthModifier = 2; // double-wide
//desc.width = pyramidSize * widthModifier;
desc.width = (int)hdCamera.screenSize.x;
desc.height = (int)hdCamera.screenSize.y;
return desc;
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs.meta


fileFormatVersion: 2
guid: 334384fee1fa7b44486f0503cf7b24a0
guid: ea3e7945ee7dc7a479b9e6846a0c544c
MonoImporter:
externalObjects: {}
serializedVersion: 2

209
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
class BufferPyramid
{
static readonly int _Size = Shader.PropertyToID("_Size");
static readonly int _Source = Shader.PropertyToID("_Source");
static readonly int _Result = Shader.PropertyToID("_Result");
static readonly int _SrcSize = Shader.PropertyToID("_SrcSize");
const int k_DepthBlockSize = 4;
GPUCopy m_GPUCopy;
ComputeShader m_ColorPyramidCS;
RenderTextureDescriptor m_ColorRenderTextureDescriptor;
int[] m_ColorPyramidMips = new int[0];
int m_ColorPyramidKernel;
ComputeShader m_DepthPyramidCS;
RenderTextureDescriptor m_DepthRenderTextureDescriptor;
int[] m_DepthPyramidMips = new int[0];
int m_DepthPyramidKernel_8;
int m_DepthPyramidKernel_1;
public RenderTextureDescriptor colorRenderTextureDescriptor { get { return m_ColorRenderTextureDescriptor; } }
public int colorUsedMipMapCount { get { return Mathf.Min(colorBufferMipMapCount, m_ColorPyramidMips.Length); } }
public int colorBufferMipMapCount
{
get
{
var minSize = Mathf.Min(colorRenderTextureDescriptor.width, colorRenderTextureDescriptor.height);
return Mathf.FloorToInt(Mathf.Log(minSize, 2f));
}
}
public RenderTextureDescriptor depthRenderTextureDescriptor { get { return m_DepthRenderTextureDescriptor; } }
public int depthUsedMipMapCount { get { return Mathf.Min(depthBufferMipMapCount, m_DepthPyramidMips.Length); } }
public int depthBufferMipMapCount
{
get
{
var minSize = Mathf.Min(depthRenderTextureDescriptor.width, depthRenderTextureDescriptor.height);
return Mathf.FloorToInt(Mathf.Log(minSize, 2f));
}
}
public BufferPyramid(
ComputeShader colorPyramidCS, int[] colorMipIds,
ComputeShader depthPyramidCS, GPUCopy gpuCopy, int[] depthMipIds)
{
m_ColorPyramidCS = colorPyramidCS;
m_ColorPyramidKernel = m_ColorPyramidCS.FindKernel("KMain");
m_ColorPyramidMips = colorMipIds;
m_DepthPyramidCS = depthPyramidCS;
m_GPUCopy = gpuCopy;
m_DepthPyramidMips = depthMipIds;
m_DepthPyramidKernel_8 = m_DepthPyramidCS.FindKernel("KMain_8");
m_DepthPyramidKernel_1 = m_DepthPyramidCS.FindKernel("KMain_1");
}
public void RenderDepthPyramid(
HDCamera hdCamera,
CommandBuffer cmd,
ScriptableRenderContext renderContext,
RenderTargetIdentifier depthTexture,
RenderTargetIdentifier targetTexture)
{
var depthPyramidDesc = m_DepthRenderTextureDescriptor;
var lodCount = depthBufferMipMapCount;
if (lodCount > m_DepthPyramidMips.Length)
{
Debug.LogWarningFormat("Cannot compute all mipmaps of the depth pyramid, max texture size supported: {0}", (2 << m_DepthPyramidMips.Length).ToString());
lodCount = m_DepthPyramidMips.Length;
}
cmd.ReleaseTemporaryRT(m_DepthPyramidMips[0]);
depthPyramidDesc.sRGB = false;
depthPyramidDesc.enableRandomWrite = true;
depthPyramidDesc.useMipMap = false;
cmd.GetTemporaryRT(m_DepthPyramidMips[0], depthPyramidDesc, FilterMode.Bilinear);
m_GPUCopy.SampleCopyChannel_xyzw2x(cmd, depthTexture, m_DepthPyramidMips[0], new Vector2(depthPyramidDesc.width, depthPyramidDesc.height));
cmd.CopyTexture(m_DepthPyramidMips[0], 0, 0, targetTexture, 0, 0);
for (var i = 0; i < lodCount; i++)
{
var srcMipWidth = depthPyramidDesc.width;
var srcMipHeight = depthPyramidDesc.height;
depthPyramidDesc.width = srcMipWidth >> 1;
depthPyramidDesc.height = srcMipHeight >> 1;
var kernel = m_DepthPyramidKernel_8;
var kernelBlockSize = 8f;
if (depthPyramidDesc.width < 4 * k_DepthBlockSize
|| depthPyramidDesc.height < 4 * k_DepthBlockSize)
{
kernel = m_DepthPyramidKernel_1;
kernelBlockSize = 1;
}
cmd.ReleaseTemporaryRT(m_DepthPyramidMips[i + 1]);
cmd.GetTemporaryRT(m_DepthPyramidMips[i + 1], depthPyramidDesc, FilterMode.Bilinear);
cmd.SetComputeTextureParam(m_DepthPyramidCS, kernel, _Source, m_DepthPyramidMips[i]);
cmd.SetComputeTextureParam(m_DepthPyramidCS, kernel, _Result, m_DepthPyramidMips[i + 1]);
cmd.SetComputeVectorParam(m_DepthPyramidCS, _SrcSize, new Vector4(srcMipWidth, srcMipHeight, 1f / srcMipWidth, 1f / srcMipHeight));
cmd.DispatchCompute(
m_DepthPyramidCS,
kernel,
Mathf.CeilToInt(depthPyramidDesc.width / kernelBlockSize),
Mathf.CeilToInt(depthPyramidDesc.height / kernelBlockSize),
1);
cmd.CopyTexture(m_DepthPyramidMips[i + 1], 0, 0, targetTexture, 0, i + 1);
}
for (int i = 0; i < lodCount + 1; i++)
cmd.ReleaseTemporaryRT(m_DepthPyramidMips[i]);
}
public void RenderColorPyramid(
HDCamera hdCamera,
CommandBuffer cmd,
ScriptableRenderContext renderContext,
RenderTargetIdentifier colorTexture,
RenderTargetIdentifier targetTexture)
{
var colorPyramidDesc = colorRenderTextureDescriptor;
var lodCount = colorBufferMipMapCount;
if (lodCount > m_ColorPyramidMips.Length)
{
Debug.LogWarningFormat("Cannot compute all mipmaps of the color pyramid, max texture size supported: {0}", (2 << m_ColorPyramidMips.Length).ToString());
lodCount = m_ColorPyramidMips.Length;
}
// Copy mip 0
cmd.CopyTexture(colorTexture, 0, 0, targetTexture, 0, 0);
var last = colorTexture;
colorPyramidDesc.sRGB = false;
colorPyramidDesc.enableRandomWrite = true;
colorPyramidDesc.useMipMap = false;
for (var i = 0; i < lodCount; i++)
{
colorPyramidDesc.width = colorPyramidDesc.width >> 1;
colorPyramidDesc.height = colorPyramidDesc.height >> 1;
// TODO: Add proper stereo support to the compute job
cmd.ReleaseTemporaryRT(m_ColorPyramidMips[i + 1]);
cmd.GetTemporaryRT(m_ColorPyramidMips[i + 1], colorPyramidDesc, FilterMode.Bilinear);
cmd.SetComputeTextureParam(m_ColorPyramidCS, m_ColorPyramidKernel, _Source, last);
cmd.SetComputeTextureParam(m_ColorPyramidCS, m_ColorPyramidKernel, _Result, m_ColorPyramidMips[i + 1]);
cmd.SetComputeVectorParam(m_ColorPyramidCS, _Size, new Vector4(colorPyramidDesc.width, colorPyramidDesc.height, 1f / colorPyramidDesc.width, 1f / colorPyramidDesc.height));
cmd.DispatchCompute(
m_ColorPyramidCS,
m_ColorPyramidKernel,
Mathf.CeilToInt(colorPyramidDesc.width / 8f),
Mathf.CeilToInt(colorPyramidDesc.height / 8f),
1);
cmd.CopyTexture(m_ColorPyramidMips[i + 1], 0, 0, targetTexture, 0, i + 1);
last = m_ColorPyramidMips[i + 1];
}
for (int i = 0; i < lodCount; i++)
cmd.ReleaseTemporaryRT(m_ColorPyramidMips[i + 1]);
}
public void Initialize(HDCamera hdCamera, bool enableStereo)
{
var colorDesc = CalculateRenderTextureDescriptor(hdCamera, enableStereo);
colorDesc.colorFormat = RenderTextureFormat.ARGBHalf;
m_ColorRenderTextureDescriptor = colorDesc;
var depthDesc = CalculateRenderTextureDescriptor(hdCamera, enableStereo);
depthDesc.colorFormat = RenderTextureFormat.RFloat;
m_DepthRenderTextureDescriptor = depthDesc;
}
public static RenderTextureDescriptor CalculateRenderTextureDescriptor(HDCamera hdCamera, bool enableStereo)
{
var desc = hdCamera.renderTextureDesc;
desc.depthBufferBits = 0;
desc.useMipMap = true;
desc.autoGenerateMips = false;
desc.msaaSamples = 1; // These are approximation textures, they don't need MSAA
// for stereo double-wide, each half of the texture will represent a single eye's pyramid
//var widthModifier = 1;
//if (stereoEnabled && (desc.dimension != TextureDimension.Tex2DArray))
// widthModifier = 2; // double-wide
//desc.width = pyramidSize * widthModifier;
desc.width = (int)hdCamera.screenSize.x;
desc.height = (int)hdCamera.screenSize.y;
return desc;
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/DepthPyramid.cs.meta


fileFormatVersion: 2
guid: ecd07105781bbbf41b8918c61197d1e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

96
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/ColorPyramid.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
class ColorPyramid
{
static readonly int _Size = Shader.PropertyToID("_Size");
static readonly int _Source = Shader.PropertyToID("_Source");
static readonly int _Result = Shader.PropertyToID("_Result");
ComputeShader m_ColorPyramidCS;
RenderTextureDescriptor m_RenderTextureDescriptor;
int[] m_ColorPyramidMips = new int[0];
int m_ColorPyramidKernel;
public RenderTextureDescriptor renderTextureDescriptor { get { return m_RenderTextureDescriptor; } }
public int usedMipMapCount { get { return Mathf.Min(bufferMipMapCount, m_ColorPyramidMips.Length); } }
public int bufferMipMapCount
{
get
{
var minSize = Mathf.Min(renderTextureDescriptor.width, renderTextureDescriptor.height);
return Mathf.FloorToInt(Mathf.Log(minSize, 2f));
}
}
public ColorPyramid(ComputeShader colorPyramidCS, int[] mipIds)
{
m_ColorPyramidCS = colorPyramidCS;
m_ColorPyramidKernel = m_ColorPyramidCS.FindKernel("KMain");
m_ColorPyramidMips = mipIds;
}
public void RenderPyramidColor(
HDCamera hdCamera,
CommandBuffer cmd,
ScriptableRenderContext renderContext,
RenderTargetIdentifier colorTexture,
RenderTargetIdentifier targetTexture)
{
var colorPyramidDesc = renderTextureDescriptor;
var lodCount = bufferMipMapCount;
if (lodCount > m_ColorPyramidMips.Length)
{
Debug.LogWarningFormat("Cannot compute all mipmaps of the color pyramid, max texture size supported: {0}", (2 << m_ColorPyramidMips.Length).ToString());
lodCount = m_ColorPyramidMips.Length;
}
// Copy mip 0
cmd.CopyTexture(colorTexture, 0, 0, targetTexture, 0, 0);
var last = colorTexture;
colorPyramidDesc.sRGB = false;
colorPyramidDesc.enableRandomWrite = true;
colorPyramidDesc.useMipMap = false;
for (var i = 0; i < lodCount; i++)
{
colorPyramidDesc.width = colorPyramidDesc.width >> 1;
colorPyramidDesc.height = colorPyramidDesc.height >> 1;
// TODO: Add proper stereo support to the compute job
cmd.ReleaseTemporaryRT(m_ColorPyramidMips[i + 1]);
cmd.GetTemporaryRT(m_ColorPyramidMips[i + 1], colorPyramidDesc, FilterMode.Bilinear);
cmd.SetComputeTextureParam(m_ColorPyramidCS, m_ColorPyramidKernel, _Source, last);
cmd.SetComputeTextureParam(m_ColorPyramidCS, m_ColorPyramidKernel, _Result, m_ColorPyramidMips[i + 1]);
cmd.SetComputeVectorParam(m_ColorPyramidCS, _Size, new Vector4(colorPyramidDesc.width, colorPyramidDesc.height, 1f / colorPyramidDesc.width, 1f / colorPyramidDesc.height));
cmd.DispatchCompute(
m_ColorPyramidCS,
m_ColorPyramidKernel,
Mathf.CeilToInt(colorPyramidDesc.width / 8f),
Mathf.CeilToInt(colorPyramidDesc.height / 8f),
1);
cmd.CopyTexture(m_ColorPyramidMips[i + 1], 0, 0, targetTexture, 0, i + 1);
last = m_ColorPyramidMips[i + 1];
}
for (int i = 0; i < lodCount; i++)
cmd.ReleaseTemporaryRT(m_ColorPyramidMips[i + 1]);
}
public void Initialize(HDCamera hdCamera, bool enableStereo)
{
var desc = PyramidUtils.CalculateRenderTextureDescriptor(hdCamera, enableStereo);
desc.colorFormat = RenderTextureFormat.ARGBHalf;
m_RenderTextureDescriptor = desc;
}
}
}

110
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/DepthPyramid.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
class DepthPyramid
{
const int k_DepthBlockSize = 4;
ComputeShader m_DepthPyramidCS;
GPUCopy m_GPUCopy;
RenderTextureDescriptor m_RenderTextureDescriptor;
int[] m_DepthPyramidMips = new int[0];
int m_DepthPyramidKernel_8;
int m_DepthPyramidKernel_1;
public RenderTextureDescriptor renderTextureDescriptor { get { return m_RenderTextureDescriptor; } }
public int usedMipMapCount { get { return Mathf.Min(bufferMipMapCount, m_DepthPyramidMips.Length); } }
public int bufferMipMapCount
{
get
{
var minSize = Mathf.Min(renderTextureDescriptor.width, renderTextureDescriptor.height);
return Mathf.FloorToInt(Mathf.Log(minSize, 2f));
}
}
public DepthPyramid(ComputeShader depthPyramidCS, GPUCopy gpuCopy, int[] mipIds)
{
m_DepthPyramidCS = depthPyramidCS;
m_GPUCopy = gpuCopy;
m_DepthPyramidKernel_8 = m_DepthPyramidCS.FindKernel("KMain_8");
m_DepthPyramidKernel_1 = m_DepthPyramidCS.FindKernel("KMain_1");
m_DepthPyramidMips = mipIds;
}
public void RenderPyramidDepth(
HDCamera hdCamera,
CommandBuffer cmd,
ScriptableRenderContext renderContext,
RenderTargetIdentifier depthTexture,
RenderTargetIdentifier targetTexture)
{
var depthPyramidDesc = m_RenderTextureDescriptor;
var lodCount = bufferMipMapCount;
if (lodCount > m_DepthPyramidMips.Length)
{
Debug.LogWarningFormat("Cannot compute all mipmaps of the depth pyramid, max texture size supported: {0}", (2 << m_DepthPyramidMips.Length).ToString());
lodCount = m_DepthPyramidMips.Length;
}
cmd.ReleaseTemporaryRT(m_DepthPyramidMips[0]);
depthPyramidDesc.sRGB = false;
depthPyramidDesc.enableRandomWrite = true;
depthPyramidDesc.useMipMap = false;
cmd.GetTemporaryRT(m_DepthPyramidMips[0], depthPyramidDesc, FilterMode.Bilinear);
m_GPUCopy.SampleCopyChannel_xyzw2x(cmd, depthTexture, m_DepthPyramidMips[0], new Vector2(depthPyramidDesc.width, depthPyramidDesc.height));
cmd.CopyTexture(m_DepthPyramidMips[0], 0, 0, targetTexture, 0, 0);
for (var i = 0; i < lodCount; i++)
{
var srcMipWidth = depthPyramidDesc.width;
var srcMipHeight = depthPyramidDesc.height;
depthPyramidDesc.width = srcMipWidth >> 1;
depthPyramidDesc.height = srcMipHeight >> 1;
var kernel = m_DepthPyramidKernel_8;
var kernelBlockSize = 8f;
if (depthPyramidDesc.width < 4 * k_DepthBlockSize
|| depthPyramidDesc.height < 4 * k_DepthBlockSize)
{
kernel = m_DepthPyramidKernel_1;
kernelBlockSize = 1;
}
cmd.ReleaseTemporaryRT(m_DepthPyramidMips[i + 1]);
cmd.GetTemporaryRT(m_DepthPyramidMips[i + 1], depthPyramidDesc, FilterMode.Bilinear);
cmd.SetComputeTextureParam(m_DepthPyramidCS, kernel, "_Source", m_DepthPyramidMips[i]);
cmd.SetComputeTextureParam(m_DepthPyramidCS, kernel, "_Result", m_DepthPyramidMips[i + 1]);
cmd.SetComputeVectorParam(m_DepthPyramidCS, "_SrcSize", new Vector4(srcMipWidth, srcMipHeight, 1f / srcMipWidth, 1f / srcMipHeight));
cmd.DispatchCompute(
m_DepthPyramidCS,
kernel,
Mathf.CeilToInt(depthPyramidDesc.width / kernelBlockSize),
Mathf.CeilToInt(depthPyramidDesc.height / kernelBlockSize),
1);
cmd.CopyTexture(m_DepthPyramidMips[i + 1], 0, 0, targetTexture, 0, i + 1);
}
for (int i = 0; i < lodCount + 1; i++)
cmd.ReleaseTemporaryRT(m_DepthPyramidMips[i]);
}
public void Initialize(HDCamera hdCamera, bool enableStereo)
{
var desc = PyramidUtils.CalculateRenderTextureDescriptor(hdCamera, enableStereo);
desc.colorFormat = RenderTextureFormat.RFloat;
m_RenderTextureDescriptor = desc;
}
}
}

26
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/PyramidUtils.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public static class PyramidUtils
{
public static RenderTextureDescriptor CalculateRenderTextureDescriptor(HDCamera hdCamera, bool enableStereo)
{
var desc = hdCamera.renderTextureDesc;
desc.depthBufferBits = 0;
desc.useMipMap = true;
desc.autoGenerateMips = false;
desc.msaaSamples = 1; // These are approximation textures, they don't need MSAA
// for stereo double-wide, each half of the texture will represent a single eye's pyramid
//var widthModifier = 1;
//if (stereoEnabled && (desc.dimension != TextureDimension.Tex2DArray))
// widthModifier = 2; // double-wide
//desc.width = pyramidSize * widthModifier;
desc.width = (int)hdCamera.screenSize.x;
desc.height = (int)hdCamera.screenSize.y;
return desc;
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/PyramidUtils.cs.meta


fileFormatVersion: 2
guid: 6f9fc7344710a1b40ac3659f2fcc5130
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/ColorPyramid.cs.meta → /ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs.meta

正在加载...
取消
保存