浏览代码

Do the color pyramid in a separate buffer

/main
Thomas 6 年前
当前提交
e7f10913
共有 6 个文件被更改,包括 73 次插入42 次删除
  1. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/PlanarReflectionProbeCache.cs
  2. 5
      com.unity.render-pipelines.high-definition/HDRP/Material/GGXConvolution/RuntimeFilterIBL.cs
  3. 21
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
  4. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  5. 30
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/ColorPyramid.compute
  6. 56
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/MipGenerator.cs

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/PlanarReflectionProbeCache.cs


m_TempRenderTexture.useMipMap = true;
m_TempRenderTexture.autoGenerateMips = false;
m_TempRenderTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarReflectionTemp", mips: true);
m_TempRenderTexture.enableRandomWrite = true;
m_TempRenderTexture.Create();
m_ConvolutionTargetTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);

m_ConvolutionTargetTexture.autoGenerateMips = false;
m_ConvolutionTargetTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf, "PlanarReflectionConvolution", mips: true);
m_ConvolutionTargetTexture.enableRandomWrite = true;
m_ConvolutionTargetTexture.Create();
InitializeProbeBakingStates();

5
com.unity.render-pipelines.high-definition/HDRP/Material/GGXConvolution/RuntimeFilterIBL.cs


FilterCubemapCommon(cmd, source, target, m_faceWorldToViewMatrixMatrices);
}
public void FilterPlanarTexture(CommandBuffer cmd, Texture source, RenderTexture target)
public void FilterPlanarTexture(CommandBuffer cmd, RenderTexture source, RenderTexture target)
cmd.Blit(source, target);
m_MipGenerator.RenderColorGaussianPyramid(cmd, new Vector2Int(source.width, source.height), target);
m_MipGenerator.RenderColorGaussianPyramid(cmd, new Vector2Int(source.width, source.height), source, target);
}
// Filters MIP map levels (other than 0) with GGX using multiple importance sampling.

21
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs


// 'm_CameraColorBuffer' does not contain diffuse lighting of SSS materials until the SSS pass. It is stored within 'm_CameraSssDiffuseLightingBuffer'.
RTHandleSystem.RTHandle m_CameraColorBuffer;
RTHandleSystem.RTHandle m_CameraColorBufferMipChain;
RTHandleSystem.RTHandle m_CameraSssDiffuseLightingBuffer;
RTHandleSystem.RTHandle m_CameraDepthStencilBuffer;

m_SSSBufferManager.InitSSSBuffers(m_GbufferManager, m_Asset.renderPipelineSettings);
m_NormalBufferManager.InitNormalBuffers(m_GbufferManager, m_Asset.renderPipelineSettings);
m_CameraColorBuffer = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGBHalf, sRGB: false, enableRandomWrite: true, enableMSAA: true, useMipMap: true, autoGenerateMips: false, name: "CameraColor");
m_CameraColorBuffer = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGBHalf, sRGB: false, enableRandomWrite: true, enableMSAA: true, useMipMap: false, name: "CameraColor");
m_CameraColorBufferMipChain = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGBHalf, sRGB: false, enableRandomWrite: true, enableMSAA: true, useMipMap: true, autoGenerateMips: false, name: "CameraColorBufferMipChain");
m_CameraSssDiffuseLightingBuffer = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.RGB111110Float, sRGB: false, enableRandomWrite: true, enableMSAA: true, name: "CameraSSSDiffuseLighting");
m_CameraDepthStencilBuffer = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.Depth32, colorFormat: RenderTextureFormat.Depth, filterMode: FilterMode.Point, bindTextureMS: true, enableMSAA: true, name: "CameraDepthStencil");

