浏览代码
Merge pull request #878 from Unity-Technologies/Branch_RTRefactoring
Merge pull request #878 from Unity-Technologies/Branch_RTRefactoring
Refactoring of HDRP render texture usage using RTHandles/main
GitHub
7 年前
当前提交
a6688080
共有 51 个文件被更改,包括 1533 次插入 和 1034 次删除
-
78ScriptableRenderPipeline/Core/CoreRP/CoreUtils.cs
-
466ScriptableRenderPipeline/Core/CoreRP/RTHandle.cs
-
2ScriptableRenderPipeline/Core/CoreRP/Resources/GPUCopy.compute
-
2ScriptableRenderPipeline/Core/CoreRP/Resources/GPUCopyAsset.cs
-
10ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
-
53ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebugPanel.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.cs
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/LightLoopSettingsUI.cs
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/RenderPipelineSettingsUI.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedRenderPipelineSettings.cs
-
5ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDCustomSamplerId.cs
-
688ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset
-
43ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
193ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/DeferredDirectionalShadow.compute
-
80ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopSettings.cs
-
28ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild-clustered.compute
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystemInternal.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Builtin/BuiltinData.cs
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/RenderPipelineMaterial.cs
-
105ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs
-
24ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/RenderPipelineSettings.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/Blit.shader
-
251ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariablesFunctions.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/HDRISky/HDRISkyRenderer.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/ProceduralSky/ProceduralSkyRenderer.cs
-
19ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs
-
77ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyRenderingContext.cs
-
57ScriptableRenderPipeline/HDRenderPipeline/HDRP/MRTBufferManager.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/MRTBufferManager.cs.meta
-
63ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DBufferManager.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DBufferManager.cs.meta
-
71ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/GBufferManager.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/GBufferManager.cs.meta
-
59ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/CopyDepthBuffer.shader
-
9ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/CopyDepthBuffer.shader.meta
688
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public abstract class MRTBufferManager |
|||
{ |
|||
protected int m_BufferCount; |
|||
protected RenderTargetIdentifier[] m_RTIDs; |
|||
protected RTHandle[] m_RTs; |
|||
protected int[] m_TextureShaderIDs; |
|||
|
|||
public int bufferCount { get { return m_BufferCount; } } |
|||
|
|||
public MRTBufferManager(int maxBufferCount) |
|||
{ |
|||
m_BufferCount = maxBufferCount; |
|||
m_RTIDs = new RenderTargetIdentifier[maxBufferCount]; |
|||
m_RTs = new RTHandle[maxBufferCount]; |
|||
m_TextureShaderIDs = new int[maxBufferCount]; |
|||
} |
|||
|
|||
public RenderTargetIdentifier[] GetBuffersRTI() |
|||
{ |
|||
// nameID can change from one frame to another depending on the msaa flag so so we need to update this array to be sure it's up to date.
|
|||
for (int i = 0; i < m_BufferCount; ++i) |
|||
{ |
|||
m_RTIDs[i] = m_RTs[i].nameID; |
|||
} |
|||
return m_RTIDs; |
|||
} |
|||
|
|||
public RTHandle GetBuffer(int index) |
|||
{ |
|||
Debug.Assert(index < m_BufferCount); |
|||
return m_RTs[index]; |
|||
} |
|||
|
|||
public abstract void CreateBuffers(); |
|||
|
|||
public void BindBufferAsTextures(CommandBuffer cmd) |
|||
{ |
|||
for (int i = 0; i < m_BufferCount; ++i) |
|||
{ |
|||
cmd.SetGlobalTexture(m_TextureShaderIDs[i], m_RTs[i]); |
|||
} |
|||
} |
|||
|
|||
virtual public void DestroyBuffers() |
|||
{ |
|||
for (int i = 0; i < m_BufferCount; ++i) |
|||
{ |
|||
RTHandle.Release(m_RTs[i]); |
|||
m_RTs[i] = null; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8a1cfa206308c414989b3240a61bc7ef |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class DBufferManager : MRTBufferManager |
|||
{ |
|||
public int vsibleDecalCount { get; set; } |
|||
|
|||
RTHandle m_HTile; |
|||
|
|||
public DBufferManager() |
|||
: base(Decal.GetMaterialDBufferCount()) |
|||
{ |
|||
Debug.Assert(m_BufferCount <= 4); |
|||
} |
|||
|
|||
public override void CreateBuffers() |
|||
{ |
|||
RenderTextureFormat[] rtFormat; |
|||
bool[] sRGBFlags; |
|||
Decal.GetMaterialDBufferDescription(out rtFormat, out sRGBFlags); |
|||
|
|||
for (int dbufferIndex = 0; dbufferIndex < m_BufferCount; ++dbufferIndex) |
|||
{ |
|||
m_RTs[dbufferIndex] = RTHandle.Alloc(Vector2.one, colorFormat: rtFormat[dbufferIndex], sRGB: sRGBFlags[dbufferIndex], filterMode: FilterMode.Point); |
|||
m_RTIDs[dbufferIndex] = m_RTs[dbufferIndex].nameID; |
|||
m_TextureShaderIDs[dbufferIndex] = HDShaderIDs._DBufferTexture[dbufferIndex]; |
|||
} |
|||
|
|||
// We use 8x8 tiles in order to match the native GCN HTile as closely as possible.
|
|||
m_HTile = RTHandle.Alloc(size => new Vector2Int((size.x + 7) / 8, (size.y + 7) / 8), filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.R8, sRGB: false, enableRandomWrite: true); // Enable UAV
|
|||
} |
|||
|
|||
override public void DestroyBuffers() |
|||
{ |
|||
base.DestroyBuffers(); |
|||
RTHandle.Release(m_HTile); |
|||
} |
|||
|
|||
public void ClearNormalTargetAndHTile(CommandBuffer cmd, HDCamera camera, Color clearColor) |
|||
{ |
|||
// index 1 is normals
|
|||
HDUtils.SetRenderTarget(cmd, camera, m_RTs[1], ClearFlag.Color, clearColor); |
|||
HDUtils.SetRenderTarget(cmd, camera, m_HTile, ClearFlag.Color, CoreUtils.clearColorAllBlack); |
|||
} |
|||
|
|||
public void SetHTile(int bindSlot, CommandBuffer cmd) |
|||
{ |
|||
cmd.SetRandomWriteTarget(bindSlot, m_HTile); |
|||
} |
|||
|
|||
public void UnSetHTile(CommandBuffer cmd) |
|||
{ |
|||
cmd.ClearRandomWriteTargets(); |
|||
} |
|||
|
|||
public void PushGlobalParams(CommandBuffer cmd) |
|||
{ |
|||
cmd.SetGlobalInt(HDShaderIDs._EnableDBuffer, vsibleDecalCount > 0 ? 1 : 0); |
|||
BindBufferAsTextures(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9335119d0dd7cc748a67cfcc6f1040ab |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class GBufferManager : MRTBufferManager |
|||
{ |
|||
int m_GBufferCount = 0; |
|||
bool m_EnableShadowMask = false; |
|||
RenderPipelineMaterial m_DeferredMaterial; |
|||
protected RenderTargetIdentifier[] m_RTIDsNoShadowMask; |
|||
|
|||
public GBufferManager(RenderPipelineMaterial deferredMaterial, bool enableBakeShadowMask) |
|||
: base(deferredMaterial.GetMaterialGBufferCount() + (enableBakeShadowMask ? 1 : 0)) |
|||
{ |
|||
Debug.Assert(m_BufferCount <= 8); |
|||
|
|||
m_DeferredMaterial = deferredMaterial; |
|||
m_GBufferCount = deferredMaterial.GetMaterialGBufferCount(); |
|||
m_EnableShadowMask = enableBakeShadowMask; |
|||
|
|||
m_RTIDsNoShadowMask = new RenderTargetIdentifier[m_GBufferCount]; |
|||
} |
|||
|
|||
public override void CreateBuffers() |
|||
{ |
|||
RenderTextureFormat[] rtFormat; |
|||
bool[] sRGBFlags; |
|||
m_DeferredMaterial.GetMaterialGBufferDescription(out rtFormat, out sRGBFlags); |
|||
|
|||
for (int gbufferIndex = 0; gbufferIndex < m_GBufferCount; ++gbufferIndex) |
|||
{ |
|||
m_RTs[gbufferIndex] = RTHandle.Alloc(Vector2.one, colorFormat: rtFormat[gbufferIndex], sRGB: sRGBFlags[gbufferIndex], filterMode: FilterMode.Point); |
|||
m_RTIDs[gbufferIndex] = m_RTs[gbufferIndex].nameID; |
|||
m_TextureShaderIDs[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex]; |
|||
m_RTIDsNoShadowMask[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex]; |
|||
} |
|||
|
|||
if (m_EnableShadowMask) |
|||
{ |
|||
m_RTs[m_GBufferCount] = RTHandle.Alloc(Vector2.one, colorFormat: Builtin.GetShadowMaskBufferFormat(), sRGB: Builtin.GetShadowMaskSRGBFlag(), filterMode: FilterMode.Point); |
|||
m_RTIDs[m_GBufferCount] = new RenderTargetIdentifier(m_RTs[m_GBufferCount]); |
|||
m_TextureShaderIDs[m_GBufferCount] = HDShaderIDs._ShadowMaskTexture; |
|||
} |
|||
} |
|||
|
|||
public RenderTargetIdentifier[] GetBuffersRTI(bool enableShadowMask) |
|||
{ |
|||
if(!enableShadowMask) |
|||
{ |
|||
// nameID can change from one frame to another depending on the msaa flag so so we need to update this array to be sure it's up to date.
|
|||
// Moreover, if we don't have shadow masks we only need to bind the first GBuffers
|
|||
// This is important because in the shader the shadowmask buffer gets optimized out so anything bound after (like the DBuffer HTile) has a different bind point.
|
|||
for (int i = 0; i < m_GBufferCount; ++i) |
|||
{ |
|||
m_RTIDsNoShadowMask[i] = m_RTs[i].nameID; |
|||
} |
|||
return m_RTIDsNoShadowMask; |
|||
|
|||
} |
|||
else |
|||
{ |
|||
return GetBuffersRTI(); |
|||
} |
|||
} |
|||
|
|||
public int GetBufferCount(bool enableShadowMask) |
|||
{ |
|||
return enableShadowMask ? m_BufferCount : m_GBufferCount; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fd31fc09c5f088f43ac4c8e0065ed56c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/HDRenderPipeline/CopyDepthBuffer" |
|||
{ |
|||
HLSLINCLUDE |
|||
|
|||
|
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Pass |
|||
{ |
|||
Name "Copy Depth" |
|||
|
|||
Cull Off |
|||
ZTest Always |
|||
ZWrite On |
|||
Blend Off |
|||
|
|||
HLSLPROGRAM |
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 xboxone vulkan metal |
|||
#pragma fragment Frag |
|||
#pragma vertex Vert |
|||
// #pragma enable_d3d11_debug_symbols |
|||
|
|||
#include "CoreRP/ShaderLibrary/Common.hlsl" |
|||
#include "../ShaderVariables.hlsl" |
|||
|
|||
TEXTURE2D(_InputDepthTexture); |
|||
|
|||
struct Attributes |
|||
{ |
|||
uint vertexID : SV_VertexID; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
}; |
|||
|
|||
Varyings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID); |
|||
return output; |
|||
} |
|||
|
|||
float Frag(Varyings input) : SV_Depth |
|||
{ |
|||
PositionInputs posInputs = GetPositionInput(input.positionCS, _ScreenSize.zw); |
|||
return LOAD_TEXTURE2D(_InputDepthTexture, posInputs.positionSS).x; |
|||
} |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
Fallback Off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 42dfcc8fe803ece4096c58630689982f |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue