maint: added htrace ssgi

This commit is contained in:
Chris
2025-12-31 12:44:11 -05:00
parent 90caaa07c4
commit 3a766f7606
203 changed files with 17634 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7a79b752c0a5472889da303294bb41c1
timeCreated: 1756743088

View File

@@ -0,0 +1,63 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace HTraceSSGI.Scripts.Passes.Shared
{
internal static class HBlueNoise
{
internal static readonly int g_OwenScrambledTexture = Shader.PropertyToID("g_OwenScrambledTexture");
internal static readonly int g_ScramblingTileXSPP = Shader.PropertyToID("g_ScramblingTileXSPP");
internal static readonly int g_RankingTileXSPP = Shader.PropertyToID("g_RankingTileXSPP");
internal static readonly int g_ScramblingTexture = Shader.PropertyToID("g_ScramblingTexture");
private static Texture2D _owenScrambledTexture;
public static Texture2D OwenScrambledTexture
{
get
{
if (_owenScrambledTexture == null)
_owenScrambledTexture = UnityEngine.Resources.Load<Texture2D>("HTraceSSGI/BlueNoise/OwenScrambledNoise256");
return _owenScrambledTexture;
}
}
private static Texture2D _scramblingTileXSPP;
public static Texture2D ScramblingTileXSPP
{
get
{
if (_scramblingTileXSPP == null)
_scramblingTileXSPP = UnityEngine.Resources.Load<Texture2D>("HTraceSSGI/BlueNoise/ScramblingTile8SPP");
return _scramblingTileXSPP;
}
}
private static Texture2D _rankingTileXSPP;
public static Texture2D RankingTileXSPP
{
get
{
if (_rankingTileXSPP == null)
_rankingTileXSPP = UnityEngine.Resources.Load<Texture2D>("HTraceSSGI/BlueNoise/RankingTile8SPP");
return _rankingTileXSPP;
}
}
private static Texture2D _scramblingTexture;
public static Texture2D ScramblingTexture
{
get
{
if (_scramblingTexture == null)
_scramblingTexture = UnityEngine.Resources.Load<Texture2D>("HTraceSSGI/BlueNoise/ScrambleNoise");
return _scramblingTexture;
}
}
public static void SetTextures(CommandBuffer cmdList)
{
cmdList.SetGlobalTexture(g_OwenScrambledTexture, OwenScrambledTexture);
cmdList.SetGlobalTexture(g_ScramblingTileXSPP, ScramblingTileXSPP);
cmdList.SetGlobalTexture(g_RankingTileXSPP, RankingTileXSPP);
cmdList.SetGlobalTexture(g_ScramblingTexture, ScramblingTexture);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9b39dbedfe8559c4984c466e938fdf33
timeCreated: 1729617470
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Passes/Shared/HBlueNoise.cs
uploadId: 840002

View File

@@ -0,0 +1,667 @@
//pipelinedefine
#define H_URP
using System;
using HTraceSSGI.Scripts.Data.Private;
using HTraceSSGI.Scripts.Data.Public;
using HTraceSSGI.Scripts.Extensions;
using HTraceSSGI.Scripts.Extensions.CameraHistorySystem;
using HTraceSSGI.Scripts.Globals;
using HTraceSSGI.Scripts.Wrappers;
using UnityEngine;
using UnityEngine.Rendering;
using HTraceSSGI.Scripts.Infrastructure.URP;
namespace HTraceSSGI.Scripts.Passes.Shared
{
internal class SSGI
{
// Kernels
internal enum HTemporalReprojectionKernels
{
TemporalReprojection = 0,
ColorReprojection = 1,
CopyHistory = 2,
LuminanceMomentsGeneration = 3,
LuminanceMomentsClear = 4,
}
internal enum HCheckerboardingKernels
{
CheckerboardClassification = 0,
IndirectArguments = 1,
}
internal enum HRenderSSGIKernels
{
TraceSSGI = 0,
MaskExclude = 1,
}
internal enum HReSTIRKernels
{
TemporalResampling = 0,
FireflySuppression = 1,
SpatialResampling = 2,
SpatialValidation = 3,
}
internal enum HDenoiserKernels
{
TemporalAccumulation = 0,
TemporalStabilization = 1,
PointDistributionFill = 2,
SpatialFilter = 3,
SpatialFilter1 = 4,
SpatialFilter2 = 5,
}
internal enum HInterpolationKernels
{
Interpolation = 0,
}
// Textures, except History
public static RTWrapper ColorCopy_URP = new RTWrapper(); // URP only
public static RTWrapper DebugOutput = new RTWrapper();
public static RTWrapper ReservoirLuminance = new RTWrapper();
public static RTWrapper Reservoir = new RTWrapper();
public static RTWrapper ReservoirReprojected = new RTWrapper();
public static RTWrapper ReservoirSpatial = new RTWrapper();
public static RTWrapper SamplecountReprojected = new RTWrapper();
public static RTWrapper TemporalInvalidityFilteredA = new RTWrapper();
public static RTWrapper TemporalInvalidityFilteredB = new RTWrapper();
public static RTWrapper TemporalInvalidityReprojected = new RTWrapper();
public static RTWrapper SpatialOcclusionReprojected = new RTWrapper();
public static RTWrapper AmbientOcclusion = new RTWrapper();
public static RTWrapper AmbientOcclusionGuidance = new RTWrapper();
public static RTWrapper AmbientOcclusionInvalidity = new RTWrapper();
public static RTWrapper AmbientOcclusionReprojected = new RTWrapper();
public static RTWrapper RadianceReprojected = new RTWrapper();
public static RTWrapper RadianceFiltered = new RTWrapper();
public static RTWrapper RadianceInterpolated = new RTWrapper();
public static RTWrapper RadianceStabilized = new RTWrapper();
public static RTWrapper RadianceStabilizedReprojected = new RTWrapper();
public static RTWrapper RadianceNormalDepth = new RTWrapper();
public static RTWrapper ColorReprojected = new RTWrapper();
public static RTWrapper DummyBlackTexture = new RTWrapper();
// History Textures
internal struct HistoryCameraDataSSGI : ICameraHistoryData, IDisposable
{
private int hash;
public RTWrapper ColorPreviousFrame;
public RTWrapper ReservoirTemporal;
public RTWrapper SampleCount;
public RTWrapper NormalDepth;
public RTWrapper NormalDepthFullRes;
public RTWrapper Radiance;
public RTWrapper RadianceAccumulated;
public RTWrapper SpatialOcclusionAccumulated;
public RTWrapper TemporalInvalidityAccumulated;
public RTWrapper AmbientOcclusionAccumulated;
public HistoryCameraDataSSGI(int hash = 0)
{
this.hash = hash;
ColorPreviousFrame = new RTWrapper();
ReservoirTemporal = new RTWrapper();
SampleCount = new RTWrapper();
NormalDepth = new RTWrapper();
NormalDepthFullRes = new RTWrapper();
Radiance = new RTWrapper();
RadianceAccumulated = new RTWrapper();
SpatialOcclusionAccumulated = new RTWrapper();
TemporalInvalidityAccumulated = new RTWrapper();
AmbientOcclusionAccumulated = new RTWrapper();
}
public int GetHash() => hash;
public void SetHash(int hashIn) => this.hash = hashIn;
public void Dispose()
{
ColorPreviousFrame?.HRelease();
ReservoirTemporal?.HRelease();
SampleCount?.HRelease();
NormalDepth?.HRelease();
NormalDepthFullRes?.HRelease();
Radiance?.HRelease();
RadianceAccumulated?.HRelease();
SpatialOcclusionAccumulated?.HRelease();
TemporalInvalidityAccumulated?.HRelease();
AmbientOcclusionAccumulated?.HRelease();
}
}
internal static readonly CameraHistorySystem<HistoryCameraDataSSGI> CameraHistorySystem = new CameraHistorySystem<HistoryCameraDataSSGI>();
// Shader Properties
public static readonly int _RayCounter = Shader.PropertyToID("_RayCounter");
public static readonly int _RayCounter_Output = Shader.PropertyToID("_RayCounter_Output");
public static readonly int _IndirectCoords_Output = Shader.PropertyToID("_IndirectCoords_Output");
public static readonly int _IndirectArguments_Output = Shader.PropertyToID("_IndirectArguments_Output");
public static readonly int _TracingCoords = Shader.PropertyToID("_TracingCoords");
public static readonly int _RayTracedCounter = Shader.PropertyToID("_RayTracedCounter");
public static readonly int _DepthToViewParams = Shader.PropertyToID("_DepthToViewParams");
public static readonly int _HScaleFactorSSGI = Shader.PropertyToID("_HScaleFactorSSGI");
public static readonly int _HPreviousScaleFactorSSGI = Shader.PropertyToID("_HPreviousScaleFactorSSGI");
public static readonly int _ReservoirDiffuseWeight = Shader.PropertyToID("_ReservoirDiffuseWeight");
public static readonly int _ExcludeCastingLayerMaskSSGI = Shader.PropertyToID("_ExcludeCastingLayerMaskSSGI");
public static readonly int _ExcludeReceivingLayerMaskSSGI = Shader.PropertyToID("_ExcludeReceivingLayerMaskSSGI");
public static readonly int _APVParams = Shader.PropertyToID("_APVParams");
public static readonly int _BrightnessClamp = Shader.PropertyToID("_BrightnessClamp");
public static readonly int _MaxDeviation = Shader.PropertyToID("_MaxDeviation");
public static readonly int _RayCount = Shader.PropertyToID("_RayCount");
public static readonly int _StepCount = Shader.PropertyToID("_StepCount");
public static readonly int _RayLength = Shader.PropertyToID("_RayLength");
public static readonly int _SkyFallbackIntensity = Shader.PropertyToID("_SkyFallbackIntensity");
public static readonly int _BackfaceLighting = Shader.PropertyToID("_BackfaceLighting");
public static readonly int _Falloff = Shader.PropertyToID("_Falloff");
public static readonly int _ThicknessParams = Shader.PropertyToID("_ThicknessParams");
public static readonly int _DenoiseFallback = Shader.PropertyToID("_DenoiseFallback");
public static readonly int _FilterAdaptivity = Shader.PropertyToID("_FilterAdaptivity");
public static readonly int _FilterRadius = Shader.PropertyToID("_FilterRadius");
public static readonly int _ColorCopy = Shader.PropertyToID("_ColorCopy");
public static readonly int _Color_History = Shader.PropertyToID("_Color_History");
public static readonly int _LuminanceMoments = Shader.PropertyToID("_LuminanceMoments");
public static readonly int _Radiance_History = Shader.PropertyToID("_Radiance_History");
public static readonly int _RadianceNormalDepth = Shader.PropertyToID("_RadianceNormalDepth");
public static readonly int _Radiance_Output = Shader.PropertyToID("_Radiance_Output");
public static readonly int _NormalDepth_History = Shader.PropertyToID("_NormalDepth_History");
public static readonly int _ReprojectedColor_Output = Shader.PropertyToID("_ReprojectedColor_Output");
public static readonly int _Samplecount_History = Shader.PropertyToID("_Samplecount_History");
public static readonly int _Samplecount_Output = Shader.PropertyToID("_Samplecount_Output");
public static readonly int _SpatialOcclusion_History = Shader.PropertyToID("_SpatialOcclusion_History");
public static readonly int _SpatialOcclusion_Output = Shader.PropertyToID("_SpatialOcclusion_Output");
public static readonly int _PointDistribution_Output = Shader.PropertyToID("_PointDistribution_Output");
public static readonly int _Reservoir = Shader.PropertyToID("_Reservoir");
public static readonly int _Reservoir_Output = Shader.PropertyToID("_Reservoir_Output");
public static readonly int _TemporalInvalidity_History = Shader.PropertyToID("_TemporalInvalidity_History");
public static readonly int _TemporalInvalidity_Output = Shader.PropertyToID("_TemporalInvalidity_Output");
public static readonly int _AmbientOcclusion_History = Shader.PropertyToID("_AmbientOcclusion_History");
public static readonly int _AmbientOcclusion_Output = Shader.PropertyToID("_AmbientOcclusion_Output");
public static readonly int _SampleCount = Shader.PropertyToID("_SampleCount");
public static readonly int _Color = Shader.PropertyToID("_Color");
public static readonly int _AmbientOcclusion = Shader.PropertyToID("_AmbientOcclusion");
public static readonly int _AmbientOcclusionInvalidity = Shader.PropertyToID("_AmbientOcclusionInvalidity");
public static readonly int _AmbientOcclusionReprojected = Shader.PropertyToID("_AmbientOcclusionReprojected");
public static readonly int _SpatialOcclusion = Shader.PropertyToID("_SpatialOcclusion");
public static readonly int _ReservoirReprojected = Shader.PropertyToID("_ReservoirReprojected");
public static readonly int _ReservoirSpatial_Output = Shader.PropertyToID("_ReservoirSpatial_Output");
public static readonly int _ReservoirLuminance = Shader.PropertyToID("_ReservoirLuminance");
public static readonly int _ReservoirTemporal_Output = Shader.PropertyToID("_ReservoirTemporal_Output");
public static readonly int _TemporalInvalidity = Shader.PropertyToID("_TemporalInvalidity");
public static readonly int _NormalDepth_HistoryOutput = Shader.PropertyToID("_NormalDepth_HistoryOutput");
public static readonly int _ReservoirLuminance_Output = Shader.PropertyToID("_ReservoirLuminance_Output");
public static readonly int _SpatialGuidance_Output = Shader.PropertyToID("_SpatialGuidance_Output");
public static readonly int _PointDistribution = Shader.PropertyToID("_PointDistribution");
public static readonly int _NormalDepth = Shader.PropertyToID("_NormalDepth");
public static readonly int _RadianceNormalDepth_Output = Shader.PropertyToID("_RadianceNormalDepth_Output");
public static readonly int _SpatialGuidance = Shader.PropertyToID("_SpatialGuidance");
public static readonly int _SamplecountReprojected = Shader.PropertyToID("_SamplecountReprojected");
public static readonly int _Radiance = Shader.PropertyToID("_Radiance");
public static readonly int _RadianceReprojected = Shader.PropertyToID("_RadianceReprojected");
public static readonly int _Radiance_TemporalOutput = Shader.PropertyToID("_Radiance_TemporalOutput");
public static readonly int _Radiance_SpatialOutput = Shader.PropertyToID("_Radiance_SpatialOutput");
public static readonly int _SampleCountSSGI = Shader.PropertyToID("_SampleCountSSGI");
public static readonly int _HTraceBufferGI = Shader.PropertyToID("_HTraceBufferGI");
public static readonly int _IndirectLightingIntensity = Shader.PropertyToID("_IndirectLightingIntensity");
public static readonly int _MetallicIndirectFallback = Shader.PropertyToID("_MetallicIndirectFallback");
private static readonly int _DebugSwitch = Shader.PropertyToID("_DebugSwitch");
private static readonly int _BuffersSwitch = Shader.PropertyToID("_BuffersSwitch");
private static readonly int _Debug_Output = Shader.PropertyToID("_Debug_Output");
// Keywords
public static readonly string VR_COMPATIBILITY = "VR_COMPATIBILITY";
public static readonly string USE_TEMPORAL_INVALIDITY = "USE_TEMPORAL_INVALIDITY";
public static readonly string USE_RECEIVE_LAYER_MASK = "USE_RECEIVE_LAYER_MASK";
public static readonly string USE_SPATIAL_OCCLUSION = "USE_SPATIAL_OCCLUSION";
public static readonly string INTERPOLATION_OUTPUT = "INTERPOLATION_OUTPUT";
public static readonly string VALIDATE_SPATIAL_OCCLUSION = "VALIDATE_SPATIAL_OCCLUSION";
public static readonly string AUTOMATIC_THICKNESS = "AUTOMATIC_THICKNESS";
public static readonly string LINEAR_THICKNESS = "LINEAR_THICKNESS";
public static readonly string UNIFORM_THICKNESS = "UNIFORM_THICKNESS";
public static readonly string CHECKERBOARDING = "CHECKERBOARDING";
public static readonly string FALLBACK_APV = "FALLBACK_APV";
public static readonly string FALLBACK_SKY = "FALLBACK_SKY";
public static readonly string FULL_RESOLUTION_DEPTH = "FULL_RESOLUTION_DEPTH";
public static readonly string REFINE_INTERSECTION = "REFINE_INTERSECTION";
public static readonly string VALIDATE_TEMPORAL_OCCLUSION = "VALIDATE_TEMPORAL_OCCLUSION";
public static readonly string VALIDATE_TEMPORAL_LIGHTING = "VALIDATE_TEMPORAL_LIGHTING";
public static readonly string HALF_STEP_VALIDATION = "HALF_STEP_VALIDATION";
public static readonly string REPROJECT_TEMPORAL_INVALIDITY = "REPROJECT_TEMPORAL_INVALIDITY";
public static readonly string AUTOMATIC_BRIGHTNESS_CLAMP = "AUTOMATIC_BRIGHTNESS_CLAMP";
public static readonly string REPROJECT_SPATIAL_OCCLUSION = "REPROJECT_SPATIAL_OCCLUSION";
public static readonly string FULL_RESOLUTION_REPROJECTION = "FULL_RESOLUTION_REPROJECTION";
public static readonly string REPROJECT_COLOR = "REPROJECT_COLOR";
// Profiler Samplers
public static ProfilingSampler AmbientLightingOverrideSampler = new ProfilingSampler("Ambient Lighting Override");
public static ProfilingSampler TemporalReprojectionSampler = new ProfilingSampler("Temporal Reprojection");
public static ProfilingSampler CheckerboardingSampler = new ProfilingSampler("Checkerboarding");
public static ProfilingSampler RadianceTracingSampler = new ProfilingSampler("Trace Radiance");
public static ProfilingSampler RestirTemporalSampler = new ProfilingSampler("ReSTIR Temporal");
public static ProfilingSampler RestirFireflySampler = new ProfilingSampler("ReSTIR Firefly");
public static ProfilingSampler RestirSpatialSampler = new ProfilingSampler("ReSTIR Spatial");
public static ProfilingSampler TemporalAccumulationSampler = new ProfilingSampler("Temporal Accumulation");
public static ProfilingSampler SpatialFilterSampler = new ProfilingSampler("Spatial Filter");
public static ProfilingSampler InterpolationSampler = new ProfilingSampler("Interpolation");
public static ProfilingSampler DebugSampler = new ProfilingSampler("Debug");
public static ProfilingSampler IndirectLightingInjectionSampler = new ProfilingSampler("Indirect Lighting Injection");
// Computes
public static ComputeShader HDebug = null;
public static ComputeShader HRenderSSGI = null;
public static ComputeShader HReSTIR = null;
public static ComputeShader HDenoiser = null;
public static ComputeShader HInterpolation = null;
public static ComputeShader HCheckerboarding = null;
public static ComputeShader PyramidGeneration = null;
public static ComputeShader HTemporalReprojection = null;
// Materials
public static Material ColorCompose_BIRP;
public static Material ColorCompose_URP;
// Buffers
public static ComputeBuffer PointDistributionBuffer;
public static ComputeBuffer LuminanceMoments;
public static ComputeBuffer IndirectArguments;
public static ComputeBuffer RayCounter;
public static HDynamicBuffer IndirectCoords;
// Variables
public static RenderTexture finalOutput;
internal struct HistoryData : IHistoryData
{
public bool RecurrentBlur;
public float ScaleFactor;
public void Update()
{
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
RecurrentBlur = profile.DenoisingSettings.RecurrentBlur;
ScaleFactor = Mathf.Round(1.0f / profile.SSGISettings.RenderScale * 100f) / 100f;
}
}
internal static HistoryData History = new HistoryData();
internal static void Execute(CommandBuffer cmd, Camera camera, int cameraWidth, int cameraHeight, RTHandle cameraColorBuffer = null, RTHandle previousColorBuffer = null)
{
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
bool UseAPV = false;
bool UseInterpolation = Mathf.Approximately(profile.SSGISettings.RenderScale, 1.0f) ? false : true;
float RenderScaleFactor = (Mathf.Round(1.0f / profile.SSGISettings.RenderScale * 100f) / 100f);
// Depth to PositionVS parameters
float FovRadians = camera.fieldOfView * Mathf.Deg2Rad;
float TanHalfFOVY = Mathf.Tan(FovRadians * 0.5f);
float invHalfTanFov = 1 / TanHalfFOVY;
Vector2 focalLen = new Vector2(invHalfTanFov * ((float)cameraWidth / (float)cameraWidth), invHalfTanFov);
Vector2 invFocalLen = new Vector2(1 / focalLen.x, 1 / focalLen.y);
Vector4 DepthToViewParams = new Vector4(2 * invFocalLen.x, 2 * invFocalLen.y, -1 * invFocalLen.x, -1 * invFocalLen.y);
// Tracing thickness management
float Thickness = Mathf.Clamp(profile.SSGISettings.Thickness, 0.05f, 1.0f);
float n = camera.nearClipPlane;
float f = camera.farClipPlane;
Vector4 ThicknessScaleBias = new Vector4();
ThicknessScaleBias.x = 1.0f / (1.0f + Thickness / 5.0f);
ThicknessScaleBias.y = -n / (f - n) * (Thickness / 5.0f * ThicknessScaleBias.x);
ThicknessScaleBias.z = 1.0f / (1.0f + Thickness / 5.0f * 2.0f);
ThicknessScaleBias.w = -n / (f - n) * (Thickness / 5.0f * 2.0f * ThicknessScaleBias.z);
if ((int)profile.SSGISettings.ThicknessMode == 1)
{
ThicknessScaleBias.x = 1.0f;
ThicknessScaleBias.y = Thickness;
ThicknessScaleBias.z = 1.0f;
ThicknessScaleBias.w = Thickness * 2.0f;
}
// Spatial radius management
float FilterRadiusReSTIR = profile.DenoisingSettings.SpatialRadius - 0.25f; // HData.DenoisingData.SpatialRadius / 2.0f;
float FilterRadiusDenoiser = FilterRadiusReSTIR * 0.7f;
FilterRadiusReSTIR = FilterRadiusReSTIR.RoundToCeilTail(1);
FilterRadiusDenoiser = FilterRadiusDenoiser.RoundToCeilTail(1);
// ---------------------------------------- PARAMETERS SET ---------------------------------------- //
cmd.SetGlobalVector(_DepthToViewParams, DepthToViewParams);
cmd.SetGlobalFloat(_HScaleFactorSSGI, RenderScaleFactor);
cmd.SetGlobalFloat(_HPreviousScaleFactorSSGI, History.ScaleFactor);
cmd.SetGlobalFloat(_ReservoirDiffuseWeight, profile.GeneralSettings.DebugMode == DebugMode.GlobalIllumination ? 0.0f : 1.0f);
#if UNITY_2023_3_OR_NEWER
cmd.SetGlobalInt(_ExcludeCastingLayerMaskSSGI, profile.GeneralSettings.ExcludeCastingMask);
cmd.SetGlobalInt(_ExcludeReceivingLayerMaskSSGI, profile.GeneralSettings.ExcludeReceivingMask);
#endif
cmd.SetGlobalVector(_APVParams, new Vector4(profile.GeneralSettings.NormalBias, profile.GeneralSettings.ViewBias, profile.GeneralSettings.SamplingNoise, profile.GeneralSettings.IntensityMultiplier));
cmd.SetComputeFloatParam(HTemporalReprojection, _BrightnessClamp, profile.DenoisingSettings.MaxValueBrightnessClamp);
cmd.SetComputeFloatParam(HTemporalReprojection, _MaxDeviation, profile.DenoisingSettings.MaxDeviationBrightnessClamp);
cmd.SetComputeIntParam(HRenderSSGI, _RayCount, profile.SSGISettings.RayCount);
cmd.SetComputeIntParam(HRenderSSGI, _StepCount, profile.SSGISettings.StepCount);
cmd.SetComputeFloatParam(HRenderSSGI, _RayLength, Mathf.Max(profile.SSGISettings.MaxRayLength, 0.1f));
cmd.SetComputeFloatParam(HRenderSSGI, _BackfaceLighting, profile.SSGISettings.BackfaceLighting);
cmd.SetComputeFloatParam(HRenderSSGI, _SkyFallbackIntensity, profile.GeneralSettings.SkyIntensity);
cmd.SetComputeFloatParam(HRenderSSGI, _Falloff, profile.SSGISettings.Falloff);
cmd.SetComputeVectorParam(HRenderSSGI, _ThicknessParams, ThicknessScaleBias);
cmd.SetComputeIntParam(HReSTIR, _DenoiseFallback, (profile.GeneralSettings.DenoiseFallback || profile.GeneralSettings.FallbackType == FallbackType.None) ? 1 : 0);
cmd.SetComputeIntParam(HReSTIR, _RayCount, profile.SSGISettings.RayCount);
cmd.SetComputeIntParam(HReSTIR, _StepCount, profile.SSGISettings.StepCount);
cmd.SetComputeFloatParam(HReSTIR, _RayLength, Mathf.Max(profile.SSGISettings.MaxRayLength, 0.1f));
cmd.SetComputeFloatParam(HReSTIR, _BackfaceLighting, profile.SSGISettings.BackfaceLighting);
cmd.SetComputeFloatParam(HReSTIR, _FilterAdaptivity, profile.DenoisingSettings.Adaptivity);
cmd.SetComputeFloatParam(HReSTIR, _Falloff, profile.SSGISettings.Falloff);
cmd.SetComputeFloatParam(HReSTIR, _FilterRadius, FilterRadiusReSTIR);
cmd.SetComputeVectorParam(HReSTIR, _ThicknessParams, ThicknessScaleBias);
cmd.SetComputeFloatParam(HDenoiser, _FilterAdaptivity, profile.DenoisingSettings.Adaptivity);
cmd.SetComputeFloatParam(HDenoiser, _FilterRadius, FilterRadiusDenoiser);
cmd.SetComputeFloatParam(HDenoiser, _StepCount, profile.SSGISettings.StepCount);
RTWrapper ColorPreviousFrame = CameraHistorySystem.GetCameraData().ColorPreviousFrame;
RTWrapper ReservoirTemporal = CameraHistorySystem.GetCameraData().ReservoirTemporal;
RTWrapper SampleCount = CameraHistorySystem.GetCameraData().SampleCount;
RTWrapper NormalDepth = CameraHistorySystem.GetCameraData().NormalDepth;
RTWrapper NormalDepthFullRes = CameraHistorySystem.GetCameraData().NormalDepthFullRes;
RTWrapper Radiance = CameraHistorySystem.GetCameraData().Radiance;
RTWrapper RadianceAccumulated = CameraHistorySystem.GetCameraData().RadianceAccumulated;
RTWrapper SpatialOcclusionAccumulated = CameraHistorySystem.GetCameraData().SpatialOcclusionAccumulated;
RTWrapper TemporalInvalidityAccumulated = CameraHistorySystem.GetCameraData().TemporalInvalidityAccumulated;
RTWrapper AmbientOcclusionAccumulated = CameraHistorySystem.GetCameraData().AmbientOcclusionAccumulated;
// ---------------------------------------- TEMPORAL REPROJECTION ---------------------------------------- //
using (new ProfilingScope(cmd, TemporalReprojectionSampler))
{
var CurrentColorBuffer = ColorPreviousFrame.rt;
var PreviousColorBuffer = ColorPreviousFrame.rt;
CurrentColorBuffer = cameraColorBuffer;
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.LuminanceMomentsGeneration, _Color_History, profile.GeneralSettings.Multibounce ? PreviousColorBuffer : CurrentColorBuffer);
cmd.SetComputeBufferParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.LuminanceMomentsGeneration, _LuminanceMoments, LuminanceMoments);
cmd.DispatchCompute(HTemporalReprojection, (int)HTemporalReprojectionKernels.LuminanceMomentsGeneration, Mathf.CeilToInt(cameraWidth / 8.0f), Mathf.CeilToInt(cameraHeight / 8.0f), 1);
KeywordSwitch(HTemporalReprojection, profile.DenoisingSettings.TemporalLightingValidation | profile.DenoisingSettings.TemporalOcclusionValidation, REPROJECT_TEMPORAL_INVALIDITY);
KeywordSwitch(HTemporalReprojection, profile.DenoisingSettings.BrightnessClamp == BrightnessClamp.Automatic, AUTOMATIC_BRIGHTNESS_CLAMP);
KeywordSwitch(HTemporalReprojection, profile.DenoisingSettings.SpatialOcclusionValidation, REPROJECT_SPATIAL_OCCLUSION);
KeywordSwitch(HTemporalReprojection, UseInterpolation == false, FULL_RESOLUTION_REPROJECTION);
KeywordSwitch(HTemporalReprojection, profile.GeneralSettings.Multibounce, REPROJECT_COLOR);
if (UseInterpolation)
{
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.ColorReprojection, _Color_History, PreviousColorBuffer);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.ColorReprojection, _Radiance_History, RadianceStabilized.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.ColorReprojection, _Radiance_Output, RadianceStabilizedReprojected.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.ColorReprojection, _NormalDepth_History, NormalDepthFullRes.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.ColorReprojection, _ReprojectedColor_Output, ColorReprojected.rt);
cmd.SetComputeBufferParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.ColorReprojection, _LuminanceMoments, LuminanceMoments);
cmd.DispatchCompute(HTemporalReprojection, (int)HTemporalReprojectionKernels.ColorReprojection, Mathf.CeilToInt(cameraWidth / 8.0f), Mathf.CeilToInt(cameraHeight / 8.0f), HRenderer.TextureXrSlices);
}
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _Color_History, PreviousColorBuffer);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _Samplecount_History, SampleCount.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _Samplecount_Output, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _NormalDepth_History, NormalDepth.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _ReprojectedColor_Output, ColorReprojected.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _Radiance_Output, RadianceReprojected.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _Radiance_History, profile.DenoisingSettings.RecurrentBlur ? Radiance.rt : RadianceAccumulated.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _SpatialOcclusion_History, SpatialOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _SpatialOcclusion_Output, SpatialOcclusionReprojected.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _Reservoir, ReservoirTemporal.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _Reservoir_Output, ReservoirReprojected.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _TemporalInvalidity_History, TemporalInvalidityAccumulated.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _TemporalInvalidity_Output, TemporalInvalidityReprojected.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _AmbientOcclusion_History, AmbientOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _AmbientOcclusion_Output, AmbientOcclusionReprojected.rt);
cmd.SetComputeBufferParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, _LuminanceMoments, LuminanceMoments);
cmd.DispatchCompute(HTemporalReprojection, (int)HTemporalReprojectionKernels.TemporalReprojection, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
cmd.SetComputeBufferParam(HTemporalReprojection, (int)HTemporalReprojectionKernels.LuminanceMomentsClear, _LuminanceMoments, LuminanceMoments);
cmd.DispatchCompute(HTemporalReprojection, (int)HTemporalReprojectionKernels.LuminanceMomentsClear, 1, 1, 1);
}
// ---------------------------------------- CHECKERBOARDING ---------------------------------------- //
if (profile.SSGISettings.Checkerboard)
{
using (new ProfilingScope(cmd, CheckerboardingSampler))
{
cmd.SetComputeTextureParam(HCheckerboarding, (int)HCheckerboardingKernels.CheckerboardClassification, _SampleCount, SamplecountReprojected.rt);
cmd.SetComputeBufferParam(HCheckerboarding, (int)HCheckerboardingKernels.CheckerboardClassification, _RayCounter_Output, RayCounter);
cmd.SetComputeBufferParam(HCheckerboarding, (int)HCheckerboardingKernels.CheckerboardClassification, _IndirectCoords_Output, IndirectCoords.ComputeBuffer);
cmd.DispatchCompute(HCheckerboarding, (int)HCheckerboardingKernels.CheckerboardClassification, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
cmd.SetComputeIntParam(HCheckerboarding, _RayTracedCounter, 0);
cmd.SetComputeBufferParam(HCheckerboarding, (int)HCheckerboardingKernels.IndirectArguments, _RayCounter, RayCounter);
cmd.SetComputeBufferParam(HCheckerboarding, (int)HCheckerboardingKernels.IndirectArguments, _IndirectArguments_Output, IndirectArguments);
cmd.DispatchCompute(HCheckerboarding, (int)HCheckerboardingKernels.IndirectArguments, 1, 1, HRenderer.TextureXrSlices);
}
}
// ---------------------------------------- GI TRACING ---------------------------------------- //
using (new ProfilingScope(cmd, RadianceTracingSampler))
{
CoreUtils.SetRenderTarget(cmd, RadianceFiltered.rt, ClearFlag.Color, Color.clear, 0, CubemapFace.Unknown, -1);
KeywordSwitch(HRenderSSGI, profile.GeneralSettings.FallbackType == FallbackType.Sky, FALLBACK_SKY);
KeywordSwitch(HRenderSSGI, (int)profile.GeneralSettings.FallbackType == 2 /* Only in HDRP & URP 6000+ */, FALLBACK_APV);
KeywordSwitch(HRenderSSGI, profile.SSGISettings.Checkerboard, CHECKERBOARDING);
KeywordSwitch(HRenderSSGI, profile.SSGISettings.RefineIntersection, REFINE_INTERSECTION);
KeywordSwitch(HRenderSSGI, profile.SSGISettings.FullResolutionDepth, FULL_RESOLUTION_DEPTH);
if ((int)profile.SSGISettings.ThicknessMode == 0) {HRenderSSGI.EnableKeyword(LINEAR_THICKNESS); HRenderSSGI.DisableKeyword(UNIFORM_THICKNESS); HRenderSSGI.DisableKeyword(AUTOMATIC_THICKNESS);}
if ((int)profile.SSGISettings.ThicknessMode == 1) {HRenderSSGI.EnableKeyword(UNIFORM_THICKNESS); HRenderSSGI.DisableKeyword(LINEAR_THICKNESS); HRenderSSGI.DisableKeyword(AUTOMATIC_THICKNESS);}
cmd.SetComputeTextureParam(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, _Color, ColorReprojected.rt);
cmd.SetComputeTextureParam(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, _Radiance_Output, RadianceFiltered.rt);
cmd.SetComputeTextureParam(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, _Reservoir_Output, Reservoir.rt);
cmd.SetComputeTextureParam(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, _AmbientOcclusion_Output, AmbientOcclusion.rt);
cmd.SetComputeTextureParam(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, _SampleCount, SamplecountReprojected.rt);
cmd.SetComputeBufferParam(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, _RayCounter, RayCounter);
cmd.SetComputeBufferParam(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, _TracingCoords, IndirectCoords.ComputeBuffer);
if (profile.SSGISettings.Checkerboard)
{
cmd.SetComputeIntParam(HRenderSSGI, HShaderParams.IndexXR, 0);
cmd.DispatchCompute(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, IndirectArguments, 0);
if (HRenderer.TextureXrSlices > 1)
{
cmd.SetComputeIntParam(HRenderSSGI, HShaderParams.IndexXR, 1);
cmd.DispatchCompute(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, IndirectArguments, sizeof(uint) * 3);
}
}
else cmd.DispatchCompute(HRenderSSGI, (int)HRenderSSGIKernels.TraceSSGI, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
}
// ---------------------------------------- RESTIR TEMPORAL ---------------------------------------- //
using (new ProfilingScope(cmd, RestirTemporalSampler))
{
KeywordSwitch(HReSTIR, profile.DenoisingSettings.TemporalOcclusionValidation, VALIDATE_TEMPORAL_OCCLUSION);
KeywordSwitch(HReSTIR, profile.DenoisingSettings.TemporalLightingValidation, VALIDATE_TEMPORAL_LIGHTING);
KeywordSwitch(HReSTIR, profile.DenoisingSettings.HalfStepValidation, HALF_STEP_VALIDATION);
KeywordSwitch(HReSTIR, profile.SSGISettings.FullResolutionDepth, FULL_RESOLUTION_DEPTH);
KeywordSwitch(HReSTIR, profile.SSGISettings.Checkerboard, CHECKERBOARDING);
if ((int)profile.SSGISettings.ThicknessMode == 0) {HReSTIR.EnableKeyword(LINEAR_THICKNESS); HReSTIR.DisableKeyword(UNIFORM_THICKNESS); HReSTIR.DisableKeyword(AUTOMATIC_THICKNESS);}
if ((int)profile.SSGISettings.ThicknessMode == 1) {HReSTIR.EnableKeyword(UNIFORM_THICKNESS); HReSTIR.DisableKeyword(LINEAR_THICKNESS); HReSTIR.DisableKeyword(AUTOMATIC_THICKNESS);}
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _Radiance_Output, RadianceFiltered.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _SampleCount, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _Color, ColorReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _AmbientOcclusion, AmbientOcclusion.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _AmbientOcclusionInvalidity, AmbientOcclusionInvalidity.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _AmbientOcclusionReprojected, AmbientOcclusionReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _AmbientOcclusion_Output, AmbientOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _SpatialOcclusion, SpatialOcclusionReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _Reservoir, Reservoir.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _ReservoirReprojected, ReservoirReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _ReservoirSpatial_Output, ReservoirSpatial.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _ReservoirTemporal_Output, ReservoirTemporal.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _TemporalInvalidity, TemporalInvalidityReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _TemporalInvalidity_Output, TemporalInvalidityAccumulated.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _NormalDepth_HistoryOutput, NormalDepth.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _ReservoirLuminance_Output, ReservoirLuminance.rt);
cmd.SetComputeBufferParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _RayCounter, RayCounter);
cmd.SetComputeBufferParam(HReSTIR, (int)HReSTIRKernels.TemporalResampling, _TracingCoords, IndirectCoords.ComputeBuffer);
cmd.DispatchCompute(HReSTIR, (int)HReSTIRKernels.TemporalResampling, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
}
// ---------------------------------------- RESTIR FIREFLY ---------------------------------------- //
using (new ProfilingScope(cmd, RestirFireflySampler))
{
if (profile.DenoisingSettings.FireflySuppression)
{
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.FireflySuppression, _SampleCount, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.FireflySuppression, _ReservoirLuminance, ReservoirLuminance.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.FireflySuppression, _ReservoirSpatial_Output, ReservoirSpatial.rt);
cmd.DispatchCompute(HReSTIR, (int)HReSTIRKernels.FireflySuppression, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
}
}
// ---------------------------------------- RESTIR SPATIAL ---------------------------------------- //
using (new ProfilingScope(cmd, RestirSpatialSampler))
{
KeywordSwitch(HReSTIR, profile.DenoisingSettings.SpatialOcclusionValidation, VALIDATE_SPATIAL_OCCLUSION);
KeywordSwitch(HReSTIR, HRenderer.TextureXrSlices > 1, VR_COMPATIBILITY);
cmd.SetComputeBufferParam(HDenoiser, (int)HDenoiserKernels.PointDistributionFill, _PointDistribution_Output, PointDistributionBuffer);
cmd.DispatchCompute(HDenoiser, (int)HDenoiserKernels.PointDistributionFill, 1, 1, 1);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _Reservoir, ReservoirSpatial.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _Reservoir_Output, Reservoir.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _SampleCount, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _TemporalInvalidity, TemporalInvalidityAccumulated.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _TemporalInvalidity_Output, TemporalInvalidityFilteredA.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _AmbientOcclusion, AmbientOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _SpatialGuidance_Output, AmbientOcclusionGuidance.rt);
cmd.SetComputeBufferParam(HReSTIR, (int)HReSTIRKernels.SpatialResampling, _PointDistribution, PointDistributionBuffer);
cmd.DispatchCompute(HReSTIR, (int)HReSTIRKernels.SpatialResampling, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _Color, ColorReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _Radiance_Output, Radiance.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _SampleCount, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _AmbientOcclusion, AmbientOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _Reservoir, Reservoir.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _Reservoir_Output, ReservoirSpatial.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _SpatialOcclusion, SpatialOcclusionReprojected.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _SpatialOcclusion_Output, SpatialOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _TemporalInvalidity, TemporalInvalidityFilteredA.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _TemporalInvalidity_Output, TemporalInvalidityFilteredB.rt);
cmd.SetComputeTextureParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _SpatialGuidance, AmbientOcclusionGuidance.rt);
cmd.SetComputeBufferParam(HReSTIR, (int)HReSTIRKernels.SpatialValidation, _PointDistribution, PointDistributionBuffer);
cmd.DispatchCompute(HReSTIR, (int)HReSTIRKernels.SpatialValidation, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
}
// ---------------------------------------- DENOISER TEMPORAL ---------------------------------------- //
using (new ProfilingScope(cmd, TemporalAccumulationSampler))
{
KeywordSwitch(HDenoiser, profile.DenoisingSettings.TemporalLightingValidation | profile.DenoisingSettings.TemporalOcclusionValidation, USE_TEMPORAL_INVALIDITY);
KeywordSwitch(HDenoiser, HRenderer.TextureXrSlices > 1, VR_COMPATIBILITY);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, _TemporalInvalidity, TemporalInvalidityFilteredB.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, _SamplecountReprojected, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, _Samplecount_Output, SampleCount.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, _Radiance, Radiance.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, _RadianceReprojected, RadianceReprojected.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, _Radiance_TemporalOutput, RadianceAccumulated.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, _Radiance_SpatialOutput, RadianceFiltered.rt);
cmd.DispatchCompute(HDenoiser, (int)HDenoiserKernels.TemporalAccumulation, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
}
// ---------------------------------------- DENOISER SPATIAL ---------------------------------------- //
using (new ProfilingScope(cmd, SpatialFilterSampler))
{
KeywordSwitch(HDenoiser, profile.DenoisingSettings.SpatialOcclusionValidation, USE_SPATIAL_OCCLUSION);
KeywordSwitch(HDenoiser, UseInterpolation, INTERPOLATION_OUTPUT);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, _NormalDepth, NormalDepth.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, _SpatialGuidance, AmbientOcclusionGuidance.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, _AmbientOcclusion, AmbientOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, _Radiance, RadianceFiltered.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, _Radiance_Output, Radiance.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, _SpatialOcclusion, SpatialOcclusionAccumulated.rt);
cmd.SetComputeBufferParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, _PointDistribution, PointDistributionBuffer);
cmd.DispatchCompute(HDenoiser, (int)HDenoiserKernels.SpatialFilter1, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _NormalDepth, NormalDepth.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _SpatialGuidance, AmbientOcclusionGuidance.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _AmbientOcclusion, AmbientOcclusionAccumulated.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _Radiance, Radiance.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _Radiance_Output, RadianceFiltered.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _RadianceNormalDepth_Output, RadianceNormalDepth.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _SpatialOcclusion, SpatialOcclusionAccumulated.rt);
cmd.SetComputeBufferParam(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, _PointDistribution, PointDistributionBuffer);
cmd.DispatchCompute(HDenoiser, (int)HDenoiserKernels.SpatialFilter2, Mathf.CeilToInt(cameraWidth / RenderScaleFactor / 8.0f), Mathf.CeilToInt(cameraHeight / RenderScaleFactor / 8.0f), HRenderer.TextureXrSlices);
}
// ---------------------------------------- INTERPOLATION SPATIAL ---------------------------------------- //
using (new ProfilingScope(cmd, InterpolationSampler))
{
if (UseInterpolation)
{
KeywordSwitch(HInterpolation, HRenderer.TextureXrSlices > 1, VR_COMPATIBILITY);
// Interpolation
cmd.SetComputeTextureParam(HInterpolation, (int)HInterpolationKernels.Interpolation, _RadianceNormalDepth, RadianceNormalDepth.rt);
cmd.SetComputeTextureParam(HInterpolation, (int)HInterpolationKernels.Interpolation, _Radiance_Output, RadianceInterpolated.rt);
cmd.SetComputeTextureParam(HInterpolation, (int)HInterpolationKernels.Interpolation, _NormalDepth_HistoryOutput, NormalDepthFullRes.rt);
cmd.DispatchCompute(HInterpolation, (int)HInterpolationKernels.Interpolation, Mathf.CeilToInt(cameraWidth / 8.0f), Mathf.CeilToInt(cameraHeight / 8.0f), HRenderer.TextureXrSlices);
// Stabilization
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalStabilization, _TemporalInvalidity, TemporalInvalidityFilteredB.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalStabilization, _SamplecountReprojected, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalStabilization, _Radiance, RadianceInterpolated.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalStabilization, _RadianceReprojected, RadianceStabilizedReprojected.rt);
cmd.SetComputeTextureParam(HDenoiser, (int)HDenoiserKernels.TemporalStabilization, _Radiance_TemporalOutput, RadianceStabilized.rt);
cmd.DispatchCompute(HDenoiser, (int)HDenoiserKernels.TemporalStabilization, Mathf.CeilToInt(cameraWidth / 8.0f), Mathf.CeilToInt(cameraHeight / 8.0f), HRenderer.TextureXrSlices);
}
}
finalOutput = Mathf.Approximately(profile.SSGISettings.RenderScale, 1.0f) ? SSGI.RadianceFiltered.rt : SSGI.RadianceInterpolated.rt;
// --------------------------------------------- DEBUG ----------------------------------------------- //
using (new ProfilingScope(cmd, DebugSampler))
{
if (profile.GeneralSettings.DebugMode != DebugMode.None && profile.GeneralSettings.DebugMode != DebugMode.DirectLighting)
{
cmd.SetComputeIntParams(HDebug, _DebugSwitch, (int)profile.GeneralSettings.DebugMode);
cmd.SetComputeIntParams(HDebug, _BuffersSwitch, (int)profile.GeneralSettings.HBuffer);
cmd.SetComputeTextureParam(HDebug, 0, _Debug_Output, DebugOutput.rt);
cmd.SetComputeTextureParam(HDebug, 0, _SampleCountSSGI, SamplecountReprojected.rt);
cmd.SetComputeTextureParam(HDebug, 0, _HTraceBufferGI, finalOutput);
cmd.DispatchCompute(HDebug, 0, Mathf.CeilToInt(cameraWidth / 8.0f), Mathf.CeilToInt(cameraHeight / 8.0f), HRenderer.TextureXrSlices);
cmd.SetGlobalTexture(_Debug_Output, DebugOutput.rt);
}
}
}
private static void KeywordSwitch(ComputeShader compute, bool state, string keyword)
{
if (state)
compute.EnableKeyword(keyword);
else
compute.DisableKeyword(keyword);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 899f5117c46144a4bd16bfff7845aff3
timeCreated: 1745928754
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Passes/Shared/SSGI.cs
uploadId: 840002

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e4b8bb5cb72847444bf29135c1e77513
timeCreated: 1729952262

View File

@@ -0,0 +1,110 @@
//pipelinedefine
#define H_URP
using HTraceSSGI.Scripts.Data.Private;
using HTraceSSGI.Scripts.Data.Public;
using HTraceSSGI.Scripts.Passes.Shared;
using HTraceSSGI.Scripts.Extensions;
using HTraceSSGI.Scripts.Globals;
using HTraceSSGI.Scripts.Infrastructure.URP;
using HTraceSSGI.Scripts.Wrappers;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
#if UNITY_2023_3_OR_NEWER
using UnityEngine.Rendering.RenderGraphModule;
#endif
namespace HTraceSSGI.Scripts.Passes.URP
{
internal class FinalPassURP : ScriptableRenderPass
{
private ScriptableRenderer _renderer;
#region --------------------------- Non Render Graph ---------------------------
protected internal void Initialize(ScriptableRenderer renderer)
{
_renderer = renderer;
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cmd = CommandBufferPool.Get(HNames.HTRACE_FINAL_PASS_NAME);
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
if (profile.GeneralSettings.DebugMode != DebugMode.None && profile.GeneralSettings.DebugMode != DebugMode.DirectLighting)
{
Blitter.BlitCameraTexture(cmd, SSGI.DebugOutput.rt, _renderer.cameraColorTargetHandle);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
#endregion --------------------------- Non Render Graph ---------------------------
#region --------------------------- Render Graph ---------------------------
#if UNITY_2023_3_OR_NEWER
private class PassData
{
public TextureHandle ColorTexture;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
using (var builder = renderGraph.AddUnsafePass<PassData>(HNames.HTRACE_FINAL_PASS_NAME, out var passData, new ProfilingSampler(HNames.HTRACE_FINAL_PASS_NAME)))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalRenderingData universalRenderingData = frameData.Get<UniversalRenderingData>();
builder.AllowGlobalStateModification(true);
builder.AllowPassCulling(false);
passData.ColorTexture = universalRenderingData.renderingMode == RenderingMode.Deferred ? resourceData.activeColorTexture : resourceData.cameraColor;
builder.SetRenderFunc((PassData data, UnsafeGraphContext context) => ExecutePass(data, context));
}
}
private static void ExecutePass(PassData data, UnsafeGraphContext rgContext)
{
var cmd = CommandBufferHelpers.GetNativeCommandBuffer(rgContext.cmd);
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
if (profile.GeneralSettings.DebugMode != DebugMode.None && profile.GeneralSettings.DebugMode != DebugMode.DirectLighting)
{
Blitter.BlitCameraTexture(cmd, SSGI.DebugOutput.rt, data.ColorTexture);
}
}
#endif
#endregion --------------------------- Render Graph ---------------------------
#region --------------------------- Shared ---------------------------
protected internal void Dispose()
{
}
#endregion --------------------------- Shared ---------------------------
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 38d0808db5cb55c4b820dedf6eaec8aa
timeCreated: 1729952288
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Passes/URP/FinalPassURP.cs
uploadId: 840002

View File

@@ -0,0 +1,498 @@
//pipelinedefine
#define H_URP
using HTraceSSGI.Scripts.Data.Private;
using HTraceSSGI.Scripts.Data.Public;
using HTraceSSGI.Scripts.Extensions;
using HTraceSSGI.Scripts.Globals;
using HTraceSSGI.Scripts.Infrastructure.URP;
using HTraceSSGI.Scripts.Wrappers;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Rendering.RendererUtils;
using UnityEngine.Rendering.Universal;
#if UNITY_2023_3_OR_NEWER
using UnityEngine.Rendering.RenderGraphModule;
#endif
namespace HTraceSSGI.Scripts.Passes.URP
{
internal class GBufferPassURP : ScriptableRenderPass
{
// Texture Names
private const string _Dummy = "_Dummy";
private const string _DepthPyramid = "_DepthPyramid";
private const string _ForwardGBuffer0 = "_ForwardGBuffer0";
private const string _ForwardGBuffer1 = "_ForwardGBuffer1";
private const string _ForwardGBuffer2 = "_ForwardGBuffer2";
private const string _ForwardGBuffer3 = "_ForwardGBuffer3";
private const string _ForwardRenderLayerMask = "_ForwardRenderLayerMask";
private const string _ForwardGBufferDepth = "_ForwardGBufferDepth";
// Materials & Computes
internal static ComputeShader HDepthPyramid = null;
// Samplers
internal static readonly ProfilingSampler GBufferProfilingSampler = new("GBuffer");
private static readonly ProfilingSampler DepthPyramidGenerationProfilingSampler = new ProfilingSampler("Depth Pyramid Generation");
// Textures
internal static RTWrapper Dummy = new RTWrapper();
internal static RTWrapper ForwardGBuffer0 = new RTWrapper();
internal static RTWrapper ForwardGBuffer1 = new RTWrapper();
internal static RTWrapper ForwardGBuffer2 = new RTWrapper();
internal static RTWrapper ForwardGBuffer3 = new RTWrapper();
internal static RTWrapper ForwardRenderLayerMask = new RTWrapper();
internal static RTWrapper ForwardGBufferDepth = new RTWrapper();
internal static RTWrapper DepthPyramidRT = new RTWrapper();
// MRT Arrays
internal static RenderTargetIdentifier[] GBufferMRT = null;
// Misc
internal static RenderStateBlock ForwardGBufferRenderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
#region --------------------------- Non Render Graph ---------------------------
private ScriptableRenderer _renderer;
protected internal void Initialize(ScriptableRenderer renderer)
{
_renderer = renderer;
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
Setup(renderingData.cameraData.camera, renderingData.cameraData.renderScale, renderingData.cameraData.cameraTargetDescriptor);
}
private static void Setup(Camera camera, float renderScale, RenderTextureDescriptor desc)
{
if (HDepthPyramid == null) HDepthPyramid = HExtensions.LoadComputeShader("HDepthPyramid");
int width = (int)(camera.scaledPixelWidth * renderScale);
int height = (int)(camera.scaledPixelHeight * renderScale);
if (desc.width != width || desc.height != height)
desc = new RenderTextureDescriptor(width, height);
desc.depthBufferBits = 0; // Color and depth cannot be combined in RTHandles
desc.stencilFormat = GraphicsFormat.None;
desc.depthStencilFormat = GraphicsFormat.None;
desc.msaaSamples = 1;
desc.bindMS = false;
var graphicsFormatRenderingLayerMask = GraphicsFormat.R8G8B8A8_UNorm;
#if UNITY_6000_2_OR_NEWER
graphicsFormatRenderingLayerMask = GraphicsFormat.R8G8_UInt;
#endif
ForwardGBuffer0.ReAllocateIfNeeded(_ForwardGBuffer0, ref desc, graphicsFormat: GraphicsFormat.R8G8B8A8_SRGB);
ForwardGBuffer1.ReAllocateIfNeeded(_ForwardGBuffer1, ref desc, graphicsFormat: GraphicsFormat.R8G8B8A8_UNorm);
ForwardGBuffer2.ReAllocateIfNeeded(_ForwardGBuffer2, ref desc, graphicsFormat: GraphicsFormat.R8G8B8A8_SNorm);
ForwardGBuffer3.ReAllocateIfNeeded(_ForwardGBuffer3, ref desc, graphicsFormat: GraphicsFormat.B10G11R11_UFloatPack32);
ForwardRenderLayerMask.ReAllocateIfNeeded(_ForwardRenderLayerMask, ref desc, graphicsFormat: graphicsFormatRenderingLayerMask);
DepthPyramidRT.ReAllocateIfNeeded(_DepthPyramid, ref desc, graphicsFormat: GraphicsFormat.R16_SFloat, useMipMap: true);
RenderTextureDescriptor depthDesc = desc;
depthDesc.depthBufferBits = 32;
depthDesc.depthStencilFormat = GraphicsFormat.None;
ForwardGBufferDepth.ReAllocateIfNeeded(_ForwardGBufferDepth, ref depthDesc, graphicsFormat: GraphicsFormat.R16_SFloat, useMipMap: false, enableRandomWrite: false);
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
var cmd = CommandBufferPool.Get(HNames.HTRACE_GBUFFER_PASS_NAME);
int width = (int)(camera.scaledPixelWidth * renderingData.cameraData.renderScale);
int height = (int)(camera.scaledPixelHeight * renderingData.cameraData.renderScale);
var nativeGBuffer0 = Shader.GetGlobalTexture(HShaderParams._GBuffer0);
var nativeGBuffer1 = Shader.GetGlobalTexture(HShaderParams._GBuffer1);
var nativeGBuffer2 = Shader.GetGlobalTexture(HShaderParams._GBuffer2);
var renderLayerMaskTexture = Shader.GetGlobalTexture(HShaderParams._CameraRenderingLayersTexture);
var screenSpaceOcclusionTexture = Shader.GetGlobalTexture(HShaderParams.g_ScreenSpaceOcclusionTexture);
// Set Depth, Color and SSAO to HTrace passes
cmd.SetGlobalTexture(HShaderParams.g_HTraceColor, _renderer.cameraColorTargetHandle);
cmd.SetGlobalTexture(HShaderParams.g_HTraceDepth, _renderer.cameraDepthTargetHandle);
cmd.SetGlobalTexture(HShaderParams.g_HTraceSSAO, screenSpaceOcclusionTexture == null ? Texture2D.whiteTexture : screenSpaceOcclusionTexture);
GBufferGenerationNonRenderGraph(cmd, width, height, nativeGBuffer0, nativeGBuffer1, nativeGBuffer2, renderLayerMaskTexture, _renderer.cameraColorTargetHandle, _renderer.cameraDepthTargetHandle, ref context, ref renderingData);
GenerateDepthPyramidShared(cmd, width, height, DepthPyramidRT.rt);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
private static void GBufferGenerationNonRenderGraph(CommandBuffer cmd, int width, int height, Texture nativeGBuffer0, Texture nativeGBuffer1,
Texture nativeGBuffer2, Texture renderLayerMask, RTHandle cameraColorBuffer, RTHandle cameraDepthBuffer,
ref ScriptableRenderContext context, ref RenderingData renderingData)
{
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
var camera = renderingData.cameraData.camera;
using (new ProfilingScope(cmd, GBufferProfilingSampler))
{
// Set sky probe management
SphericalHarmonicsL2 ambientProbe = RenderSettings.ambientProbe;
cmd.SetGlobalVector(HShaderParams.H_SHAr, new Vector4(ambientProbe[0, 3], ambientProbe[0, 1], ambientProbe[0, 2], ambientProbe[0, 0] - ambientProbe[0, 6]));
cmd.SetGlobalVector(HShaderParams.H_SHAg, new Vector4(ambientProbe[1, 3], ambientProbe[1, 1], ambientProbe[1, 2], ambientProbe[1, 0] - ambientProbe[1, 6]));
cmd.SetGlobalVector(HShaderParams.H_SHAb, new Vector4(ambientProbe[2, 3], ambientProbe[2, 1], ambientProbe[2, 2], ambientProbe[2, 0] - ambientProbe[2, 6]));
cmd.SetGlobalVector(HShaderParams.H_SHBr, new Vector4(ambientProbe[0, 4], ambientProbe[0, 5], ambientProbe[0, 6] * 3, ambientProbe[0, 7]));
cmd.SetGlobalVector(HShaderParams.H_SHBg, new Vector4(ambientProbe[1, 4], ambientProbe[1, 5], ambientProbe[1, 6] * 3, ambientProbe[1, 7]));
cmd.SetGlobalVector(HShaderParams.H_SHBb, new Vector4(ambientProbe[2, 4], ambientProbe[2, 5], ambientProbe[2, 6] * 3, ambientProbe[2, 7]));
cmd.SetGlobalVector(HShaderParams.H_SHC, new Vector4(ambientProbe[0, 8], ambientProbe[1, 8], ambientProbe[2, 8], 1));
// Check if GBuffer is valid (e.g. Forward / wrong scale / is not set, etc.)
bool RequestForwardGBufferRender = false;
if (nativeGBuffer0 == null || nativeGBuffer1 == null || nativeGBuffer2 == null)
{ RequestForwardGBufferRender = true; }
else if ( nativeGBuffer0.width != width || nativeGBuffer0.height != height) // CameraDepthBuffer.rtHandleProperties.currentViewportSize.x
{ RequestForwardGBufferRender = true; }
// Set Render Layer Mask to black dummy in case it's disabled as a feature and we can't render it
if (renderLayerMask == null)
renderLayerMask = Texture2D.blackTexture;// Dummy.rt;
// RequestForwardGBufferRender = true;
// GBuffer can't be rendered because its resolution doesn't match the resolution of Unity's depth buffer. Happens when switching between Scene and Game windows
if (ForwardGBuffer0.rt.rt.width != cameraDepthBuffer.rt.width || ForwardGBuffer0.rt.rt.height != cameraDepthBuffer.rt.height)
{
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer0, ForwardGBuffer0.rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer1, ForwardGBuffer1.rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer2, ForwardGBuffer2.rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceRenderLayerMask, ForwardRenderLayerMask.rt);
return;
}
// Set GBuffer to HTrace passes if valid or render it otherwise
if (RequestForwardGBufferRender == false)
{
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer0, nativeGBuffer0);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer1, nativeGBuffer1);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer2, nativeGBuffer2);
cmd.SetGlobalTexture(HShaderParams.g_HTraceRenderLayerMask, renderLayerMask);
}
else
{
if (HRendererURP.RenderGraphEnabled)
GBufferMRT = new RenderTargetIdentifier[] { ForwardGBuffer0.rt, ForwardGBuffer1.rt, ForwardGBuffer2.rt, ForwardGBuffer3.rt, ForwardGBufferDepth.rt, ForwardRenderLayerMask.rt };
else
GBufferMRT = new RenderTargetIdentifier[] { ForwardGBuffer0.rt, ForwardGBuffer1.rt, ForwardGBuffer2.rt, ForwardGBuffer3.rt, ForwardRenderLayerMask.rt };
// If CameraDepthBuffer.rt doesn't work for any reason - we can replace it with our ForwardGBufferDepth.rt, but GBuffer rendering performance will suffer.
CoreUtils.SetRenderTarget(cmd, GBufferMRT, cameraDepthBuffer.rt);
CullingResults cullingResults = renderingData.cullResults;
int layerMask = camera.cullingMask;
ForwardGBufferRenderStateBlock.depthState = new DepthState(false, CompareFunction.LessEqual);
ForwardGBufferRenderStateBlock.mask |= RenderStateMask.Depth;
var renderList = new UnityEngine.Rendering.RendererUtils.RendererListDesc(HShaderParams.UniversalGBufferTag, cullingResults, camera)
{
rendererConfiguration = PerObjectData.None,
renderQueueRange = RenderQueueRange.opaque,
sortingCriteria = SortingCriteria.OptimizeStateChanges,
layerMask = layerMask,
stateBlock = ForwardGBufferRenderStateBlock,
};
// Cache the current keyword state set by Unity
bool RenderLayerKeywordState = Shader.IsKeywordEnabled(HShaderParams._WRITE_RENDERING_LAYERS);
// If we don't need render layers we do not touch the keyword at all
#if UNITY_2023_3_OR_NEWER
if (profile.GeneralSettings.ExcludeReceivingMask != 0 || profile.GeneralSettings.ExcludeCastingMask != 0)
CoreUtils.SetKeyword(cmd, HShaderParams._WRITE_RENDERING_LAYERS, true);
#endif
CoreUtils.DrawRendererList(context, cmd, context.CreateRendererList(renderList));
// If we altered the keyword, we restore it to the original state
#if UNITY_2023_3_OR_NEWER
if (profile.GeneralSettings.ExcludeReceivingMask != 0 || profile.GeneralSettings.ExcludeCastingMask != 0)
CoreUtils.SetKeyword(cmd, HShaderParams._WRITE_RENDERING_LAYERS, RenderLayerKeywordState);
#endif
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer0, ForwardGBuffer0.rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer1, ForwardGBuffer1.rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer2, ForwardGBuffer2.rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceRenderLayerMask, ForwardRenderLayerMask.rt);
}
}
}
#endregion --------------------------- Non Render Graph ---------------------------
#region --------------------------- Render Graph ---------------------------
#if UNITY_2023_3_OR_NEWER
private class PassData
{
public TextureHandle[] GBufferTextures;
public TextureHandle SSAOTexture;
public TextureHandle ColorTexture;
public TextureHandle DepthTexture;
public TextureHandle NormalsTexture;
public RendererListHandle ForwardGBufferRendererListHandle;
public UniversalCameraData UniversalCameraData;
public TextureHandle ForwardGBuffer0Texture;
public TextureHandle ForwardGBuffer1Texture;
public TextureHandle ForwardGBuffer2Texture;
public TextureHandle ForwardGBuffer3Texture;
public TextureHandle ForwardRenderLayerMaskTexture;
public TextureHandle DepthPyramidTexture;
public TextureHandle DepthPyramidIntermediateTexture;
public TextureHandle ForwardGBufferDepthTexture;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
using (var builder = renderGraph.AddUnsafePass<PassData>(HNames.HTRACE_GBUFFER_PASS_NAME, out var passData, new ProfilingSampler(HNames.HTRACE_GBUFFER_PASS_NAME)))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalCameraData universalCameraData = frameData.Get<UniversalCameraData>();
UniversalRenderingData universalRenderingData = frameData.Get<UniversalRenderingData>();
UniversalLightData lightData = frameData.Get<UniversalLightData>();
builder.AllowGlobalStateModification(true);
builder.AllowPassCulling(false);
TextureHandle colorTexture = universalRenderingData.renderingMode == RenderingMode.Deferred ? resourceData.activeColorTexture : resourceData.cameraColor;
TextureHandle depthTexture = universalRenderingData.renderingMode == RenderingMode.Deferred ? resourceData.activeDepthTexture : resourceData.cameraDepth;
TextureHandle normalsTexture = resourceData.cameraNormalsTexture;
builder.UseTexture(depthTexture, AccessFlags.Read);
builder.UseTexture(normalsTexture, AccessFlags.Read);
passData.NormalsTexture = resourceData.cameraNormalsTexture;
passData.ColorTexture = colorTexture;
passData.DepthTexture = depthTexture;
passData.UniversalCameraData = universalCameraData;
passData.GBufferTextures = resourceData.gBuffer;
passData.SSAOTexture = resourceData.ssaoTexture;
if (HDepthPyramid == null) HDepthPyramid = HExtensions.LoadComputeShader("HDepthPyramid");
TextureHandle colorTextureHandle = resourceData.cameraColor;
TextureDesc desc = colorTextureHandle.GetDescriptor(renderGraph);
desc.clearBuffer = false;
TextureHandle depthTextureHandle = resourceData.cameraDepthTexture;
TextureDesc descDepth = depthTextureHandle.GetDescriptor(renderGraph);
descDepth.clearBuffer = false;
var graphicsFormatRenderingLayerMask = GraphicsFormat.R8G8B8A8_UNorm;
#if UNITY_6000_2_OR_NEWER
graphicsFormatRenderingLayerMask = GraphicsFormat.R8G8_UInt;
#endif
passData.ForwardGBuffer0Texture = ExtensionsURP.CreateTexture(_ForwardGBuffer0, renderGraph, ref desc, format: GraphicsFormat.R8G8B8A8_SRGB);
builder.UseTexture(passData.ForwardGBuffer0Texture, AccessFlags.Write);
passData.ForwardGBuffer1Texture = ExtensionsURP.CreateTexture(_ForwardGBuffer1, renderGraph, ref desc, format: GraphicsFormat.R8G8B8A8_UNorm);
builder.UseTexture(passData.ForwardGBuffer1Texture, AccessFlags.Write);
passData.ForwardGBuffer2Texture = ExtensionsURP.CreateTexture(_ForwardGBuffer2, renderGraph, ref desc, format: GraphicsFormat.R8G8B8A8_SNorm);
builder.UseTexture(passData.ForwardGBuffer2Texture, AccessFlags.Write);
passData.ForwardGBuffer3Texture = ExtensionsURP.CreateTexture(_ForwardGBuffer3, renderGraph, ref desc, format: GraphicsFormat.B10G11R11_UFloatPack32);
builder.UseTexture(passData.ForwardGBuffer3Texture, AccessFlags.Write);
passData.ForwardRenderLayerMaskTexture = ExtensionsURP.CreateTexture(_ForwardRenderLayerMask, renderGraph, ref desc, format: graphicsFormatRenderingLayerMask);
builder.UseTexture(passData.ForwardRenderLayerMaskTexture, AccessFlags.Write);
passData.DepthPyramidTexture = ExtensionsURP.CreateTexture(_DepthPyramid, renderGraph, ref desc, format: GraphicsFormat.R16_SFloat, useMipMap: true);
builder.UseTexture(passData.DepthPyramidTexture, AccessFlags.Write);
desc.width /= 16;
desc.height /= 16;
passData.ForwardGBufferDepthTexture = ExtensionsURP.CreateTexture(_ForwardGBufferDepth, renderGraph, ref descDepth, format: GraphicsFormat.R16_SFloat, useMipMap: false, enableRandomWrite: false);
builder.UseTexture(passData.ForwardGBufferDepthTexture, AccessFlags.Write);
if (universalRenderingData.renderingMode == RenderingMode.Deferred
#if UNITY_6000_1_OR_NEWER
|| universalRenderingData.renderingMode == RenderingMode.DeferredPlus
#endif
)
{
if (resourceData.ssaoTexture.IsValid())
builder.UseTexture(resourceData.ssaoTexture, AccessFlags.Read);
builder.UseTexture(resourceData.gBuffer[0], AccessFlags.Read);
builder.UseTexture(resourceData.gBuffer[1], AccessFlags.Read);
builder.UseTexture(resourceData.gBuffer[2], AccessFlags.Read);
builder.UseTexture(resourceData.gBuffer[3], AccessFlags.Read);
if (resourceData.gBuffer.Length >= 6 && resourceData.gBuffer[5].IsValid())
builder.UseTexture(resourceData.gBuffer[5], AccessFlags.Read);
}
CullingResults cullingResults = universalRenderingData.cullResults;
ShaderTagId tags = new ShaderTagId("UniversalGBuffer");
int layerMask = universalCameraData.camera.cullingMask;
ForwardGBufferRenderStateBlock.depthState = new DepthState(false, CompareFunction.LessEqual);
ForwardGBufferRenderStateBlock.mask |= RenderStateMask.Depth;
RendererListDesc rendererListDesc = new RendererListDesc(tags, cullingResults, universalCameraData.camera)
{
rendererConfiguration = PerObjectData.None,
renderQueueRange = RenderQueueRange.opaque,
sortingCriteria = SortingCriteria.OptimizeStateChanges,
layerMask = layerMask,
stateBlock = ForwardGBufferRenderStateBlock,
};
passData.ForwardGBufferRendererListHandle = renderGraph.CreateRendererList(rendererListDesc);
builder.UseRendererList(passData.ForwardGBufferRendererListHandle);
builder.SetRenderFunc((PassData data, UnsafeGraphContext context) => ExecutePass(data, context));
}
}
private static void ExecutePass(PassData data, UnsafeGraphContext rgContext)
{
var cmd = CommandBufferHelpers.GetNativeCommandBuffer(rgContext.cmd);
int width = (int)(data.UniversalCameraData.camera.scaledPixelWidth * data.UniversalCameraData.renderScale);
int height = (int)(data.UniversalCameraData.camera.scaledPixelHeight * data.UniversalCameraData.renderScale);
// Set Depth, Color and SSAO to HTrace passes
cmd.SetGlobalTexture(HShaderParams.g_HTraceDepth, data.DepthTexture);
cmd.SetGlobalTexture(HShaderParams.g_HTraceColor, data.ColorTexture);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer2, data.NormalsTexture);
cmd.SetGlobalTexture(HShaderParams.g_HTraceSSAO, data.SSAOTexture.IsValid() ? data.SSAOTexture : Texture2D.whiteTexture);
var nativeGBuffer0 = data.GBufferTextures[0];
var nativeGBuffer1 = data.GBufferTextures[1];
var nativeGBuffer2 = data.GBufferTextures[2];
Texture renderLayerMaskTexture = data.GBufferTextures.Length >= 6 ? data.GBufferTextures[5] : null;
GBufferGenerationRenderGraph(cmd, data, width, height, nativeGBuffer0, nativeGBuffer1, nativeGBuffer2, renderLayerMaskTexture);
GenerateDepthPyramidShared(cmd, width, height, data.DepthPyramidTexture);
}
private static void GBufferGenerationRenderGraph(CommandBuffer cmd, PassData data, int width, int height, Texture nativeGBuffer0, Texture nativeGBuffer1,
Texture nativeGBuffer2, Texture renderLayerMask)
{
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
using (new ProfilingScope(cmd, GBufferProfilingSampler))
{
// Sky probe management
SphericalHarmonicsL2 ambientProbe = RenderSettings.ambientProbe;
cmd.SetGlobalVector(HShaderParams.H_SHAr, new Vector4(ambientProbe[0, 3], ambientProbe[0, 1], ambientProbe[0, 2], ambientProbe[0, 0] - ambientProbe[0, 6]));
cmd.SetGlobalVector(HShaderParams.H_SHAg, new Vector4(ambientProbe[1, 3], ambientProbe[1, 1], ambientProbe[1, 2], ambientProbe[1, 0] - ambientProbe[1, 6]));
cmd.SetGlobalVector(HShaderParams.H_SHAb, new Vector4(ambientProbe[2, 3], ambientProbe[2, 1], ambientProbe[2, 2], ambientProbe[2, 0] - ambientProbe[2, 6]));
cmd.SetGlobalVector(HShaderParams.H_SHBr, new Vector4(ambientProbe[0, 4], ambientProbe[0, 5], ambientProbe[0, 6] * 3, ambientProbe[0, 7]));
cmd.SetGlobalVector(HShaderParams.H_SHBg, new Vector4(ambientProbe[1, 4], ambientProbe[1, 5], ambientProbe[1, 6] * 3, ambientProbe[1, 7]));
cmd.SetGlobalVector(HShaderParams.H_SHBb, new Vector4(ambientProbe[2, 4], ambientProbe[2, 5], ambientProbe[2, 6] * 3, ambientProbe[2, 7]));
cmd.SetGlobalVector(HShaderParams.H_SHC, new Vector4(ambientProbe[0, 8], ambientProbe[1, 8], ambientProbe[2, 8], 1));
// Check if GBuffer is valid (e.g. Forward / wrong scale / is not set, etc.)
bool requestForwardGBufferRender = false;
if (nativeGBuffer0 == null || nativeGBuffer1 == null || nativeGBuffer2 == null)
{ requestForwardGBufferRender = true; }
else if ( nativeGBuffer0.width != width || nativeGBuffer0.height != height) // CameraDepthBuffer.rtHandleProperties.currentViewportSize.x
{ requestForwardGBufferRender = true; }
// Set Render Layer Mask to black dummy in case it's disabled as a feature and we can't render it
if (renderLayerMask == null)
renderLayerMask = Texture2D.blackTexture; // HRenderer.EmptyTexture;
// RequestForwardGBufferRender = true;
// Set GBuffer to HTrace passes if valid or render it otherwise
if (requestForwardGBufferRender == false)
{
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer0, nativeGBuffer0);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer1, nativeGBuffer1);
// cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer2, nativeGBuffer2);
cmd.SetGlobalTexture(HShaderParams.g_HTraceRenderLayerMask, renderLayerMask);
}
else
{
if (HRendererURP.RenderGraphEnabled)
GBufferMRT = new RenderTargetIdentifier[] { data.ForwardGBuffer0Texture, data.ForwardGBuffer1Texture, data.ForwardGBuffer2Texture, data.ForwardGBuffer3Texture, data.ForwardGBufferDepthTexture, data.ForwardRenderLayerMaskTexture };
else
GBufferMRT = new RenderTargetIdentifier[] { data.ForwardGBuffer0Texture, data.ForwardGBuffer1Texture, data.ForwardGBuffer2Texture, data.ForwardGBuffer3Texture, data.ForwardRenderLayerMaskTexture };
// If CameraDepthBuffer.rt doesn't work for any reason - we can replace it with our ForwardGBufferDepth.rt, but GBuffer rendering performance will suffer.
CoreUtils.SetRenderTarget(cmd, GBufferMRT, data.DepthTexture, ClearFlag.None);
// Cache the current keyword state set by Unity
bool RenderLayerKeywordState = Shader.IsKeywordEnabled(HShaderParams._WRITE_RENDERING_LAYERS);
// If we don't need render layers we do not touch the keyword at all
#if UNITY_2023_3_OR_NEWER
if (profile.GeneralSettings.ExcludeReceivingMask != 0 || profile.GeneralSettings.ExcludeCastingMask != 0)
CoreUtils.SetKeyword(cmd, HShaderParams._WRITE_RENDERING_LAYERS, true);
#endif
cmd.DrawRendererList(data.ForwardGBufferRendererListHandle);
// If we altered the keyword, we restore it to the original state
#if UNITY_2023_3_OR_NEWER
if (profile.GeneralSettings.ExcludeReceivingMask != 0 || profile.GeneralSettings.ExcludeCastingMask != 0)
CoreUtils.SetKeyword(cmd, HShaderParams._WRITE_RENDERING_LAYERS, RenderLayerKeywordState);
#endif
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer0, data.ForwardGBuffer0Texture);
cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer1, data.ForwardGBuffer1Texture);
// cmd.SetGlobalTexture(HShaderParams.g_HTraceGBuffer2, data.ForwardGBuffer2Texture);
cmd.SetGlobalTexture(HShaderParams.g_HTraceRenderLayerMask, data.ForwardRenderLayerMaskTexture);
}
}
}
#endif
#endregion --------------------------- Render Graph ---------------------------
#region --------------------------- Shared ---------------------------
private static void GenerateDepthPyramidShared(CommandBuffer cmd, int width, int height, RTHandle depthPyramidTexture)
{
using (new ProfilingScope(cmd, DepthPyramidGenerationProfilingSampler))
{
int generate_depth_pyramid_kernel = HDepthPyramid.FindKernel("GenerateDepthPyramid");
cmd.SetComputeTextureParam(HDepthPyramid, generate_depth_pyramid_kernel, HShaderParams._DepthPyramid_OutputMIP0, depthPyramidTexture, 0);
cmd.SetComputeTextureParam(HDepthPyramid, generate_depth_pyramid_kernel, HShaderParams._DepthPyramid_OutputMIP1, depthPyramidTexture, 1);
cmd.SetComputeTextureParam(HDepthPyramid, generate_depth_pyramid_kernel, HShaderParams._DepthPyramid_OutputMIP2, depthPyramidTexture, 2);
cmd.SetComputeTextureParam(HDepthPyramid, generate_depth_pyramid_kernel, HShaderParams._DepthPyramid_OutputMIP3, depthPyramidTexture, 3);
cmd.SetComputeTextureParam(HDepthPyramid, generate_depth_pyramid_kernel, HShaderParams._DepthPyramid_OutputMIP4, depthPyramidTexture, 4);
cmd.DispatchCompute(HDepthPyramid, generate_depth_pyramid_kernel, Mathf.CeilToInt(width / 16.0f), Mathf.CeilToInt(height / 16.0f), HRenderer.TextureXrSlices);
cmd.SetGlobalTexture(HShaderParams.g_HTraceDepthPyramidSSGI, depthPyramidTexture);
}
}
protected internal void Dispose()
{
Dummy?.HRelease();
ForwardGBuffer0?.HRelease();
ForwardGBuffer1?.HRelease();
ForwardGBuffer2?.HRelease();
ForwardGBuffer3?.HRelease();
ForwardRenderLayerMask?.HRelease();
ForwardGBufferDepth?.HRelease();
DepthPyramidRT?.HRelease();
}
#endregion --------------------------- Shared ---------------------------
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fd63347b53844f7fa3fdc1ef13ff65ba
timeCreated: 1757347187
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Passes/URP/GBufferPassURP.cs
uploadId: 840002