m_GbufferManager.DestroyBuffers();
m_DbufferManager.DestroyBuffers();
m_BufferPyramid.DestroyBuffers();
RTHandles.Release(m_CameraColorBufferMipChain);
RTHandles.Release(m_CameraSssDiffuseLightingBuffer);
RTHandles.Release(m_CameraDepthStencilBuffer);

);
PushGlobalRTHandle(
cmd,
m_CameraColorBuffer,
m_CameraColorBufferMipChain,
HDShaderIDs._ColorPyramidTexture,
HDShaderIDs._ColorPyramidSize,
HDShaderIDs._ColorPyramidScale

uint x, y, z;
m_applyDistortionCS.GetKernelThreadGroupSizes(m_applyDistortionKernel, out x, out y, out z);
cmd.SetComputeTextureParam(m_applyDistortionCS, m_applyDistortionKernel, HDShaderIDs._DistortionTexture, m_DistortionBuffer);
cmd.SetComputeTextureParam(m_applyDistortionCS, m_applyDistortionKernel, HDShaderIDs._ColorPyramidTexture, m_CameraColorBuffer);
cmd.SetComputeTextureParam(m_applyDistortionCS, m_applyDistortionKernel, HDShaderIDs._ColorPyramidTexture, m_CameraColorBufferMipChain);
cmd.SetComputeTextureParam(m_applyDistortionCS, m_applyDistortionKernel, HDShaderIDs._Destination, m_CameraColorBuffer);
cmd.SetComputeVectorParam(m_applyDistortionCS, HDShaderIDs._Size, size);

using (new ProfilingSample(cmd, "Color Gaussian MIP Chain", CustomSamplerId.ColorPyramid))
{
var size = new Vector2Int(hdCamera.actualWidth, hdCamera.actualHeight);
lodCount = m_MipGenerator.RenderColorGaussianPyramid(cmd, size, m_CameraColorBuffer);
lodCount = m_MipGenerator.RenderColorGaussianPyramid(cmd, size, m_CameraColorBuffer, m_CameraColorBufferMipChain);
float scaleX = hdCamera.actualWidth / (float)m_CameraColorBuffer.rt.width;
float scaleY = hdCamera.actualHeight / (float)m_CameraColorBuffer.rt.height;
cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, m_CameraColorBuffer);
float scaleX = hdCamera.actualWidth / (float)m_CameraColorBufferMipChain.rt.width;
float scaleY = hdCamera.actualHeight / (float)m_CameraColorBufferMipChain.rt.height;
cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, m_CameraColorBufferMipChain);
PushFullScreenDebugTextureMip(hdCamera, cmd, m_CameraColorBuffer, lodCount, new Vector4(scaleX, scaleY, 0f, 0f), isPreRefraction ? FullScreenDebugMode.PreRefractionColorPyramid : FullScreenDebugMode.FinalColorPyramid);
PushFullScreenDebugTextureMip(hdCamera, cmd, m_CameraColorBufferMipChain, lodCount, new Vector4(scaleX, scaleY, 0f, 0f), isPreRefraction ? FullScreenDebugMode.PreRefractionColorPyramid : FullScreenDebugMode.FinalColorPyramid);
}
void RenderDepthPyramid(HDCamera hdCamera, CommandBuffer cmd, FullScreenDebugMode debugMode)

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _Size = Shader.PropertyToID("_Size");
public static readonly int _Source = Shader.PropertyToID("_Source");
public static readonly int _Destination = Shader.PropertyToID("_Destination");
public static readonly int _Mip0 = Shader.PropertyToID("_Mip0");
public static readonly int _AtmosphericScatteringType = Shader.PropertyToID("_AtmosphericScatteringType");
public static readonly int _AmbientProbeCoeffs = Shader.PropertyToID("_AmbientProbeCoeffs");

30
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/ColorPyramid.compute


#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#pragma kernel KColorGaussian KERNEL_SIZE=8 MAIN_GAUSSIAN=KColorGaussian
#pragma kernel KColorDownsample KERNEL_SIZE=8 MAIN_DOWNSAMPLE=KColorDownsample
#pragma kernel KColorGaussian KERNEL_SIZE=8 MAIN_GAUSSIAN=KColorGaussian
#pragma kernel KColorDownsample KERNEL_SIZE=8 MAIN_DOWNSAMPLE=KColorDownsample
#pragma kernel KColorDownsampleCopyMip0 KERNEL_SIZE=8 MAIN_DOWNSAMPLE=KColorDownsampleCopyMip0 COPY_MIP_0
#if COPY_MIP_0
RWTexture2D<float4> _Mip0;
#endif
SamplerState sampler_LinearClamp;

}
[numthreads(KERNEL_SIZE, KERNEL_SIZE, 1)]
void KColorDownsample(uint2 dispatchThreadId : SV_DispatchThreadID)
void MAIN_DOWNSAMPLE(uint2 dispatchThreadId : SV_DispatchThreadID)
float4 p00 = _Source[clamp(offset + uint2(0u, 0u), 0u, size)];
float4 p10 = _Source[clamp(offset + uint2(1u, 0u), 0u, size)];
float4 p11 = _Source[clamp(offset + uint2(1u, 1u), 0u, size)];
float4 p01 = _Source[clamp(offset + uint2(0u, 1u), 0u, size)];
uint2 c00 = clamp(offset + uint2(0u, 0u), 0u, size);
uint2 c10 = clamp(offset + uint2(1u, 0u), 0u, size);
uint2 c11 = clamp(offset + uint2(1u, 1u), 0u, size);
uint2 c01 = clamp(offset + uint2(0u, 1u), 0u, size);
float4 p00 = _Source[c00];
float4 p10 = _Source[c10];
float4 p11 = _Source[c11];
float4 p01 = _Source[c01];
#if COPY_MIP_0
_Mip0[c00] = p00;
_Mip0[c10] = p10;
_Mip0[c11] = p11;
_Mip0[c01] = p01;
#endif
_Destination[dispatchThreadId] = (p00 + p01 + p11 + p10) * 0.25;
}

56
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/MipGenerator.cs


