浏览代码

Prelim work on pyramid generation

I need to fix the size and some of the compute work when generating the gaussian pyramids
/xr-hdrp-pyramids
Robert Srinivasiah 6 年前
当前提交
86c87d66
共有 3 个文件被更改,包括 37 次插入9 次删除
  1. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  3. 40
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


void RenderPyramidDepth(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
{
if (!m_FrameSettings.enableRoughRefraction)
return;
//if (!m_FrameSettings.enableRoughRefraction)
// return;
using (new ProfilingSample(cmd, "Pyramid Depth", CustomSamplerId.PyramidDepth.GetSampler()))
m_BufferPyramid.RenderDepthPyramid(hdCamera, cmd, renderContext, GetDepthTexture());

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


uint2 depthSize = uint2(_PyramidDepthMipSize.xy);
// Get the depth of the approximated back plane
// XRTODO: Correct for stereo? I don't think we correct NDC or SS anywhere
float pyramidDepth = LOAD_TEXTURE2D_LOD(_PyramidDepthTexture, posInputs.positionNDC * (depthSize >> 2), 2).r;
float depth = LinearEyeDepth(pyramidDepth, _ZBufferParams);

// Calculate screen space coordinates of refracted point in back plane
float2 refractedBackPointNDC = ComputeNormalizedDeviceCoordinates(refractedBackPointWS, UNITY_MATRIX_VP);
uint2 depthSize = uint2(_PyramidDepthMipSize.xy);
// XRTODO: Fix this coordinate for stereo
float refractedBackPointDepth = LinearEyeDepth(LOAD_TEXTURE2D_LOD(_PyramidDepthTexture, refractedBackPointNDC * depthSize, 0).r, _ZBufferParams);
// Exit if texel is out of color buffer

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


// Instead of using the screen size, we round up to the next power of 2 because currently some platforms don't support NPOT Render Texture with mip maps (PS4 for example)
// Then we render in a Screen Sized viewport.
// Note that even if PS4 supported POT Mips, the buffers would be padded to the next power of 2 anyway (TODO: check with other platforms...)
// XRTODO: XR can double the width just fine, still POT
int pyramidSize = (int)Mathf.NextPowerOfTwo(Mathf.Max(size.x, size.y));
return new Vector2Int((int)(pyramidSize * GetXRscale()), pyramidSize);
}

{
for (int i = currentLodCount; i < lodCount; ++i)
{
// XRTODO: CalculatePyramidMipSize is passed in as the lambda to Alloc, and then Alloc
// provides the size to CalculatePyramidMipSize. CalculatePyramidMipSize is also stashed
// as the scaler method
int mipIndexCopy = i + 1; // Don't remove this copy! It's important for the value to be correctly captured by the lambda.
RTHandle newMip = RTHandle.Alloc(size => CalculatePyramidMipSize(CalculatePyramidSize(size), mipIndexCopy), colorFormat: format, sRGB: false, enableRandomWrite: true, useMipMap: false, filterMode: FilterMode.Bilinear, name: string.Format("PyramidMip{0}", i));
mipList.Add(newMip);

public Vector2 GetPyramidToScreenScale(HDCamera camera)
{
return new Vector2((float)camera.actualWidth / m_DepthPyramidBuffer.rt.width, (float)camera.actualHeight / m_DepthPyramidBuffer.rt.height);
//return new Vector2((float)camera.actualWidth / m_DepthPyramidBuffer.rt.width, (float)camera.actualHeight / m_DepthPyramidBuffer.rt.height);
return new Vector2((float)camera.screenSize.x / m_DepthPyramidBuffer.rt.width, (float)camera.screenSize.y / m_DepthPyramidBuffer.rt.height);
}
public void RenderDepthPyramid(

RTHandle depthTexture)
{
int lodCount = GetPyramidLodCount(hdCamera);
// XRINFO: Allocate list of handles for mip levels
cmd.SetGlobalVector(HDShaderIDs._DepthPyramidMipSize, new Vector4(hdCamera.actualWidth, hdCamera.actualHeight, lodCount, 0.0f));
// XRTODO: Use actual or screen size?
// used in lighting too!
// This should probably be set to the single-eye...?
//cmd.SetGlobalVector(HDShaderIDs._DepthPyramidMipSize, new Vector4(hdCamera.actualWidth, hdCamera.actualHeight, lodCount, 0.0f));
cmd.SetGlobalVector(HDShaderIDs._DepthPyramidMipSize, new Vector4(hdCamera.screenSize.x, hdCamera.screenSize.y, lodCount, 0.0f));
// XRTODO: Since this is an unfiltered load copy, might not need to stereo-ize for double-wide.
// Texture array will need to be fixed up though. Maybe do it per slice?
// XRINFO: I don't know if this is right scale to set up...
// I think it should be single eye screen against entire texture
Vector2 scale = GetPyramidToScreenScale(hdCamera);
RTHandle src = m_DepthPyramidBuffer;

var srcMipWidth = hdCamera.actualWidth >> i;
var srcMipHeight = hdCamera.actualHeight >> i;
//var srcMipWidth = hdCamera.actualWidth >> i;
//var srcMipHeight = hdCamera.actualHeight >> i;
// XRTODO: Fix for stereo
var srcMipWidth = ((int)hdCamera.screenSize.x) >> i;
var srcMipHeight = ((int)hdCamera.screenSize.y) >> i;
var dstMipWidth = srcMipWidth >> 1;
var dstMipHeight = srcMipHeight >> 1;

cmd.SetComputeTextureParam(m_DepthPyramidCS, kernel, _Result, dest);
cmd.SetComputeVectorParam(m_DepthPyramidCS, _SrcSize, new Vector4(srcMipWidth, srcMipHeight, (1.0f / srcMipWidth) * scale.x, (1.0f / srcMipHeight) * scale.y));
// XRTODO: This might actually need to be stereo-ized properly, because it does some manual filtering on the downsample
// We don't want to have incorrect calculations at the middle eye boundary
// XRTODO: Get framesettings, I am cheating
var stereoEnabled = (m_DepthPyramidBuffer.rt.descriptor.vrUsage == VRTextureUsage.TwoEyes);
var tgZ = stereoEnabled ? 2 : 1;
1);
tgZ);
//1);
// If we could bind texture mips as UAV we could avoid this copy...(which moreover copies more than the needed viewport if not fullscreen)
cmd.CopyTexture(m_DepthPyramidMips[i], 0, 0, 0, 0, dstMipWidth, dstMipHeight, m_DepthPyramidBuffer, 0, i + 1, 0, 0);
// XRNOTE: This just works for double-wide
// If we could bind texture mips as UAV we could avoid this copy...(which moreover copies more than the needed viewport if not fullscreen)
cmd.CopyTexture(m_DepthPyramidMips[i], 0, 0, 0, 0, dstMipWidth, dstMipHeight, m_DepthPyramidBuffer, 0, i + 1, 0, 0);
// XRTODO: where does depth pyramid size get set?
cmd.SetGlobalTexture(HDShaderIDs._PyramidDepthTexture, m_DepthPyramidBuffer);
}

正在加载...
取消
保存