View File

@@ -0,0 +1,345 @@
//pipelinedefine
#define H_URP
using System;
using HTraceSSGI.Scripts.Data.Private;
using HTraceSSGI.Scripts.Extensions;
using HTraceSSGI.Scripts.Globals;
using HTraceSSGI.Scripts.Wrappers;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
#if UNITY_2023_3_OR_NEWER
using UnityEngine.Rendering.RenderGraphModule;
#else
using UnityEngine.Experimental.Rendering.RenderGraphModule;
#endif
namespace HTraceSSGI.Scripts.Passes.URP
{
internal class MotionVectorsURP : ScriptableRenderPass
{
// Texture Names
const string _ObjectMotionVectorsColorURP = "_ObjectMotionVectorsColorURP";
const string _ObjectMotionVectorsDepthURP = "_ObjectMotionVectorsDepthURP";
const string _CustomCameraMotionVectorsURP_0 = "_CustomCameraMotionVectorsURP_0";
const string _CustomCameraMotionVectorsURP_1 = "_CustomCameraMotionVectorsURP_1";
const string _MotionVectorsTagID = "MotionVectors";
// Shader Properties
private static readonly int _ObjectMotionVectorsColor = Shader.PropertyToID("_ObjectMotionVectors");
private static readonly int _ObjectMotionVectorsDepth = Shader.PropertyToID("_ObjectMotionVectorsDepth");
private static readonly int _BiasOffset = Shader.PropertyToID("_BiasOffset");
// Textures
internal static RTWrapper[] CustomCameraMotionVectorsURP = new RTWrapper[2] {new RTWrapper(), new RTWrapper()};
internal static RTWrapper ObjectMotionVectorsColorURP = new RTWrapper();
internal static RTWrapper ObjectMotionVectorsDepthURP = new RTWrapper();
// Materials
private static Material MotionVectorsMaterial_URP;
private static ProfilingSampler ObjectMVProfilingSampler = new ProfilingSampler(HNames.HTRACE_OBJECTS_MV_PASS_NAME);
private static ProfilingSampler MVProfilingSampler = new ProfilingSampler(HNames.HTRACE_CAMERA_MV_PASS_NAME);
#region --------------------------- Non Render Graph ---------------------------
private ScriptableRenderer _renderer;
private static int _historyCameraIndex;
protected internal void Initialize(ScriptableRenderer renderer)
{
_renderer = renderer;
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
Setup(renderingData.cameraData.camera, renderingData.cameraData.renderScale, renderingData.cameraData.cameraTargetDescriptor);
}
private static void Setup(Camera camera, float renderScale, RenderTextureDescriptor desc)
{
if (MotionVectorsMaterial_URP == null) MotionVectorsMaterial_URP = new Material(Shader.Find($"Hidden/{HNames.ASSET_NAME}/MotionVectorsURP"));
int width = (int)(camera.scaledPixelWidth * renderScale);
int height = (int)(camera.scaledPixelHeight * renderScale);
if (desc.width != width || desc.height != height)
desc = new RenderTextureDescriptor(width, height);
desc.depthBufferBits = 0; // Color and depth cannot be combined in RTHandles
desc.stencilFormat = GraphicsFormat.None;
desc.depthStencilFormat = GraphicsFormat.None;
desc.msaaSamples = 1;
desc.bindMS = false;
desc.enableRandomWrite = true;
RenderTextureDescriptor depthDesc = desc;
depthDesc.depthBufferBits = 32;
depthDesc.enableRandomWrite = false;
depthDesc.colorFormat = RenderTextureFormat.Depth;
CustomCameraMotionVectorsURP[0].ReAllocateIfNeeded(_CustomCameraMotionVectorsURP_0, ref desc, graphicsFormat: GraphicsFormat.R16G16_SFloat);
CustomCameraMotionVectorsURP[1].ReAllocateIfNeeded(_CustomCameraMotionVectorsURP_1, ref desc, graphicsFormat: GraphicsFormat.R8_SNorm);
ObjectMotionVectorsColorURP.ReAllocateIfNeeded(_ObjectMotionVectorsColorURP, ref desc, graphicsFormat: GraphicsFormat.R16G16_SFloat);
ObjectMotionVectorsDepthURP.ReAllocateIfNeeded(_ObjectMotionVectorsDepthURP, ref depthDesc, enableRandomWrite: false);
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
ConfigureInput(ScriptableRenderPassInput.Motion | ScriptableRenderPassInput.Depth);
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cmd = CommandBufferPool.Get(HNames.HTRACE_MV_PASS_NAME);
Camera camera = renderingData.cameraData.camera;
RenderMotionVectorsNonRenderGraph(cmd, camera, ref renderingData, ref context);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
private void RenderMotionVectorsNonRenderGraph(CommandBuffer cmd, Camera camera, ref RenderingData renderingData, ref ScriptableRenderContext context)
{
void RenderObjectsMotionVectors(ref RenderingData renderingData, ref ScriptableRenderContext context)
{
#if UNITY_2023_3_OR_NEWER
if (camera.cameraType == CameraType.SceneView)
return;
#endif
CoreUtils.SetRenderTarget(cmd, ObjectMotionVectorsColorURP.rt, ClearFlag.All, Color.clear);
CoreUtils.SetRenderTarget(cmd, ObjectMotionVectorsDepthURP.rt, ClearFlag.All, Color.clear);
#if UNITY_2023_1_OR_NEWER
// We'll write not only to our own Color, but also to our own Depth target to use it later (in Camera MV) to compose per-object mv
CoreUtils.SetRenderTarget(cmd, ObjectMotionVectorsColorURP.rt, ObjectMotionVectorsDepthURP.rt);
#else
// Prior to 2023 camera motion vectors are rendered directly on objects, so we write to both motion mask and motion vectors via MRT
RenderTargetIdentifier[] motionVectorsMRT = { CustomCameraMotionVectorsURP[0].rt, CustomCameraMotionVectorsURP[1].rt,};
CoreUtils.SetRenderTarget(cmd, motionVectorsMRT, ObjectMotionVectorsDepthURP.rt);
#endif // UNITY_2023_1_OR_NEWER
CullingResults cullingResults = renderingData.cullResults;
ShaderTagId[] tags
#if UNITY_2023_1_OR_NEWER
= {new ShaderTagId("MotionVectors")};
#else
= {new ShaderTagId("Meta")};
#endif // UNITY_2023_1_OR_NEWER
var renderList = new UnityEngine.Rendering.RendererUtils.RendererListDesc(tags, cullingResults, camera)
{
rendererConfiguration = PerObjectData.MotionVectors,
renderQueueRange = RenderQueueRange.opaque,
sortingCriteria = SortingCriteria.CommonOpaque,
layerMask = camera.cullingMask,
overrideMaterial
#if UNITY_2023_1_OR_NEWER
= null,
#else
= MotionVectorsMaterial_URP,
overrideMaterialPassIndex = 1,
// If somethingis wrong with our custom shader we can always use the standard one (and ShaderPass = 0) instead
// Material ObjectMotionVectorsMaterial = new Material(Shader.Find("Hidden/Universal Render Pipeline/ObjectMotionVectors"));
// overrideMaterialPassIndex = 0,
#endif //UNITY_2023_1_OR_NEWER
};
CoreUtils.DrawRendererList(context, cmd, context.CreateRendererList(renderList));
#if !UNITY_2023_1_OR_NEWER
// Prior to 2023 camera motion vectors are rendered directly on objects, so we will finish mv calculation here and won't execute camera mv
cmd.SetGlobalTexture(HShaderParams.g_HTraceMotionVectors, CustomCameraMotionVectorsURP[0].rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceMotionMask, CustomCameraMotionVectorsURP[1].rt);
#endif // UNITY_2023_1_OR_NEWER
}
void RenderCameraMotionVectors()
{
#if UNITY_2023_1_OR_NEWER
float DepthBiasOffset = 0;
#if UNITY_2023_1_OR_NEWER
DepthBiasOffset = 0.00099f;
#endif // UNITY_2023_1_OR_NEWER
#if UNITY_6000_0_OR_NEWER
DepthBiasOffset = 0;
#endif // UNITY_6000_0_OR_NEWER
// Target target[0] is set as a Depth Buffer, just because this method requires Depth, but we don't care for it in the fullscreen pass
RenderTargetIdentifier[] motionVectorsMRT = { CustomCameraMotionVectorsURP[0].rt, CustomCameraMotionVectorsURP[1].rt};
CoreUtils.SetRenderTarget(cmd, motionVectorsMRT, motionVectorsMRT[0]);
MotionVectorsMaterial_URP.SetTexture(_ObjectMotionVectorsColor, ObjectMotionVectorsColorURP.rt);
MotionVectorsMaterial_URP.SetTexture(_ObjectMotionVectorsDepth, ObjectMotionVectorsDepthURP.rt);
MotionVectorsMaterial_URP.SetFloat(_BiasOffset, DepthBiasOffset);
cmd.DrawProcedural(Matrix4x4.identity, MotionVectorsMaterial_URP, 0, MeshTopology.Triangles, 3, 1);
// This restores color camera color target (.SetRenderTarget can be used for Forward + any Depth Priming, but doesn't work in Deferred)
#pragma warning disable CS0618
ConfigureTarget(_renderer.cameraColorTargetHandle);
#pragma warning restore CS0618
cmd.SetGlobalTexture(HShaderParams.g_HTraceMotionVectors, CustomCameraMotionVectorsURP[0].rt);
cmd.SetGlobalTexture(HShaderParams.g_HTraceMotionMask, CustomCameraMotionVectorsURP[1].rt);
#endif // UNITY_2023_1_OR_NEWER
}
RenderObjectsMotionVectors(ref renderingData, ref context);
RenderCameraMotionVectors();
}
#endregion --------------------------- Non Render Graph ---------------------------
#region --------------------------- Render Graph ---------------------------
#if UNITY_2023_3_OR_NEWER
private class ObjectMVPassData
{
public RendererListHandle RendererListHandle;
}
private class CameraMVPassData
{
public TextureHandle ObjectMotionVectorsColor;
public TextureHandle ObjectMotionVectorsDepth;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
UniversalCameraData universalCameraData = frameData.Get<UniversalCameraData>();
ConfigureInput(ScriptableRenderPassInput.Motion | ScriptableRenderPassInput.Depth);
using (IRasterRenderGraphBuilder builder = renderGraph.AddRasterRenderPass<ObjectMVPassData>(HNames.HTRACE_OBJECTS_MV_PASS_NAME, out var passData, ObjectMVProfilingSampler))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalRenderingData universalRenderingData = frameData.Get<UniversalRenderingData>();
builder.AllowGlobalStateModification(true);
builder.AllowPassCulling(false);
TextureHandle depthTexture = resourceData.activeDepthTexture;
TextureHandle motionVectorsTexture = resourceData.motionVectorColor;
if (motionVectorsTexture.IsValid())
builder.UseTexture(motionVectorsTexture, AccessFlags.Read);
AddRendererList(renderGraph, universalCameraData, universalRenderingData, passData, builder);
// This was previously colorTexture.GetDescriptor(renderGraph);
TextureDesc descDepth = depthTexture.GetDescriptor(renderGraph);
descDepth.colorFormat = GraphicsFormat.R16G16_SFloat;
descDepth.name = _ObjectMotionVectorsColorURP;
TextureHandle objectMotionVectorsColorTexHandle = renderGraph.CreateTexture(descDepth);
builder.SetRenderAttachment(objectMotionVectorsColorTexHandle, 0);
builder.SetRenderAttachmentDepth(depthTexture, AccessFlags.ReadWrite);
//if (motionVectorsTexture.IsValid()) //seems to work fine without this
builder.SetGlobalTextureAfterPass(motionVectorsTexture, HShaderParams.g_HTraceMotionVectors);
builder.SetGlobalTextureAfterPass(objectMotionVectorsColorTexHandle, HShaderParams.g_HTraceMotionMask);
builder.SetRenderFunc((ObjectMVPassData data, RasterGraphContext context) =>
{
RasterCommandBuffer cmd = context.cmd;
cmd.ClearRenderTarget(false, true, Color.black);
cmd.DrawRendererList(data.RendererListHandle);
});
}
// Render Graph + Game View - no need to render camera mv, as they are already available to us in this combination
if (universalCameraData.cameraType == CameraType.Game)
return;
using (IRasterRenderGraphBuilder builder = renderGraph.AddRasterRenderPass<CameraMVPassData>(HNames.HTRACE_CAMERA_MV_PASS_NAME, out var passData, MVProfilingSampler))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
builder.AllowGlobalStateModification(true);
builder.AllowPassCulling(false);
TextureHandle colorTexture = resourceData.activeColorTexture;
if (MotionVectorsMaterial_URP == null) MotionVectorsMaterial_URP = new Material(Shader.Find($"Hidden/{HNames.ASSET_NAME}/MotionVectorsURP"));
TextureDesc desc = colorTexture.GetDescriptor(renderGraph);
desc.colorFormat = GraphicsFormat.R16G16_SFloat;
desc.name = _CustomCameraMotionVectorsURP_0;
TextureHandle cameraMotionVectorsColorTexHandle = renderGraph.CreateTexture(desc);
builder.SetRenderAttachment(cameraMotionVectorsColorTexHandle, 0);
builder.SetGlobalTextureAfterPass(cameraMotionVectorsColorTexHandle, HShaderParams.g_HTraceMotionVectors);
builder.SetRenderFunc((CameraMVPassData data, RasterGraphContext context) =>
{
RasterCommandBuffer cmd = context.cmd;
MotionVectorsMaterial_URP.SetTexture(_ObjectMotionVectorsColor, context.defaultResources.blackTexture);
MotionVectorsMaterial_URP.SetTexture(_ObjectMotionVectorsDepth, context.defaultResources.whiteTexture);
MotionVectorsMaterial_URP.SetFloat(_BiasOffset, 0);
cmd.DrawProcedural(Matrix4x4.identity, MotionVectorsMaterial_URP, 0, MeshTopology.Triangles, 3, 1);
});
}
}
private static void AddRendererList(RenderGraph renderGraph, UniversalCameraData universalCameraData, UniversalRenderingData universalRenderingData, ObjectMVPassData objectMvPassData, IRasterRenderGraphBuilder builder)
{
RenderStateBlock ForwardGBufferRenderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
ForwardGBufferRenderStateBlock.depthState = new DepthState(false, CompareFunction.LessEqual); // Probably CompareFunction.Less ?
ForwardGBufferRenderStateBlock.mask |= RenderStateMask.Depth;
ShaderTagId motionVectorsShaderTag = new ShaderTagId(_MotionVectorsTagID);
var renderList = new UnityEngine.Rendering.RendererUtils.RendererListDesc(motionVectorsShaderTag, universalRenderingData.cullResults, universalCameraData.camera)
{
rendererConfiguration = PerObjectData.MotionVectors,
renderQueueRange = RenderQueueRange.opaque,
sortingCriteria = SortingCriteria.CommonOpaque,
stateBlock = ForwardGBufferRenderStateBlock,
};
objectMvPassData.RendererListHandle = renderGraph.CreateRendererList(renderList);
builder.UseRendererList(objectMvPassData.RendererListHandle);
}
#endif
#endregion --------------------------- Render Graph ---------------------------
#region --------------------------- Share ---------------------------
protected internal void Dispose()
{
CustomCameraMotionVectorsURP[0]?.HRelease();
CustomCameraMotionVectorsURP[1]?.HRelease();
ObjectMotionVectorsColorURP?.HRelease();
ObjectMotionVectorsDepthURP?.HRelease();
}
#endregion --------------------------- Share ---------------------------
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 603fb045f7d843da93b9e3f0435072b7
timeCreated: 1757339660
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Passes/URP/MotionVectorsURP.cs
uploadId: 840002

View File

@@ -0,0 +1,225 @@
//pipelinedefine
#define H_URP
using HTraceSSGI.Scripts.Data.Private;
using HTraceSSGI.Scripts.Extensions.CameraHistorySystem;
using HTraceSSGI.Scripts.Globals;
using HTraceSSGI.Scripts.Passes.Shared;
using HTraceSSGI.Scripts.Wrappers;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.RendererUtils;
using UnityEngine.Rendering.Universal;
#if UNITY_2023_3_OR_NEWER
using UnityEngine.Rendering.RenderGraphModule;
#else
using UnityEngine.Experimental.Rendering.RenderGraphModule;
#endif
namespace HTraceSSGI.Scripts.Passes.URP
{
internal class PrePassURP : ScriptableRenderPass
{
private static Vector4 s_HRenderScalePrevious = Vector4.one;
private struct HistoryCameraData : ICameraHistoryData
{
private int hash;
public Matrix4x4 previousViewProjMatrix;
public Matrix4x4 previousInvViewProjMatrix;
public int GetHash() => hash;
public void SetHash(int hashIn) => this.hash = hashIn;
}
private static readonly CameraHistorySystem<HistoryCameraData> CameraHistorySystem = new CameraHistorySystem<HistoryCameraData>();
private static int s_FrameCount = 0;
#region --------------------------- Non Render Graph ---------------------------
private ScriptableRenderer _renderer;
protected internal void Initialize(ScriptableRenderer renderer)
{
_renderer = renderer;
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
CameraHistorySystem.UpdateCameraHistoryIndex(camera.GetHashCode());
CameraHistorySystem.UpdateCameraHistoryData();
CameraHistorySystem.GetCameraData().SetHash(camera.GetHashCode());
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
ConfigureInput(ScriptableRenderPassInput.Depth); // | ScriptableRenderPassInput.Normal);
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cmd = CommandBufferPool.Get(HNames.HTRACE_PRE_PASS_NAME);
Camera camera = renderingData.cameraData.camera;
// -------------- HRenderScale -----------------
// Unity's _RTHandleScale in URP always (1,1,1,1)? We need to overwrite it anyway...
cmd.SetGlobalVector(HShaderParams.HRenderScalePrevious, s_HRenderScalePrevious);
//s_HRenderScalePrevious = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, 1 / RTHandles.rtHandleProperties.rtHandleScale.x, 1 / RTHandles.rtHandleProperties.rtHandleScale.y); //we don't needed it more
cmd.SetGlobalVector(HShaderParams.HRenderScale, s_HRenderScalePrevious);
// -------------- Matrix -----------------
Matrix4x4 projMatrix = GL.GetGPUProjectionMatrix(camera.projectionMatrix, true); //renderingData.cameraData.GetGPUProjectionMatrix();
Matrix4x4 viewMatrix = renderingData.cameraData.GetViewMatrix();
Matrix4x4 viewProjMatrix = projMatrix * viewMatrix;
Matrix4x4 invViewProjMatrix = Matrix4x4.Inverse(viewProjMatrix);
{
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_VP, viewProjMatrix);
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_I_VP, invViewProjMatrix);
ref var previousViewProjMatrix = ref CameraHistorySystem.GetCameraData().previousViewProjMatrix;
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_PREV_VP, previousViewProjMatrix);
ref var previousInvViewProjMatrix = ref CameraHistorySystem.GetCameraData().previousInvViewProjMatrix;
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_PREV_I_VP, previousInvViewProjMatrix);
previousViewProjMatrix = viewProjMatrix;
previousInvViewProjMatrix = invViewProjMatrix;
CameraHistorySystem.GetCameraData().SetHash(camera.GetHashCode());
// HistoryCameraData currentData = CameraHistorySystem.GetCameraData();
// currentData.previousViewProjMatrix = viewProjMatrix;
// currentData.previousInvViewProjMatrix = invViewProjMatrix;
// CameraHistorySystem.SetCameraData(currentData);
}
// -------------- Other -----------------
cmd.SetGlobalInt(HShaderParams.FrameCount, s_FrameCount);
s_FrameCount++;
// Unity's blue noise is unreliable, so we'll use ours in all pipelines
HBlueNoise.SetTextures(cmd);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
#endregion --------------------------- Non Render Graph ---------------------------
#region --------------------------- Render Graph ---------------------------
#if UNITY_2023_3_OR_NEWER
RTHandle OwenScrambledRTHandle;
RTHandle ScramblingTileXSPPRTHandle;
RTHandle RankingTileXSPPRTHandle;
RTHandle ScramblingTextureRTHandle;
private class PassData
{
public RendererListHandle RendererListHandle;
public UniversalCameraData UniversalCameraData;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
using (var builder = renderGraph.AddRasterRenderPass<PassData>(HNames.HTRACE_PRE_PASS_NAME, out var passData, new ProfilingSampler(HNames.HTRACE_PRE_PASS_NAME)))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalCameraData universalCameraData = frameData.Get<UniversalCameraData>();
UniversalRenderingData universalRenderingData = frameData.Get<UniversalRenderingData>();
UniversalLightData lightData = frameData.Get<UniversalLightData>();
ConfigureInput(ScriptableRenderPassInput.Depth | ScriptableRenderPassInput.Normal);
builder.AllowGlobalStateModification(true);
builder.AllowPassCulling(false);
passData.UniversalCameraData = universalCameraData;
Camera camera = universalCameraData.camera;
CameraHistorySystem.UpdateCameraHistoryIndex(camera.GetHashCode());
CameraHistorySystem.UpdateCameraHistoryData();
CameraHistorySystem.GetCameraData().SetHash(camera.GetHashCode());
//Blue noise
if (OwenScrambledRTHandle == null) OwenScrambledRTHandle = RTHandles.Alloc(HBlueNoise.OwenScrambledTexture);
TextureHandle owenScrambledTextureHandle = renderGraph.ImportTexture(OwenScrambledRTHandle);
builder.SetGlobalTextureAfterPass(owenScrambledTextureHandle, HBlueNoise.g_OwenScrambledTexture);
if (ScramblingTileXSPPRTHandle == null) ScramblingTileXSPPRTHandle = RTHandles.Alloc(HBlueNoise.ScramblingTileXSPP);
TextureHandle scramblingTileXSPPTextureHandle = renderGraph.ImportTexture(ScramblingTileXSPPRTHandle);
builder.SetGlobalTextureAfterPass(scramblingTileXSPPTextureHandle, HBlueNoise.g_ScramblingTileXSPP);
if (RankingTileXSPPRTHandle == null) RankingTileXSPPRTHandle = RTHandles.Alloc(HBlueNoise.RankingTileXSPP);
TextureHandle rankingTileXSPPTextureHandle = renderGraph.ImportTexture(RankingTileXSPPRTHandle);
builder.SetGlobalTextureAfterPass(rankingTileXSPPTextureHandle, HBlueNoise.g_RankingTileXSPP);
if (ScramblingTextureRTHandle == null) ScramblingTextureRTHandle = RTHandles.Alloc(HBlueNoise.ScramblingTexture);
TextureHandle scramblingTextureHandle = renderGraph.ImportTexture(ScramblingTextureRTHandle);
builder.SetGlobalTextureAfterPass(scramblingTextureHandle, HBlueNoise.g_ScramblingTexture);
builder.SetRenderFunc((PassData data, RasterGraphContext context) => ExecutePass(data, context));
}
}
private static void ExecutePass(PassData data, RasterGraphContext rgContext)
{
var cmd = rgContext.cmd;
Camera camera = data.UniversalCameraData.camera;
// -------------- HRenderScale -----------------
// Unity's _RTHandleScale in URP always (1,1,1,1)? We need to overwrite it anyway...
cmd.SetGlobalVector(HShaderParams.HRenderScalePrevious, s_HRenderScalePrevious);
//s_HRenderScalePrevious = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, 1 / RTHandles.rtHandleProperties.rtHandleScale.x, 1 / RTHandles.rtHandleProperties.rtHandleScale.y); //we don't needed it more
cmd.SetGlobalVector(HShaderParams.HRenderScale, s_HRenderScalePrevious);
// -------------- Matrix -----------------
Matrix4x4 projMatrix = GL.GetGPUProjectionMatrix(camera.projectionMatrix, true); //renderingData.cameraData.GetGPUProjectionMatrix();
Matrix4x4 viewMatrix = data.UniversalCameraData.GetViewMatrix();
Matrix4x4 viewProjMatrix = projMatrix * viewMatrix;
Matrix4x4 invViewProjMatrix = Matrix4x4.Inverse(viewProjMatrix);
{
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_VP, viewProjMatrix);
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_I_VP, invViewProjMatrix);
ref var previousViewProjMatrix = ref CameraHistorySystem.GetCameraData().previousViewProjMatrix;
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_PREV_VP, previousViewProjMatrix);
ref var previousInvViewProjMatrix = ref CameraHistorySystem.GetCameraData().previousInvViewProjMatrix;
cmd.SetGlobalMatrix(HShaderParams.H_MATRIX_PREV_I_VP, previousInvViewProjMatrix);
previousViewProjMatrix = viewProjMatrix;
previousInvViewProjMatrix = invViewProjMatrix;
CameraHistorySystem.GetCameraData().SetHash(camera.GetHashCode());
// HistoryCameraData currentData = CameraHistorySystem.GetCameraData();
// currentData.previousViewProjMatrix = viewProjMatrix;
// currentData.previousInvViewProjMatrix = invViewProjMatrix;
// CameraHistorySystem.SetCameraData(currentData);
}
// -------------- Other -----------------
cmd.SetGlobalInt(HShaderParams.FrameCount, s_FrameCount);
s_FrameCount++;
}
#endif
#endregion --------------------------- Render Graph ---------------------------
protected internal void Dispose()
{
s_FrameCount = 0;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 1499f9a9fbb1cf242835eeae03872d5d
timeCreated: 1729952288
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Passes/URP/PrePassURP.cs
uploadId: 840002

View File

@@ -0,0 +1,446 @@
//pipelinedefine
#define H_URP
using HTraceSSGI.Scripts.Data.Private;
using HTraceSSGI.Scripts.Data.Public;
using HTraceSSGI.Scripts.Extensions;
using HTraceSSGI.Scripts.Globals;
using HTraceSSGI.Scripts.Passes.Shared;
using HTraceSSGI.Scripts.Wrappers;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
#if UNITY_2023_3_OR_NEWER
using HTraceSSGI.Scripts.Infrastructure.URP;
using UnityEngine.Rendering.RenderGraphModule;
#endif
namespace HTraceSSGI.Scripts.Passes.URP
{
internal class SSGIPassURP : ScriptableRenderPass
{
private static readonly int CameraNormalsTexture = Shader.PropertyToID("_CameraNormalsTexture");
// Texture Names
internal const string _ColorPreviousFrame = "_ColorPreviousFrame";
internal const string _DebugOutput = "_DebugOutput";
internal const string _ColorCopy = "_ColorCopy";
internal const string _ReservoirLuminance = "_ReservoirLuminance";
internal const string _Reservoir = "_Reservoir";
internal const string _ReservoirReprojected = "_ReservoirReprojected";
internal const string _ReservoirSpatial = "_ReservoirSpatial";
internal const string _ReservoirTemporal = "_ReservoirTemporal";
internal const string _SampleCount = "_Samplecount";
internal const string _SamplecountReprojected = "_SamplecountReprojected";
internal const string _TemporalInvalidityFilteredA = "_TemporalInvalidityFilteredA";
internal const string _TemporalInvalidityFilteredB = "_TemporalInvalidityFilteredB";
internal const string _TemporalInvalidityAccumulated = "_TemporalInvalidityAccumulated";
internal const string _TemporalInvalidityReprojected = "_TemporalInvalidityReprojected";
internal const string _SpatialOcclusionAccumulated = "_SpatialOcclusionAccumulated";
internal const string _SpatialOcclusionReprojected = "_SpatialOcclusionReprojected";
internal const string _AmbientOcclusion = "_AmbientOcclusion";
internal const string _AmbientOcclusionGuidance = "_AmbientOcclusionGuidance";
internal const string _AmbientOcclusionInvalidity = "_AmbientOcclusionInvalidity";
internal const string _AmbientOcclusionAccumulated = "_AmbientOcclusionAccumulated";
internal const string _AmbientOcclusionReprojected = "_AmbientOcclusionReprojected";
internal const string _Radiance = "_Radiance";
internal const string _RadianceReprojected = "_RadianceReprojected";
internal const string _RadianceAccumulated = "_RadianceAccumulated";
internal const string _RadianceFiltered = "_RadianceFiltered";
internal const string _RadianceInterpolated = "_RadianceInterpolated";
internal const string _RadianceStabilized = "_RadianceStabilized";
internal const string _RadianceStabilizedReprojected = "_RadianceStabilizedReprojected";
internal const string _RadianceNormalDepth = "_RadianceNormalDepth";
internal const string _ColorReprojected = "_ColorReprojected";
internal const string _NormalDepthHistory = "_NormalDepthHistory";
internal const string _NormalDepthHistoryFullRes = "_NormalDepthHistoryFullRes";
internal const string _DummyBlackTexture = "_DummyBlackTexture";
#region --------------------------- Non Render Graph ---------------------------
private ScriptableRenderer _renderer;
protected internal void Initialize(ScriptableRenderer renderer)
{
_renderer = renderer;
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
SSGI.CameraHistorySystem.UpdateCameraHistoryIndex(renderingData.cameraData.camera.GetHashCode());
SSGI.CameraHistorySystem.UpdateCameraHistoryData();
SSGI.CameraHistorySystem.GetCameraData().SetHash(renderingData.cameraData.camera.GetHashCode());
SetupShared(renderingData.cameraData.camera, renderingData.cameraData.renderScale, renderingData.cameraData.cameraTargetDescriptor);
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
}
#if UNITY_2023_3_OR_NEWER
[System.Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
var cmd = CommandBufferPool.Get(HNames.HTRACE_SSGI_PASS_NAME);
Camera camera = renderingData.cameraData.camera;
float renderScale = renderingData.cameraData.renderScale;
int width = (int)(camera.scaledPixelWidth * renderScale);
int height = (int)(camera.scaledPixelHeight * renderScale);
if (Shader.GetGlobalTexture(CameraNormalsTexture) == null)
return;
// ---------------------------------------- AMBIENT LIGHTING OVERRIDE ---------------------------------------- //
using (new ProfilingScope(cmd, SSGI.AmbientLightingOverrideSampler))
{
cmd.SetGlobalFloat(SSGI._IndirectLightingIntensity, profile.SSGISettings.Intensity);
if (profile.GeneralSettings.AmbientOverride)
{
// Copy Color buffer
CoreUtils.SetRenderTarget(cmd, SSGI.ColorCopy_URP.rt);
cmd.DrawProcedural(Matrix4x4.identity, SSGI.ColorCompose_URP, 0, MeshTopology.Triangles, 3, 1);
// Subtract indirect lighting from Color buffer
CoreUtils.SetRenderTarget(cmd, _renderer.cameraColorTargetHandle);
SSGI.ColorCompose_URP.SetTexture(SSGI._ColorCopy, SSGI.ColorCopy_URP.rt);
cmd.DrawProcedural(Matrix4x4.identity, SSGI.ColorCompose_URP, 1, MeshTopology.Triangles, 3, 1);
}
// Early out if we want to prview direct lighting only
if (profile.GeneralSettings.DebugMode == DebugMode.DirectLighting)
{
ConfigureTarget(_renderer.cameraColorTargetHandle);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
return;
}
}
SSGI.Execute(cmd, camera, width, height, _renderer.cameraColorTargetHandle);
// ---------------------------------------- INDIRECT LIGHTING INJECTION ---------------------------------------- //
using (new ProfilingScope(cmd, SSGI.IndirectLightingInjectionSampler))
{
var finalOutput = Mathf.Approximately(profile.SSGISettings.RenderScale, 1.0f) ? SSGI.RadianceFiltered.rt : SSGI.RadianceInterpolated.rt;
cmd.SetGlobalTexture(SSGI._SampleCountSSGI, SSGI.SamplecountReprojected.rt);
cmd.SetGlobalTexture(SSGI._HTraceBufferGI, finalOutput);
// Copy color buffer + indirect lighting (without intensity multiplication) for multibounce
if (profile.GeneralSettings.Multibounce == true)
{
cmd.SetComputeTextureParam(SSGI.HTemporalReprojection, (int)SSGI.HTemporalReprojectionKernels.CopyHistory, SSGI._Radiance_History, _renderer.cameraColorTargetHandle);
cmd.SetComputeTextureParam(SSGI.HTemporalReprojection, (int)SSGI.HTemporalReprojectionKernels.CopyHistory, SSGI._Radiance_Output, SSGI.CameraHistorySystem.GetCameraData().ColorPreviousFrame.rt);
cmd.DispatchCompute(SSGI.HTemporalReprojection, (int)SSGI.HTemporalReprojectionKernels.CopyHistory, Mathf.CeilToInt(width / 8.0f), Mathf.CeilToInt(height / 8.0f), HRenderer.TextureXrSlices);
}
#if UNITY_2023_3_OR_NEWER
if (profile.GeneralSettings.ExcludeReceivingMask != 0)
SSGI.ColorCompose_URP.EnableKeyword(SSGI.USE_RECEIVE_LAYER_MASK);
#endif
// Inject final indirect lighting (with intensity multiplication) into color buffer via additive blending
CoreUtils.SetRenderTarget(cmd, _renderer.cameraColorTargetHandle);
SSGI.ColorCompose_URP.SetInt(SSGI._MetallicIndirectFallback, profile.GeneralSettings.MetallicIndirectFallback ? 1 : 0);
cmd.DrawProcedural(Matrix4x4.identity, SSGI.ColorCompose_URP, 2, MeshTopology.Triangles, 3, 1);
ConfigureTarget(_renderer.cameraColorTargetHandle);
}
SSGI.History.Update();
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
return;
}
#endregion --------------------------- Non Render Graph ---------------------------
#region --------------------------- Render Graph ---------------------------
#if UNITY_2023_3_OR_NEWER
private class PassData
{
public UniversalCameraData UniversalCameraData;
public TextureHandle ColorTexture;
public TextureHandle DepthTexture;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
using (var builder = renderGraph.AddUnsafePass<PassData>(HNames.HTRACE_SSGI_PASS_NAME, out var passData, new ProfilingSampler(HNames.HTRACE_SSGI_PASS_NAME)))
{
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
UniversalCameraData universalCameraData = frameData.Get<UniversalCameraData>();
UniversalRenderingData universalRenderingData = frameData.Get<UniversalRenderingData>();
UniversalLightData lightData = frameData.Get<UniversalLightData>();
ConfigureInput(ScriptableRenderPassInput.Normal);
builder.AllowGlobalStateModification(true);
builder.AllowPassCulling(false);
RenderTextureDescriptor targetDesc = universalCameraData.cameraTargetDescriptor;
TextureHandle colorTexture = universalRenderingData.renderingMode == RenderingMode.Deferred
#if UNITY_6000_1_OR_NEWER
|| universalRenderingData.renderingMode == RenderingMode.DeferredPlus
#endif
? resourceData.activeColorTexture : resourceData.cameraColor;
TextureHandle depthTexture = universalRenderingData.renderingMode == RenderingMode.Deferred
#if UNITY_6000_1_OR_NEWER
|| universalRenderingData.renderingMode == RenderingMode.DeferredPlus
#endif
? resourceData.activeDepthTexture : resourceData.cameraDepth;
builder.UseTexture(colorTexture, AccessFlags.Write);
builder.UseTexture(resourceData.cameraNormalsTexture);
builder.UseTexture(resourceData.motionVectorColor);
passData.UniversalCameraData = universalCameraData;
passData.ColorTexture = colorTexture;
passData.DepthTexture = depthTexture;
Camera camera = universalCameraData.camera;
SSGI.CameraHistorySystem.UpdateCameraHistoryIndex(camera.GetHashCode());
SSGI.CameraHistorySystem.UpdateCameraHistoryData();
SSGI.CameraHistorySystem.GetCameraData().SetHash(camera.GetHashCode());
SetupShared(camera, universalCameraData.renderScale, universalCameraData.cameraTargetDescriptor);
builder.SetRenderFunc((PassData data, UnsafeGraphContext context) => ExecutePass(data, context));
}
}
private static void ExecutePass(PassData data, UnsafeGraphContext rgContext)
{
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
var cmd = CommandBufferHelpers.GetNativeCommandBuffer(rgContext.cmd);
Camera camera = data.UniversalCameraData.camera;
float renderScale = data.UniversalCameraData.renderScale;
int width = (int)(camera.scaledPixelWidth * renderScale);
int height = (int)(camera.scaledPixelHeight * renderScale);
if (Shader.GetGlobalTexture(CameraNormalsTexture) == null)
return;
// ---------------------------------------- AMBIENT LIGHTING OVERRIDE ---------------------------------------- //
using (new ProfilingScope(cmd, SSGI.AmbientLightingOverrideSampler))
{
cmd.SetGlobalFloat(SSGI._IndirectLightingIntensity, profile.SSGISettings.Intensity);
if (profile.GeneralSettings.AmbientOverride)
{
// Copy Color buffer
CoreUtils.SetRenderTarget(cmd, SSGI.ColorCopy_URP.rt);
cmd.DrawProcedural(Matrix4x4.identity, SSGI.ColorCompose_URP, 0, MeshTopology.Triangles, 3, 1);
// Subtract indirect lighting from Color buffer
CoreUtils.SetRenderTarget(cmd, data.ColorTexture);
SSGI.ColorCompose_URP.SetTexture(SSGI._ColorCopy, SSGI.ColorCopy_URP.rt);
cmd.DrawProcedural(Matrix4x4.identity, SSGI.ColorCompose_URP, 1, MeshTopology.Triangles, 3, 1);
}
// Early out if we want to prview direct lighting only
if (profile.GeneralSettings.DebugMode == DebugMode.DirectLighting)
{
return;
}
}
SSGI.Execute(cmd, camera, width, height, data.ColorTexture);
// ---------------------------------------- INDIRECT LIGHTING INJECTION ---------------------------------------- //
using (new ProfilingScope(cmd, SSGI.IndirectLightingInjectionSampler))
{
cmd.SetGlobalTexture(SSGI._HTraceBufferGI, SSGI.finalOutput);
// Copy color buffer + indirect lighting (without intensity multiplication) for multibounce
if (profile.GeneralSettings.Multibounce == true)
{
cmd.SetComputeTextureParam(SSGI.HTemporalReprojection, (int)SSGI.HTemporalReprojectionKernels.CopyHistory, SSGI._Radiance_History, data.ColorTexture);
cmd.SetComputeTextureParam(SSGI.HTemporalReprojection, (int)SSGI.HTemporalReprojectionKernels.CopyHistory, SSGI._Radiance_Output, SSGI.CameraHistorySystem.GetCameraData().ColorPreviousFrame.rt);
cmd.DispatchCompute(SSGI.HTemporalReprojection, (int)SSGI.HTemporalReprojectionKernels.CopyHistory, Mathf.CeilToInt(width / 8.0f), Mathf.CeilToInt(height / 8.0f), HRenderer.TextureXrSlices);
}
#if UNITY_2023_3_OR_NEWER
if (profile.GeneralSettings.ExcludeReceivingMask != 0)
SSGI.ColorCompose_URP.EnableKeyword(SSGI.USE_RECEIVE_LAYER_MASK);
#endif
// Inject final indirect lighting (with intensity multiplication) into color buffer via additive blending
CoreUtils.SetRenderTarget(cmd, data.ColorTexture);
SSGI.ColorCompose_URP.SetInt(SSGI._MetallicIndirectFallback, profile.GeneralSettings.MetallicIndirectFallback ? 1 : 0);
cmd.DrawProcedural(Matrix4x4.identity, SSGI.ColorCompose_URP, 2, MeshTopology.Triangles, 3, 1);
}
SSGI.History.Update();
}
#endif
#endregion --------------------------- Render Graph ---------------------------
#region ------------------------------------ Shared ------------------------------------
private static void SetupShared(Camera camera, float renderScale, RenderTextureDescriptor desc)
{
HTraceSSGIProfile profile = HTraceSSGISettings.ActiveProfile;
if (SSGI.HDebug == null) SSGI.HDebug = HExtensions.LoadComputeShader("HDebugSSGI");
if (SSGI.HReSTIR == null) SSGI.HReSTIR = HExtensions.LoadComputeShader("HRestirSSGI");
if (SSGI.HRenderSSGI == null) SSGI.HRenderSSGI = HExtensions.LoadComputeShader("HRenderSSGI");
if (SSGI.HDenoiser == null) SSGI.HDenoiser = HExtensions.LoadComputeShader("HDenoiserSSGI");
if (SSGI.HInterpolation == null) SSGI.HInterpolation = HExtensions.LoadComputeShader("HInterpolationSSGI");
if (SSGI.HCheckerboarding == null) SSGI.HCheckerboarding = HExtensions.LoadComputeShader("HCheckerboardingSSGI");
if (SSGI.PyramidGeneration == null) SSGI.PyramidGeneration = HExtensions.LoadComputeShader("HDepthPyramid");
if (SSGI.HTemporalReprojection == null) SSGI.HTemporalReprojection = HExtensions.LoadComputeShader("HTemporalReprojectionSSGI");
if (SSGI.ColorCompose_URP == null) SSGI.ColorCompose_URP = new Material(Shader.Find($"Hidden/{HNames.ASSET_NAME}/ColorComposeURP"));
int width = (int)(camera.scaledPixelWidth * renderScale);
int height = (int)(camera.scaledPixelHeight * renderScale);
if (desc.width != width || desc.height != height)
desc = new RenderTextureDescriptor(width, height);
// Debug.Log($"All params in cameraTargetDescriptor: width: {desc.width}, height:{desc.height}, volumeDepth: {desc.volumeDepth}, depthBufferBits: {desc.depthBufferBits}, \n" +
// $"graphicsFormat: {desc.graphicsFormat}, colorFormat: {desc.colorFormat}, stencilFormat: {desc.stencilFormat}, msaaSamples: {desc.msaaSamples}, \n" +
// $"useMipMap: {desc.useMipMap}, autoGenerateMips: {desc.autoGenerateMips}, mipCount: {desc.mipCount}, \n" +
// $"enableRandomWrite: {desc.enableRandomWrite}, useDynamicScale: {desc.useDynamicScale}, ");
desc.depthBufferBits = 0; // Color and depth cannot be combined in RTHandles
desc.stencilFormat = GraphicsFormat.None;
desc.depthStencilFormat = GraphicsFormat.None;
desc.msaaSamples = 1;
desc.bindMS = false;
desc.enableRandomWrite = true;
ref var cameraData = ref SSGI.CameraHistorySystem.GetCameraData();
if (cameraData.ColorPreviousFrame == null) cameraData.ColorPreviousFrame = new RTWrapper();
if (cameraData.ReservoirTemporal == null) cameraData.ReservoirTemporal = new RTWrapper();
if (cameraData.SampleCount == null) cameraData.SampleCount = new RTWrapper();
if (cameraData.NormalDepth == null) cameraData.NormalDepth = new RTWrapper();
if (cameraData.NormalDepthFullRes == null) cameraData.NormalDepthFullRes = new RTWrapper();
if (cameraData.Radiance == null) cameraData.Radiance = new RTWrapper();
if (cameraData.RadianceAccumulated == null) cameraData.RadianceAccumulated = new RTWrapper();
if (cameraData.SpatialOcclusionAccumulated == null) cameraData.SpatialOcclusionAccumulated = new RTWrapper();
if (cameraData.TemporalInvalidityAccumulated == null) cameraData.TemporalInvalidityAccumulated = new RTWrapper();
if (cameraData.AmbientOcclusionAccumulated == null) cameraData.AmbientOcclusionAccumulated = new RTWrapper();
cameraData.ColorPreviousFrame.ReAllocateIfNeeded(_ColorPreviousFrame, ref desc, graphicsFormat: GraphicsFormat.B10G11R11_UFloatPack32);
cameraData.ReservoirTemporal.ReAllocateIfNeeded(_ReservoirTemporal, ref desc, graphicsFormat: GraphicsFormat.R32G32B32A32_UInt);
cameraData.TemporalInvalidityAccumulated.ReAllocateIfNeeded(_TemporalInvalidityAccumulated, ref desc, graphicsFormat: GraphicsFormat.R8G8_UNorm);
cameraData.SpatialOcclusionAccumulated.ReAllocateIfNeeded(_SpatialOcclusionAccumulated, ref desc, graphicsFormat: GraphicsFormat.R8_UNorm);
cameraData.AmbientOcclusionAccumulated.ReAllocateIfNeeded(_AmbientOcclusionAccumulated, ref desc, graphicsFormat: GraphicsFormat.R8_UNorm);
cameraData.Radiance.ReAllocateIfNeeded(_Radiance, ref desc, graphicsFormat: profile.DenoisingSettings.RecurrentBlur ? GraphicsFormat.R16G16B16A16_SFloat : GraphicsFormat.B10G11R11_UFloatPack32);
cameraData.RadianceAccumulated.ReAllocateIfNeeded(_RadianceAccumulated, ref desc, graphicsFormat: GraphicsFormat.R16G16B16A16_SFloat);
cameraData.SampleCount.ReAllocateIfNeeded(_SampleCount, ref desc, graphicsFormat: GraphicsFormat.R16_SFloat);
cameraData.NormalDepth.ReAllocateIfNeeded(_NormalDepthHistory, ref desc, graphicsFormat: GraphicsFormat.R32_UInt);
cameraData.NormalDepthFullRes.ReAllocateIfNeeded(_NormalDepthHistoryFullRes, ref desc, graphicsFormat: GraphicsFormat.R32_UInt);
SSGI.ColorCopy_URP.ReAllocateIfNeeded(_ColorCopy, ref desc, graphicsFormat: GraphicsFormat.B10G11R11_UFloatPack32);
SSGI.DebugOutput.ReAllocateIfNeeded(_ColorCopy, ref desc, graphicsFormat: GraphicsFormat.B10G11R11_UFloatPack32);
SSGI.ColorReprojected.ReAllocateIfNeeded(_ColorReprojected, ref desc, graphicsFormat: GraphicsFormat.R32_UInt);
SSGI.Reservoir.ReAllocateIfNeeded(_Reservoir, ref desc, graphicsFormat: GraphicsFormat.R32G32B32A32_UInt);
SSGI.ReservoirReprojected.ReAllocateIfNeeded(_ReservoirReprojected, ref desc, graphicsFormat: GraphicsFormat.R32G32B32A32_UInt);
SSGI.ReservoirSpatial.ReAllocateIfNeeded(_ReservoirSpatial, ref desc, graphicsFormat: GraphicsFormat.R32G32B32A32_UInt);
SSGI.ReservoirLuminance.ReAllocateIfNeeded(_ReservoirLuminance, ref desc, graphicsFormat: GraphicsFormat.R16_SFloat);
SSGI.TemporalInvalidityFilteredA.ReAllocateIfNeeded(_TemporalInvalidityFilteredA, ref desc, graphicsFormat: GraphicsFormat.R8G8_UNorm);
SSGI.TemporalInvalidityFilteredB.ReAllocateIfNeeded(_TemporalInvalidityFilteredB, ref desc, graphicsFormat: GraphicsFormat.R8G8_UNorm);
SSGI.TemporalInvalidityReprojected.ReAllocateIfNeeded(_TemporalInvalidityReprojected, ref desc, graphicsFormat: GraphicsFormat.R8G8_UNorm);
SSGI.SpatialOcclusionReprojected.ReAllocateIfNeeded(_SpatialOcclusionReprojected, ref desc, graphicsFormat: GraphicsFormat.R8_UNorm);
SSGI.AmbientOcclusion.ReAllocateIfNeeded(_AmbientOcclusion, ref desc, graphicsFormat: GraphicsFormat.R8_SNorm);
SSGI.AmbientOcclusionGuidance.ReAllocateIfNeeded(_AmbientOcclusionGuidance, ref desc, graphicsFormat: GraphicsFormat.R8G8_UInt);
SSGI.AmbientOcclusionInvalidity.ReAllocateIfNeeded(_AmbientOcclusionInvalidity, ref desc, graphicsFormat: GraphicsFormat.R8_UNorm);
SSGI.AmbientOcclusionReprojected.ReAllocateIfNeeded(_AmbientOcclusionReprojected, ref desc, graphicsFormat: GraphicsFormat.R8_UNorm);
SSGI.RadianceFiltered.ReAllocateIfNeeded(_RadianceFiltered, ref desc, graphicsFormat: GraphicsFormat.B10G11R11_UFloatPack32);
SSGI.RadianceReprojected.ReAllocateIfNeeded(_RadianceReprojected, ref desc, graphicsFormat: GraphicsFormat.R16G16B16A16_SFloat);
SSGI.RadianceNormalDepth.ReAllocateIfNeeded(_RadianceNormalDepth, ref desc, graphicsFormat: GraphicsFormat.R32G32_UInt);
SSGI.RadianceInterpolated.ReAllocateIfNeeded(_RadianceInterpolated, ref desc, graphicsFormat: GraphicsFormat.B10G11R11_UFloatPack32);
SSGI.RadianceStabilizedReprojected.ReAllocateIfNeeded(_RadianceStabilizedReprojected, ref desc, graphicsFormat: GraphicsFormat.R16G16B16A16_SFloat);
SSGI.RadianceStabilized.ReAllocateIfNeeded(_RadianceStabilized, ref desc, graphicsFormat: GraphicsFormat.R16G16B16A16_SFloat);
SSGI.SamplecountReprojected.ReAllocateIfNeeded(_SamplecountReprojected, ref desc, graphicsFormat: GraphicsFormat.R16_SFloat);
SSGI.DummyBlackTexture.ReAllocateIfNeeded(_DummyBlackTexture, ref desc, graphicsFormat: GraphicsFormat.R8_UNorm);
if (SSGI.PointDistributionBuffer == null) SSGI.PointDistributionBuffer = new ComputeBuffer(32 * 4 * HRenderer.TextureXrSlices, 3 * sizeof(int));
if (SSGI.LuminanceMoments == null) SSGI.LuminanceMoments = new ComputeBuffer(2 * HRenderer.TextureXrSlices, 2 * sizeof(int));
if (SSGI.IndirectArguments == null) SSGI.IndirectArguments = new ComputeBuffer(3 * HRenderer.TextureXrSlices, sizeof(int), ComputeBufferType.IndirectArguments);
if (SSGI.IndirectCoords == null) SSGI.IndirectCoords = new HDynamicBuffer(BufferType.ComputeBuffer, 2 * sizeof(uint), HRenderer.TextureXrSlices, avoidDownscale: false);
SSGI.IndirectCoords.ReAllocIfNeeded(new Vector2Int(width, height));
if (SSGI.RayCounter == null)
{
SSGI.RayCounter = new ComputeBuffer(2 * 1, sizeof(uint));
uint[] zeroArray = new uint[2 * 1];
SSGI.RayCounter.SetData(zeroArray);
}
}
protected internal void Dispose()
{
var historyCameraDataSSGI = SSGI.CameraHistorySystem.GetCameraData();
historyCameraDataSSGI.ColorPreviousFrame?.HRelease();
historyCameraDataSSGI.ReservoirTemporal?.HRelease();
historyCameraDataSSGI.SampleCount?.HRelease();
historyCameraDataSSGI.NormalDepth?.HRelease();
historyCameraDataSSGI.NormalDepthFullRes?.HRelease();
historyCameraDataSSGI.Radiance?.HRelease();
historyCameraDataSSGI.RadianceAccumulated?.HRelease();
historyCameraDataSSGI.SpatialOcclusionAccumulated?.HRelease();
historyCameraDataSSGI.TemporalInvalidityAccumulated?.HRelease();
historyCameraDataSSGI.AmbientOcclusionAccumulated?.HRelease();
SSGI.ColorCopy_URP?.HRelease();
SSGI.DebugOutput?.HRelease();
SSGI.ColorReprojected?.HRelease();
SSGI.Reservoir?.HRelease();
SSGI.ReservoirReprojected?.HRelease();
SSGI.ReservoirSpatial?.HRelease();
SSGI.ReservoirLuminance?.HRelease();
SSGI.TemporalInvalidityFilteredA?.HRelease();
SSGI.TemporalInvalidityFilteredB?.HRelease();
SSGI.TemporalInvalidityReprojected?.HRelease();
SSGI.SpatialOcclusionReprojected?.HRelease();
SSGI.AmbientOcclusion?.HRelease();
SSGI.AmbientOcclusionGuidance?.HRelease();
SSGI.AmbientOcclusionInvalidity?.HRelease();
SSGI.AmbientOcclusionReprojected?.HRelease();
SSGI.RadianceFiltered?.HRelease();
SSGI.RadianceReprojected?.HRelease();
SSGI.RadianceNormalDepth?.HRelease();
SSGI.RadianceInterpolated?.HRelease();
SSGI.RadianceStabilizedReprojected?.HRelease();
SSGI.RadianceStabilized?.HRelease();
SSGI.SamplecountReprojected?.HRelease();
SSGI.DummyBlackTexture?.HRelease();
SSGI.PointDistributionBuffer.HRelease();
SSGI.LuminanceMoments.HRelease();
SSGI.RayCounter.HRelease();
SSGI.IndirectCoords.HRelease();
SSGI.IndirectArguments.HRelease();
SSGI.PointDistributionBuffer = null;
SSGI.LuminanceMoments = null;
SSGI.RayCounter = null;
SSGI.IndirectCoords = null;
SSGI.IndirectArguments = null;
}
#endregion ------------------------------------ Shared ------------------------------------
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 82482812f9bf9de4a878162fdf59954b
timeCreated: 1729952288
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Passes/URP/SSGIPassURP.cs
uploadId: 840002