using UnityEngine.Assertions;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline

public class MipGenerator
{
RTHandle m_TempFullscreenTarget;
RTHandle m_TempColorTarget;
ComputeShader m_DepthPyramidCS;
ComputeShader m_ColorPyramidCS;

int m_ColorDownsampleKernelCopyMip0;
int m_ColorGaussianKernel;
public MipGenerator(HDRenderPipelineAsset asset)

m_DepthDownsampleKernel = m_DepthPyramidCS.FindKernel("KDepthDownsample8DualUav");
m_ColorDownsampleKernel = m_ColorPyramidCS.FindKernel("KColorDownsample");
m_ColorDownsampleKernelCopyMip0 = m_ColorPyramidCS.FindKernel("KColorDownsampleCopyMip0");
RTHandles.Release(m_TempFullscreenTarget);
m_TempFullscreenTarget = null;
RTHandles.Release(m_TempColorTarget);
m_TempColorTarget = null;
public int RenderMinDepthPyramid(CommandBuffer cmd, Vector2Int size, RTHandle texture)
public int RenderMinDepthPyramid(CommandBuffer cmd, Vector2Int size, RenderTexture texture)
{
var cs = m_DepthPyramidCS;
int kernel = m_DepthDownsampleKernel;

return srcMipLevel - 1;
}
// Generates an in-place gaussian pyramid
// Generates the gaussian pyramid of source into destination
// We can't do it in place as the color pyramid has to be read while writing to the color
// buffer in some cases (e.g. refraction, distortion)
public int RenderColorGaussianPyramid(CommandBuffer cmd, Vector2Int size, RTHandle texture)
{
return RenderColorGaussianPyramid(cmd, size, texture.rt);
}
// Need this RenderTexture variant because some of the code in HDRP still hasn't switched to
// the RTHandle system :(
public int RenderColorGaussianPyramid(CommandBuffer cmd, Vector2Int size, RenderTexture texture)
public int RenderColorGaussianPyramid(CommandBuffer cmd, Vector2Int size, RenderTexture source, RenderTexture destination)
if (m_TempFullscreenTarget == null)
if (m_TempColorTarget == null)
m_TempFullscreenTarget = RTHandles.Alloc(
m_TempColorTarget = RTHandles.Alloc(
Vector2.one * 0.5f,
filterMode: FilterMode.Bilinear,
colorFormat: RenderTextureFormat.ARGBHalf,

var cs = m_ColorPyramidCS;
int downsampleKernel = m_ColorDownsampleKernel;
int downsampleKernelMip0 = m_ColorDownsampleKernelCopyMip0;
while (srcMipWidth >= 2 || srcMipHeight >= 2)
while (srcMipWidth >= 8 || srcMipHeight >= 8)
cmd.SetComputeTextureParam(cs, downsampleKernel, HDShaderIDs._Source, texture, srcMipLevel);
cmd.SetComputeTextureParam(cs, downsampleKernel, HDShaderIDs._Destination, m_TempFullscreenTarget);
cmd.DispatchCompute(cs, downsampleKernel, (dstMipWidth + 7) / 8, (dstMipHeight + 7) / 8, 1);
// First dispatch also copies src to dst mip0
if (srcMipLevel == 0)
{
cmd.SetComputeTextureParam(cs, downsampleKernelMip0, HDShaderIDs._Source, source, 0);
cmd.SetComputeTextureParam(cs, downsampleKernelMip0, HDShaderIDs._Mip0, destination, 0);
cmd.SetComputeTextureParam(cs, downsampleKernelMip0, HDShaderIDs._Destination, m_TempColorTarget);
cmd.DispatchCompute(cs, downsampleKernelMip0, (dstMipWidth + 7) / 8, (dstMipHeight + 7) / 8, 1);
}
else
{
cmd.SetComputeTextureParam(cs, downsampleKernel, HDShaderIDs._Source, destination, srcMipLevel);
cmd.SetComputeTextureParam(cs, downsampleKernel, HDShaderIDs._Destination, m_TempColorTarget);
cmd.DispatchCompute(cs, downsampleKernel, (dstMipWidth + 7) / 8, (dstMipHeight + 7) / 8, 1);
}
cmd.SetComputeTextureParam(cs, gaussianKernel, HDShaderIDs._Source, m_TempFullscreenTarget);
cmd.SetComputeTextureParam(cs, gaussianKernel, HDShaderIDs._Destination, texture, srcMipLevel + 1);
cmd.SetComputeTextureParam(cs, gaussianKernel, HDShaderIDs._Source, m_TempColorTarget);
cmd.SetComputeTextureParam(cs, gaussianKernel, HDShaderIDs._Destination, destination, srcMipLevel + 1);
cmd.DispatchCompute(cs, gaussianKernel, (dstMipWidth + 7) / 8, (dstMipHeight + 7) / 8, 1);
srcMipLevel++;

正在加载...
取消
保存