浏览代码

[PyramidBuffer] use screen size for depth pyramid

/feature-ScreenSpaceProjection
Frédéric Vauchelles 7 年前
当前提交
eba4a6c3
共有 3 个文件被更改,包括 52 次插入14 次删除
  1. 15
      ScriptableRenderPipeline/Core/CoreRP/Debugging/DebugItemHandler.cs
  2. 24
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  3. 27
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs

15
ScriptableRenderPipeline/Core/CoreRP/Debugging/DebugItemHandler.cs


{
protected uint m_Min = 0;
protected uint m_Max = 1;
protected Func<uint> m_MinGetter = null;
protected Func<uint> m_MaxGetter = null;
public uint min { get { return m_MinGetter != null ? m_MinGetter() : m_Min; } }
public uint max { get { return m_MaxGetter != null ? m_MaxGetter() : m_Max; } }
public DebugItemHandlerUIntMinMax(uint min, uint max)
{

public DebugItemHandlerUIntMinMax(Func<uint> minGetter, Func<uint> maxGetter)
{
m_MinGetter = minGetter;
m_MaxGetter = maxGetter;
}
setter(Math.Min(m_Max, Math.Max(m_Min, (uint)getter())));
setter(Math.Min(max, Math.Max(min, (uint)getter())));
}
#if UNITY_EDITOR

EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntSlider(m_DebugItem.name, (int)(uint)m_DebugItem.GetValue(), (int)m_Min, (int)m_Max);
int value = EditorGUILayout.IntSlider(m_DebugItem.name, (int)(uint)m_DebugItem.GetValue(), (int)min, (int)max);
if (EditorGUI.EndChangeCheck())
{
m_DebugItem.SetValue((uint)value);

24
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs


DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kShadowMinValueDebug, () => lightingDebugSettings.shadowMinValue, (value) => lightingDebugSettings.shadowMinValue = (float)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kShadowMaxValueDebug, () => lightingDebugSettings.shadowMaxValue, (value) => lightingDebugSettings.shadowMaxValue = (float)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, int>(kFullScreenDebugMode, () => (int)fullScreenDebugMode, (value) => fullScreenDebugMode = (FullScreenDebugMode)value, DebugItemFlag.None, new DebugItemHandlerIntEnum(DebugDisplaySettings.lightingFullScreenDebugStrings, DebugDisplaySettings.lightingFullScreenDebugValues));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kFullScreenDebugMip, () => fullscreenDebugMip, value => fullscreenDebugMip = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0f, 1f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(
kFullScreenDebugMip,
() =>
{
var depthSize = Shader.GetGlobalVector(HDShaderIDs._DepthPyramidMipSize);
var lodCount = Mathf.FloorToInt(Mathf.Log(Mathf.Min(depthSize.x, depthSize.y), 2f));
return (uint)(fullscreenDebugMip * lodCount);
},
value =>
{
var depthSize = Shader.GetGlobalVector(HDShaderIDs._DepthPyramidMipSize);
var lodCount = Mathf.Floor(Mathf.Log(Mathf.Min(depthSize.x, depthSize.y), 2f));
fullscreenDebugMip = (float)Convert.ChangeType(value, typeof(Single)) / lodCount;
},
DebugItemFlag.None,
new DebugItemHandlerUIntMinMax(() => 0,
() =>
{
var depthSize = Shader.GetGlobalVector(HDShaderIDs._DepthPyramidMipSize);
var lodCount = Mathf.FloorToInt(Mathf.Log(Mathf.Min(depthSize.x, depthSize.y), 2f));
return (uint)lodCount;
})
);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, DebugLightingMode>(kLightingDebugMode, () => lightingDebugSettings.debugLightingMode, (value) => SetDebugLightingMode((DebugLightingMode)value));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kOverrideSmoothnessDebug, () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kOverrideSmoothnessValueDebug, () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));

27
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


using (new ProfilingSample(cmd, "Pyramid Depth", CustomSamplerId.PyramidDepth.GetSampler()))
{
var depthPyramidDesc = m_DepthPyramidBufferDesc;
var pyramidSideSize = GetPyramidSize(depthPyramidDesc);
var minSize = Mathf.Min(depthPyramidDesc.width, depthPyramidDesc.height);
// The gaussian pyramid compute works in blocks of 8x8 so make sure the last lod has a
// minimum size of 8x8
int lodCount = Mathf.FloorToInt(Mathf.Log(pyramidSideSize, 2f) - 3f);
var lodCount = Mathf.FloorToInt(Mathf.Log(minSize, 2f));
if (lodCount > HDShaderIDs._DepthPyramidMips.Length)
{
Debug.LogWarningFormat("Cannot compute all mipmaps of the depth pyramid, max texture size supported: {0}", (2 << HDShaderIDs._DepthPyramidMips.Length).ToString());

cmd.SetGlobalVector(HDShaderIDs._DepthPyramidMipSize, new Vector4(pyramidSideSize, pyramidSideSize, lodCount, 0));
cmd.SetGlobalVector(HDShaderIDs._DepthPyramidMipSize, new Vector4(depthPyramidDesc.width, depthPyramidDesc.height, lodCount, 0));
cmd.ReleaseTemporaryRT(HDShaderIDs._DepthPyramidMips[0]);

m_GPUCopy.SampleCopyChannel_xyzw2x(cmd, GetDepthTexture(), HDShaderIDs._DepthPyramidMips[0], new Vector2(depthPyramidDesc.width, depthPyramidDesc.height));
cmd.CopyTexture(HDShaderIDs._DepthPyramidMips[0], 0, 0, m_DepthPyramidBufferRT, 0, 0);
for (int i = 0; i < lodCount; i++)
for (var i = 0; i < lodCount; i++)
//var sourceTarget = i == 0
// ? m_DepthPyramidBufferRT
// : HDShaderIDs._DepthPyramidMips[i];
var srcMipWidth = depthPyramidDesc.width;
var srcMipHeight = depthPyramidDesc.height;
depthPyramidDesc.width = srcMipWidth >> 1;

cmd.SetComputeTextureParam(m_DepthPyramidCS, m_DepthPyramidKernel, "_Result", HDShaderIDs._DepthPyramidMips[i + 1]);
cmd.SetComputeVectorParam(m_DepthPyramidCS, "_SrcSize", new Vector4(srcMipWidth, srcMipHeight, 1f / srcMipWidth, 1f / srcMipHeight));
cmd.DispatchCompute(m_DepthPyramidCS, m_DepthPyramidKernel, depthPyramidDesc.width / 8, depthPyramidDesc.height / 8, 1);
cmd.DispatchCompute(
m_DepthPyramidCS,
m_DepthPyramidKernel,
Mathf.CeilToInt(depthPyramidDesc.width / 8f),
Mathf.CeilToInt(depthPyramidDesc.height / 8f),
1);
cmd.CopyTexture(HDShaderIDs._DepthPyramidMips[i + 1], 0, 0, m_DepthPyramidBufferRT, 0, i + 1);
}

desc.msaaSamples = 1; // These are approximation textures, they don't need MSAA
var pyramidSize = CalculatePyramidSize((int)hdCamera.screenSize.x, (int)hdCamera.screenSize.y);
// 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))

desc.width = pyramidSize;
desc.height = pyramidSize;
desc.width = (int)hdCamera.screenSize.x;
desc.height = (int)hdCamera.screenSize.y;
return desc;
}
正在加载...
取消
保存