浏览代码

Output HTile via a pixel shader

/RenderPassXR_Sandbox
Evgenii Golubev 7 年前
当前提交
2c8fcff2
共有 5 个文件被更改,包括 67 次插入5 次删除
  1. 59
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CopyStencilBuffer.shader
  3. 1
      Assets/ScriptableRenderPipeline/ShaderLibrary/API/D3D11.hlsl
  4. 1
      Assets/ScriptableRenderPipeline/ShaderLibrary/API/Metal.hlsl
  5. 1
      Assets/ScriptableRenderPipeline/ShaderLibrary/API/PSSL.hlsl

59
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


private RenderTexture m_CameraDepthStencilBuffer = null;
private RenderTexture m_CameraDepthBufferCopy = null;
private RenderTexture m_CameraStencilBufferCopy = null; // Currently, it's manually copied using a pixel shader, and optimized to only contain the SSS bit
private RenderTexture m_HTile = null; // If the hardware does not expose it, we compute our own, optimized to only contain the SSS bit
private RenderTargetIdentifier m_HTileRT;
// Post-processing context and screen-space effects (recycled on every frame to avoid GC alloc)
readonly PostProcessRenderContext m_PostProcessContext;

{
m_CameraStencilBufferCopy.Release();
}
m_CameraStencilBufferCopy = new RenderTexture(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.R8);
m_CameraStencilBufferCopy = new RenderTexture(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.R8); // DXGI_FORMAT_R8_UINT is not supported by Unity
}
if (NeedHTileCopy())
{
if (m_HTile!= null)
{
m_HTile.Release();
}
// We use 8x8 tiles in order to match the native GCN HTile as closely as possible.
m_HTile = new RenderTexture((camera.pixelWidth + 7) / 8, (camera.pixelHeight + 7) / 8, 0, RenderTextureFormat.R8); // DXGI_FORMAT_R8_UINT is not supported by Unity
m_HTile.filterMode = FilterMode.Point;
m_HTile.enableRandomWrite = true;
m_HTile.Create();
m_HTileRT = new RenderTargetIdentifier(m_HTile);
}
}

return m_DebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission;
}
bool NeedHTileCopy()
{
// Currently, Unity does not offer a way to access the GCN HTile even on PS4 and Xbox One.
// Therefore, it's computed in a pixel shader, and optimized to only contain the SSS bit.
return NeedStencilBufferCopy();
}
RenderTargetIdentifier GetDepthTexture()
{
return NeedDepthBufferCopy() ? m_CameraDepthBufferCopy : m_CameraDepthStencilBuffer;

return NeedStencilBufferCopy() ? m_CameraStencilBufferCopyRT : m_CameraDepthStencilBufferRT;
}
RenderTargetIdentifier GetHTile()
{
// Currently, Unity does not offer a way to access the GCN HTile.
return m_HTileRT;
}
private void CopyDepthBufferIfNeeded(CommandBuffer cmd)
{
using (new Utilities.ProfilingSample(NeedDepthBufferCopy() ? "Copy DepthBuffer" : "Set DepthBuffer", cmd))

{
using (new Utilities.ProfilingSample("Copy StencilBuffer", cmd))
{
cmd.SetRandomWriteTarget(1, GetHTile());
cmd.ClearRandomWriteTargets();
cmd.SetGlobalTexture("_HTile", GetHTile());
cmd.SetGlobalTexture("_StencilTexture", GetStencilTexture());
}

}
// Old SSS Model >>>
// Clear the SSS filtering target
using (new Utilities.ProfilingSample("Clear SSS filtering target", cmd))
if (!sssSettings.useDisneySSS)
Utilities.SetRenderTarget(cmd, m_CameraFilteringBuffer, m_CameraDepthStencilBufferRT, ClearFlag.ClearColor, Color.black);
// Clear the SSS filtering target
using (new Utilities.ProfilingSample("Clear SSS filtering target", cmd))
{
Utilities.SetRenderTarget(cmd, m_CameraFilteringBuffer, m_CameraDepthStencilBufferRT, ClearFlag.ClearColor, Color.black);
}
if (NeedStencilBufferCopy())
{
using (new Utilities.ProfilingSample("Clear stencil texture", cmd))
{
Utilities.SetRenderTarget(cmd, m_CameraStencilBufferCopyRT, ClearFlag.ClearColor, Color.black);
}
}
if (NeedHTileCopy())
{
using (new Utilities.ProfilingSample("Clear HTile", cmd))
{
Utilities.SetRenderTarget(cmd, m_HTileRT, ClearFlag.ClearColor, Color.black);
}
}
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CopyStencilBuffer.shader


#include "../../../ShaderVariables.hlsl"
#include "../../../Lighting/LightDefinition.cs.hlsl"
RW_TEXTURE2D(float, _HTile) : register(u1); // DXGI_FORMAT_R8_UINT is not supported by Unity
struct Attributes
{
uint vertexID : SV_VertexID;

return output;
}
// Should use HiS and therefore be faster than a GPU memcpy().
// Force the stencil test before the UAV write.
[earlydepthstencil]
uint2 positionSS = (uint2)input.positionCS.xy;
// There's no need for atomics as we are always writing the same value.
_HTile[positionSS / 8] = STENCILLIGHTINGUSAGE_SPLIT_LIGHTING;
return float4(STENCILLIGHTINGUSAGE_SPLIT_LIGHTING, 0, 0, 0);
}
ENDHLSL

1
Assets/ScriptableRenderPipeline/ShaderLibrary/API/D3D11.hlsl


#define TEXTURECUBE(textureName) TextureCube textureName
#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName
#define TEXTURE3D(textureName) Texture3D textureName
#define RW_TEXTURE2D(type, textureName) RWTexture2D<type> textureName
#define SAMPLER2D(samplerName) SamplerState samplerName
#define SAMPLERCUBE(samplerName) SamplerState samplerName

1
Assets/ScriptableRenderPipeline/ShaderLibrary/API/Metal.hlsl


#define TEXTURECUBE(textureName) TextureCube textureName
#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName
#define TEXTURE3D(textureName) Texture3D textureName
#define RW_TEXTURE2D(type, textureName) RWTexture2D<type> textureName
#define SAMPLER2D(samplerName) SamplerState samplerName
#define SAMPLERCUBE(samplerName) SamplerState samplerName

1
Assets/ScriptableRenderPipeline/ShaderLibrary/API/PSSL.hlsl


#define TEXTURECUBE(textureName) TextureCube textureName
#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName
#define TEXTURE3D(textureName) Texture3D textureName
#define RW_TEXTURE2D(type, textureName) RWTexture2D<type> textureName
#define SAMPLER2D(samplerName) SamplerState samplerName
#define SAMPLERCUBE(samplerName) SamplerState samplerName

正在加载...
取消
保存