Adaug proiectul Unity

This commit is contained in:
2026-11-01 23:39:55 +02:00
parent cb14d9d37d
commit 863eac8f2c
23463 changed files with 5412601 additions and 0 deletions
@@ -0,0 +1,20 @@
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Color history before rendering transparent objects. Raw rendered geometry. No UI overlay.
/// Color space is linear RGB.
/// No mips.
/// MSAA is not supported and is resolved for the history.
/// XR is supported.
/// </summary>
internal sealed class BeforeTransparentsColorHistory : ColorHistory
{
/// <inheritdoc />
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
m_Names[0] = "BeforeTransparentsColorHistory0";
m_Names[1] = "BeforeTransparentsColorHistory1";
base.OnCreate(owner, typeId);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b1a6c4c4329a09f49a96f22a8922f69a
@@ -0,0 +1,195 @@
using System;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Base class for color history.
/// Color space is linear RGB.
/// No mips.
/// MSAA is not supported and is resolved for the history.
/// XR is supported.
/// </summary>
public abstract class ColorHistory : CameraHistoryItem
{
// Currently we are storing up to 2, one for each eye in the case of XR stereo rendering
private int[] m_Ids = new int[2];
/// <summary>
/// The names to use for history items.
/// </summary>
protected string[] m_Names = new[]
{
"ColorHistory0",
"ColorHistory1"
};
private RenderTextureDescriptor m_Descriptor;
private Hash128 m_DescKey;
// Store one jitter offset per eye per history RT. Currently the jitter offset
// is the same for both eyes, but first of all this could change, but mostly
// it's because eye jitters could be updated at different times.
private Vector2[] m_JitterOffsets = new Vector2[2*2];
/// <inheritdoc />
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
base.OnCreate(owner, typeId);
m_Ids[0] = MakeId(0);
m_Ids[1] = MakeId(1);
Array.Fill(m_JitterOffsets, Vector2.zero);
}
/// <summary>
/// Get the current history texture.
/// Current history might not be valid yet. It is valid only after executing the producing render pass.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The texture.</returns>
public RTHandle GetCurrentTexture(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return null;
return GetCurrentFrameRT(m_Ids[eyeIndex]);
}
/// <summary>
/// Get the previous history texture.
/// Previous history might not be valid yet. It is valid only after executing the producing render pass.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The texture.</returns>
public RTHandle GetPreviousTexture(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return null;
return GetPreviousFrameRT(m_Ids[eyeIndex]);
}
/// <summary>
/// Get the current history jitter value.
/// Current history might not be valid yet. It is valid only after executing the producing render pass.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The jitter value in NDC space [-1,1].</returns>
public Vector2 GetCurrentJitter(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return Vector2.zero;
int stableIndex = GetCurrentFrameRTStableIndex(m_Ids[eyeIndex]);
if (stableIndex < 0)
return Vector2.zero;
return m_JitterOffsets[stableIndex + 2 * eyeIndex];
}
/// <summary>
/// Get the previous history jitter value.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The jitter value in NDC space [-1,1].</returns>
public Vector2 GetPreviousJitter(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return Vector2.zero;
int stableIndex = GetPreviousFrameRTStableIndex(m_Ids[eyeIndex]);
if (stableIndex < 0)
return Vector2.zero;
return m_JitterOffsets[stableIndex + 2 * eyeIndex];
}
private bool IsAllocated()
{
return GetCurrentTexture() != null;
}
// True if the desc changed, graphicsFormat etc.
private bool IsDirty(ref RenderTextureDescriptor desc)
{
return m_DescKey != Hash128.Compute(ref desc);
}
private void Alloc(ref RenderTextureDescriptor desc, bool xrMultipassEnabled)
{
// In generic case, the current texture might not have been written yet. We need double buffering.
AllocHistoryFrameRT(m_Ids[0], 2, ref desc, m_Names[0]);
if(xrMultipassEnabled)
AllocHistoryFrameRT(m_Ids[1], 2, ref desc, m_Names[1]);
m_Descriptor = desc;
m_DescKey = Hash128.Compute(ref desc);
}
/// <summary>
/// Release the history texture(s).
/// </summary>
public override void Reset()
{
for(int i = 0; i < m_Ids.Length; i++)
ReleaseHistoryFrameRT(m_Ids[i]);
}
internal RenderTextureDescriptor GetHistoryDescriptor(ref RenderTextureDescriptor cameraDesc)
{
var colorDesc = cameraDesc;
colorDesc.depthStencilFormat = GraphicsFormat.None;
colorDesc.mipCount = 0;
colorDesc.msaaSamples = 1;
return colorDesc;
}
// Return true if the RTHandles were reallocated.
internal bool Update(UniversalCameraData cameraData, bool xrMultipassEnabled = false, in RenderTextureDescriptor? cameraDescOverride = null)
{
#if ENABLE_VR && ENABLE_XR_MODULE
int eyeIndex = (cameraData.xr.enabled && !cameraData.xr.singlePassEnabled) ? cameraData.xr.multipassId : 0;
#else
const int eyeIndex = 0;
#endif
Debug.Assert(eyeIndex < m_JitterOffsets.Length);
int stableIndex = GetCurrentFrameRTStableIndex(m_Ids[eyeIndex]);
if (stableIndex >= 0)
{
// Update the current jitter value for the current eye. Note that we could handle the case where
// this is the first time or if we reallocate the buffers except there's no clear definition of
// what we should use for a sensible previous jitter value in that case. So might just leave it as is.
m_JitterOffsets[stableIndex + 2 * eyeIndex] = cameraData.jitter;
}
RenderTextureDescriptor cameraDesc;
if (cameraDescOverride.HasValue)
{
cameraDesc = cameraDescOverride.Value;
}
else
{
cameraDesc = cameraData.cameraTargetDescriptor;
}
if (cameraDesc.width > 0 && cameraDesc.height > 0 && cameraDesc.graphicsFormat != GraphicsFormat.None)
{
var historyDesc = GetHistoryDescriptor(ref cameraDesc);
Camera camera = cameraData.camera;
bool isPreview = camera.cameraType == CameraType.Preview;
bool isRenderRequest = camera.isProcessingRenderRequest;
if (!isPreview && !isRenderRequest && IsDirty(ref historyDesc))
Reset();
if (!IsAllocated())
{
Alloc(ref historyDesc, xrMultipassEnabled);
return true;
}
}
return false;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b0ecc0d40b758794593fe6ee53c2b117
@@ -0,0 +1,204 @@
using System;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Base class for depth history.
/// Format is the camera depth format or R32Float on platforms with limitations.
/// If TemporalAA is enabled the depth is jittered.
/// No mips. No depth pyramid.
/// MSAA is not supported and is resolved for the history.
/// XR is supported.
/// </summary>
public abstract class DepthHistory : CameraHistoryItem
{
// Currently we are storing up to 2, one for each eye in the case of XR stereo rendering
private int[] m_Ids = new int[2];
/// <summary>
/// The names to use for history items.
/// </summary>
protected readonly string[] m_Names = new[]
{
"DepthHistory0",
"DepthHistory1"
};
private RenderTextureDescriptor m_Descriptor;
private Hash128 m_DescKey;
// Store one jitter offset per eye per history RT. Currently the jitter offset
// is the same for both eyes, but first of all this could change, but mostly
// it's because eye jitters could be updated at different times.
private Vector2[] m_JitterOffsets = new Vector2[2*2];
/// <inheritdoc />
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
base.OnCreate(owner, typeId);
m_Ids[0] = MakeId(0);
m_Ids[1] = MakeId(1);
Array.Fill(m_JitterOffsets, Vector2.zero);
}
/// <summary>
/// Get the current history texture.
/// Current history might not be valid yet. It is valid only after executing the producing render pass.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The texture.</returns>
public RTHandle GetCurrentTexture(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return null;
return GetCurrentFrameRT(m_Ids[eyeIndex]);
}
/// <summary>
/// Get the previous history texture.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The texture.</returns>
public RTHandle GetPreviousTexture(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return null;
return GetPreviousFrameRT(m_Ids[eyeIndex]);
}
/// <summary>
/// Get the current history jitter value.
/// Current history might not be valid yet. It is valid only after executing the producing render pass.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The jitter value in NDC space [-1,1].</returns>
public Vector2 GetCurrentJitter(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return Vector2.zero;
int stableIndex = GetCurrentFrameRTStableIndex(m_Ids[eyeIndex]);
if (stableIndex < 0)
return Vector2.zero;
return m_JitterOffsets[stableIndex + 2 * eyeIndex];
}
/// <summary>
/// Get the previous history jitter value.
/// </summary>
/// <param name="eyeIndex">Eye index, typically XRPass.multipassId.</param>
/// <returns>The jitter value in NDC space [-1,1].</returns>
public Vector2 GetPreviousJitter(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_Ids.Length)
return Vector2.zero;
int stableIndex = GetPreviousFrameRTStableIndex(m_Ids[eyeIndex]);
if (stableIndex < 0)
return Vector2.zero;
return m_JitterOffsets[stableIndex + 2 * eyeIndex];
}
private bool IsAllocated()
{
return GetCurrentTexture() != null;
}
// True if the desc changed, graphicsFormat etc.
private bool IsDirty(ref RenderTextureDescriptor desc)
{
return m_DescKey != Hash128.Compute(ref desc);
}
private void Alloc(ref RenderTextureDescriptor desc, bool xrMultipassEnabled)
{
// Generic type, we need double buffering.
AllocHistoryFrameRT(m_Ids[0], 2, ref desc, m_Names[0]);
if(xrMultipassEnabled)
AllocHistoryFrameRT(m_Ids[1], 2, ref desc, m_Names[1]);
m_Descriptor = desc;
m_DescKey = Hash128.Compute(ref desc);
}
/// <summary>
/// Release the history texture(s).
/// </summary>
public override void Reset()
{
for(int i = 0; i < m_Ids.Length; i++)
ReleaseHistoryFrameRT(m_Ids[i]);
}
internal RenderTextureDescriptor GetHistoryDescriptor(ref RenderTextureDescriptor cameraDesc)
{
var depthDesc = cameraDesc;
depthDesc.mipCount = 0;
depthDesc.msaaSamples = 1; // History copy should not have MSAA.
return depthDesc;
}
// Return true if the RTHandles were reallocated.
internal bool Update(UniversalCameraData cameraData, bool xrMultipassEnabled, in RenderTextureDescriptor? cameraDescOverride = null)
{
#if ENABLE_VR && ENABLE_XR_MODULE
int eyeIndex = (cameraData.xr.enabled && !cameraData.xr.singlePassEnabled) ? cameraData.xr.multipassId : 0;
#else
const int eyeIndex = 0;
#endif
Debug.Assert(eyeIndex < m_JitterOffsets.Length);
int stableIndex = GetCurrentFrameRTStableIndex(m_Ids[eyeIndex]);
if (stableIndex >= 0)
{
// Update the current jitter value for the current eye. Note that we could handle the case where
// this is the first time or if we reallocate the buffers except there's no clear definition of
// what we should use for a sensible previous jitter value in that case. So might just leave it as is.
m_JitterOffsets[stableIndex + 2 * eyeIndex] = cameraData.jitter;
}
RenderTextureDescriptor cameraDesc;
if (cameraDescOverride.HasValue)
{
cameraDesc = cameraDescOverride.Value;
}
else
{
cameraDesc = cameraData.cameraTargetDescriptor;
// On GLES we don't support sampling the MSAA targets, so if auto depth resolve is not available, the only thing that works is rendering to a color target.
// This has been the behavior from at least 6.0. However, it results in the format mostly being color on the different graphics APIs, even when
// it could be a depth format if MSAA sampling for depth is allowed.
if (RenderingUtils.MultisampleDepthResolveSupported())
{
cameraDesc.graphicsFormat = GraphicsFormat.None;
}
else
{
cameraDesc.graphicsFormat = GraphicsFormat.R32_SFloat;
cameraDesc.depthStencilFormat = GraphicsFormat.None;
}
}
if (cameraDesc.width > 0 && cameraDesc.height > 0 && (cameraDesc.depthStencilFormat != GraphicsFormat.None || cameraDesc.graphicsFormat != GraphicsFormat.None) )
{
var historyDesc = GetHistoryDescriptor(ref cameraDesc);
if (IsDirty(ref historyDesc))
Reset();
if (!IsAllocated())
{
Alloc(ref historyDesc, xrMultipassEnabled);
return true;
}
}
return false;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 691713c8a2b6fda46a6e558da3e63dd4
@@ -0,0 +1,24 @@
using System;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Raw render color history. The color snapshot is taken before post processing. Raw rendered geometry. No UI overlay.
/// A matching depth is RawDepthHistory.
/// Color space is linear RGB.
/// No mips.
/// MSAA is not supported and is resolved for the history.
/// XR is supported.
/// </summary>
public sealed class RawColorHistory : ColorHistory
{
/// <inheritdoc />
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
m_Names[0] = "RawColorHistory0";
m_Names[1] = "RawColorHistory1";
base.OnCreate(owner, typeId);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d8d2b2ac40c1940d281d4f1f8384a0bf
@@ -0,0 +1,25 @@
using System;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Raw render depth history. The depth snapshot is taken before post processing.
/// A matching color is RawColorHistory.
/// Format is the camera depth format or R32Float on platforms with limitations.
/// If TemporalAA is enabled the depth is jittered.
/// No mips. No depth pyramid.
/// MSAA is not supported and is resolved for the history.
/// XR is supported.
/// </summary>
public sealed class RawDepthHistory : DepthHistory
{
/// <inheritdoc />
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
m_Names[0] = "RawDepthHistory0";
m_Names[1] = "RawDepthHistory1";
base.OnCreate(owner, typeId);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e120334449e144591bf8fd51debb4063
@@ -0,0 +1,189 @@
#if MODERN_SSAO
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Screen Space Ambient Occlusion (SSAO) history for temporal filtering.
/// Uses double buffering so the previous frame can be sampled while the current frame is written.
/// The history stores packed depth (RG), AO (B), and a normalized accumulated frame count (A) in an RGBA8 texture.
/// </summary>
public sealed class SSAOHistory : CameraHistoryItem
{
private int[] m_AccumulationTextureIds = new int[2];
private int[] m_AccumulationVersions = new int[2];
private static readonly string[] m_AccumulationNames = new[]
{
"SSAOAccumulationTex0",
"SSAOAccumulationTex1"
};
private RenderTextureDescriptor m_Descriptor;
private Hash128 m_DescKey;
/// <summary>
/// Called internally on instance creation.
/// Sets up RTHandle ids.
/// </summary>
/// <param name="owner">BufferedRTHandleSystem of the owning camera.</param>
/// <param name="typeId">Unique id given to SSAOHistory by the owning camera.</param>
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
base.OnCreate(owner, typeId);
m_AccumulationTextureIds[0] = MakeId(0);
m_AccumulationTextureIds[1] = MakeId(1);
}
/// <summary>
/// Release SSAO accumulation textures.
/// </summary>
public override void Reset()
{
for (int i = 0; i < m_AccumulationTextureIds.Length; i++)
{
ReleaseHistoryFrameRT(m_AccumulationTextureIds[i]);
m_AccumulationVersions[i] = -1;
}
m_Descriptor.width = 0;
m_Descriptor.height = 0;
m_Descriptor.graphicsFormat = GraphicsFormat.None;
m_DescKey = Hash128.Compute(0);
}
/// <summary>
/// Get the SSAO history write target for the current frame.
/// </summary>
/// <param name="eyeIndex">Eye index for XR multi-pass.</param>
/// <returns>Current frame RTHandle for SSAO history writes.</returns>
public RTHandle GetCurrentTexture(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_AccumulationTextureIds.Length)
return null;
return GetCurrentFrameRT(m_AccumulationTextureIds[eyeIndex]);
}
/// <summary>
/// Get the SSAO history read target from the previous frame.
/// </summary>
/// <param name="eyeIndex">Eye index for XR multi-pass.</param>
/// <returns>Previous frame RTHandle for SSAO history reads.</returns>
public RTHandle GetPreviousTexture(int eyeIndex = 0)
{
if ((uint)eyeIndex >= m_AccumulationTextureIds.Length)
return null;
return GetPreviousFrameRT(m_AccumulationTextureIds[eyeIndex]);
}
/// <summary>
/// Get SSAO accumulation texture.
/// </summary>
/// <param name="eyeIndex">Eye index for XR multi-pass.</param>
/// <returns>Current frame RTHandle for SSAO accumulation texture.</returns>
public RTHandle GetAccumulationTexture(int eyeIndex = 0)
{
return GetCurrentTexture(eyeIndex);
}
/// <summary>
/// Get SSAO accumulation texture version.
/// Tracks which frame the accumulation was last updated.
/// </summary>
/// <param name="eyeIndex">Eye index for XR multi-pass.</param>
/// <returns>Accumulation texture version.</returns>
public int GetAccumulationVersion(int eyeIndex = 0)
{
return m_AccumulationVersions[eyeIndex];
}
/// <summary>
/// Set SSAO accumulation texture version.
/// </summary>
/// <param name="eyeIndex">Eye index for XR multi-pass.</param>
/// <param name="version">Version to set (typically Time.frameCount).</param>
internal void SetAccumulationVersion(int eyeIndex, int version)
{
m_AccumulationVersions[eyeIndex] = version;
}
// Check if the SSAO accumulation texture is valid.
private bool IsValid()
{
return GetCurrentTexture(0) != null;
}
// True if the desc changed, graphicsFormat etc.
private bool IsDirty(ref RenderTextureDescriptor desc)
{
return m_DescKey != Hash128.Compute(ref desc);
}
private void Alloc(ref RenderTextureDescriptor desc, bool xrMultipassEnabled)
{
AllocHistoryFrameRT(m_AccumulationTextureIds[0], 2, ref desc, m_AccumulationNames[0]);
if (xrMultipassEnabled)
AllocHistoryFrameRT(m_AccumulationTextureIds[1], 2, ref desc, m_AccumulationNames[1]);
m_Descriptor = desc;
m_DescKey = Hash128.Compute(ref desc);
}
/// <summary>
/// Create SSAO history descriptor from camera descriptor.
/// </summary>
/// <param name="cameraDesc">Camera render texture descriptor.</param>
/// <param name="downsample">Whether SSAO is running at half resolution.</param>
/// <param name="enableRandomWrite">Whether the resource requires enableRandomWrite.</param>
/// <returns>SSAO history render texture descriptor.</returns>
internal static RenderTextureDescriptor GetHistoryDescriptor(ref RenderTextureDescriptor cameraDesc, bool downsample, bool enableRandomWrite)
{
int downsampleDivider = downsample ? 2 : 1;
RenderTextureDescriptor ssaoDesc = cameraDesc;
ssaoDesc.graphicsFormat = GraphicsFormat.R8G8B8A8_UNorm;
ssaoDesc.depthStencilFormat = GraphicsFormat.None;
ssaoDesc.msaaSamples = 1;
ssaoDesc.width /= downsampleDivider;
ssaoDesc.height /= downsampleDivider;
ssaoDesc.enableRandomWrite = enableRandomWrite;
return ssaoDesc;
}
/// <summary>
/// Update the SSAO history texture allocation.
/// </summary>
/// <param name="cameraData">Camera data providing the render texture descriptor.</param>
/// <param name="downsample">Whether SSAO is running at half resolution.</param>
/// <param name="enableRandomWrite">Whether the resource requires enableRandomWrite.</param>
/// <param name="xrMultipassEnabled">Whether XR multi-pass is enabled.</param>
/// <returns>True if the RTHandles were reallocated.</returns>
internal bool Update(UniversalCameraData cameraData, bool downsample, bool enableRandomWrite, bool xrMultipassEnabled = false)
{
ref RenderTextureDescriptor cameraDesc = ref cameraData.cameraTargetDescriptor;
if (cameraDesc.width > 0 && cameraDesc.height > 0 && cameraDesc.graphicsFormat != GraphicsFormat.None)
{
var ssaoDesc = GetHistoryDescriptor(ref cameraDesc, downsample, enableRandomWrite);
Camera camera = cameraData.camera;
bool isPreview = camera.cameraType == CameraType.Preview;
bool isRenderRequest = camera.isProcessingRenderRequest;
if (!isPreview && !isRenderRequest && IsDirty(ref ssaoDesc))
Reset();
if (!IsValid())
{
Alloc(ref ssaoDesc, xrMultipassEnabled);
return true;
}
}
return false;
}
}
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7e13c1c4ebc377d4a9c45f387209add8
@@ -0,0 +1,94 @@
using System;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.Universal
{
// TODO: Draft. A convenience base class to wrap single texture into a type.
internal abstract class SingleHistoryBase : CameraHistoryItem
{
private int m_Id;
private RenderTextureDescriptor m_Descriptor;
private Hash128 m_DescKey;
/// <summary>
/// Called internally on instance creation.
/// Sets up RTHandle ids.
/// </summary>
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
base.OnCreate(owner, typeId);
m_Id = MakeId(0);
}
/// <summary>
/// Get the history texture(s).
/// </summary>
public RTHandle GetTexture(int frameIndex = 0)
{
if ((uint)frameIndex >= GetHistoryFrameCount())
return null;
return storage.GetFrameRT(m_Id, frameIndex);
}
public RTHandle GetCurrentTexture()
{
return GetCurrentFrameRT(m_Id);
}
public RTHandle GetPreviousTexture()
{
return GetTexture(1);
}
internal bool IsAllocated()
{
return GetTexture() != null;
}
// True if the desc changed, graphicsFormat etc.
internal bool IsDirty(ref RenderTextureDescriptor desc)
{
return m_DescKey != Hash128.Compute(ref desc);
}
private void Alloc(ref RenderTextureDescriptor desc)
{
AllocHistoryFrameRT(m_Id, GetHistoryFrameCount(), ref desc, GetHistoryName());
m_Descriptor = desc;
m_DescKey = Hash128.Compute(ref desc);
}
/// <summary>
/// Release the history texture(s).
/// </summary>
public override void Reset()
{
ReleaseHistoryFrameRT(m_Id);
}
// Return true if the RTHandles were reallocated.
internal bool Update(ref RenderTextureDescriptor cameraDesc)
{
if (cameraDesc.width > 0 && cameraDesc.height > 0 && cameraDesc.graphicsFormat != GraphicsFormat.None)
{
var historyDesc = GetHistoryDescriptor(ref cameraDesc);
if (IsDirty(ref historyDesc))
Reset();
if (!IsAllocated())
{
Alloc(ref historyDesc);
return true;
}
}
return false;
}
protected abstract int GetHistoryFrameCount();
protected abstract string GetHistoryName();
protected abstract RenderTextureDescriptor GetHistoryDescriptor(ref RenderTextureDescriptor cameraDesc);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3e5bfeb218ab44b849bf614e7b230a7b
@@ -0,0 +1,54 @@
namespace UnityEngine.Rendering.Universal
{
internal sealed class StpHistory : CameraHistoryItem
{
/// <summary>
/// STP uses a custom history texture management system in order to simplify code sharing with other SRPs
/// In URP's case, we potentially need two of these in order to support multi-pass XR rendering
/// </summary>
STP.HistoryContext[] m_historyContexts = new STP.HistoryContext[2];
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
base.OnCreate(owner, typeId);
for (int eyeIndex = 0; eyeIndex < 2; ++eyeIndex)
{
m_historyContexts[eyeIndex] = new STP.HistoryContext();
}
}
public override void Reset()
{
for (int eyeIndex = 0; eyeIndex < 2; ++eyeIndex)
{
// Clear internal data within the contexts whenever we're reset
m_historyContexts[eyeIndex].Dispose();
}
}
internal STP.HistoryContext GetHistoryContext(int eyeIndex)
{
// STP only supports XR multi-pass with two views
Debug.Assert(eyeIndex < 2);
return m_historyContexts[eyeIndex];
}
// Return true if the internal history data is invalid after the update operation
internal bool Update(UniversalCameraData cameraData)
{
STP.HistoryUpdateInfo info;
info.preUpscaleSize = new Vector2Int(cameraData.cameraTargetDescriptor.width, cameraData.cameraTargetDescriptor.height);
info.postUpscaleSize = new Vector2Int(cameraData.pixelWidth, cameraData.pixelHeight);
info.useHwDrs = false;
info.useTexArray = cameraData.xr.enabled && cameraData.xr.singlePassEnabled;
int eyeIndex = (cameraData.xr.enabled && !cameraData.xr.singlePassEnabled) ? cameraData.xr.multipassId : 0;
bool hasValidHistory = GetHistoryContext(eyeIndex).Update(ref info);
return !hasValidHistory;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9eac74bd55c9f7248a432b8e8725366c
@@ -0,0 +1,129 @@
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.Universal
{
/// <summary>
/// Temporal Anti-aliasing (TAA) persistent data for Universal Rendering Pipeline.
/// Holds the TAA color history accumulation texture.
/// </summary>
public sealed class TaaHistory : CameraHistoryItem
{
private int[] m_TaaAccumulationTextureIds = new int[2];
private int[] m_TaaAccumulationVersions = new int[2];
private static readonly string[] m_TaaAccumulationNames = new[]
{
"TaaAccumulationTex0",
"TaaAccumulationTex1"
};
private RenderTextureDescriptor m_Descriptor;
private Hash128 m_DescKey;
/// <summary>
/// Called internally on instance creation.
/// Sets up RTHandle ids.
/// </summary>
/// <param name="owner">BufferedRTHandleSystem of the owning camera.</param>
/// <param name="typeId">Unique id given to TaaHistory by the owning camera.</param>
public override void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
base.OnCreate(owner, typeId);
m_TaaAccumulationTextureIds[0] = MakeId(0);
m_TaaAccumulationTextureIds[1] = MakeId(1);
}
/// <summary>
/// Release TAA accumulation textures.
/// </summary>
public override void Reset()
{
for (int i = 0; i < m_TaaAccumulationTextureIds.Length; i++)
{
ReleaseHistoryFrameRT(m_TaaAccumulationTextureIds[i]);
m_TaaAccumulationVersions[i] = -1;
}
m_Descriptor.width = 0;
m_Descriptor.height = 0;
m_Descriptor.graphicsFormat = GraphicsFormat.None;
m_DescKey = Hash128.Compute(0);
}
/// <summary>
/// Get TAA accumulation texture.
/// </summary>
/// <param name="eyeIndex">Eye index for XR multi-pass.</param>
/// <returns>Current frame RTHandle for TAA accumulation texture.</returns>
public RTHandle GetAccumulationTexture(int eyeIndex = 0)
{
return GetCurrentFrameRT(m_TaaAccumulationTextureIds[eyeIndex]);
}
/// <summary>
/// Get TAA accumulation texture version.
/// Tracks which frame the accumulation was last updated.
/// </summary>
/// <param name="eyeIndex">Eye index for XR multi-pass.</param>
/// <returns>Accumulation texture version.</returns>
public int GetAccumulationVersion(int eyeIndex = 0)
{
return m_TaaAccumulationVersions[eyeIndex];
}
internal void SetAccumulationVersion(int eyeIndex, int version)
{
m_TaaAccumulationVersions[eyeIndex] = version;
}
// Check if the TAA accumulation texture is valid.
private bool IsValid()
{
return GetAccumulationTexture(0) != null;
}
// True if the desc changed, graphicsFormat etc.
private bool IsDirty(ref RenderTextureDescriptor desc)
{
return m_DescKey != Hash128.Compute(ref desc);
}
private void Alloc(ref RenderTextureDescriptor desc, bool xrMultipassEnabled)
{
AllocHistoryFrameRT(m_TaaAccumulationTextureIds[0], 1, ref desc, m_TaaAccumulationNames[0]);
if (xrMultipassEnabled)
AllocHistoryFrameRT(m_TaaAccumulationTextureIds[1], 1, ref desc, m_TaaAccumulationNames[1]);
m_Descriptor = desc;
m_DescKey = Hash128.Compute(ref desc);
}
// Return true if the RTHandles were reallocated.
internal bool Update(UniversalCameraData cameraData, bool xrMultipassEnabled = false)
{
ref RenderTextureDescriptor cameraDesc = ref cameraData.cameraTargetDescriptor;
if (cameraDesc.width > 0 && cameraDesc.height > 0 && cameraDesc.graphicsFormat != GraphicsFormat.None)
{
var taaDesc = TemporalAA.TemporalAADescFromCameraDesc(ref cameraDesc);
// Editor can reuse a camera as a preview camera or do single frame RenderRequests.
// These can break history as it is no longer unique for the camera.
// Avoid resetting history and treat previews as redraws.
Camera camera = cameraData.camera;
bool isPreview = camera.cameraType == CameraType.Preview;
bool isRenderRequest = camera.isProcessingRenderRequest;
if (!isPreview && !isRenderRequest && IsDirty(ref taaDesc))
Reset();
if (!IsValid())
{
Alloc(ref taaDesc, xrMultipassEnabled);
return true;
}
}
return false;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 787a9a86657542348d1b4e9caece0a0e
timeCreated: 1711366137