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: 2ce18ebb0d794317835a43506e011560
timeCreated: 1756743209

View File

@@ -0,0 +1,71 @@
using System;
namespace HTraceSSGI.Scripts.Extensions.CameraHistorySystem
{
public class CameraHistorySystem<T> where T : struct, ICameraHistoryData
{
private const int MaxCameraCount = 4; // minimum 2
private int _cameraHistoryIndex;
private readonly T[] _cameraHistoryData = new T[MaxCameraCount];
public int UpdateCameraHistoryIndex(int currentCameraHash)
{
_cameraHistoryIndex = GetCameraHistoryDataIndex(currentCameraHash);
return _cameraHistoryIndex;
}
private int GetCameraHistoryDataIndex(int cameraHash)
{
// Unroll manually for MAX_CAMERA_COUNT = 4
if (_cameraHistoryData[0].GetHash() == cameraHash) return 0;
if (_cameraHistoryData[1].GetHash() == cameraHash) return 1;
if (_cameraHistoryData[2].GetHash() == cameraHash) return 2;
if (_cameraHistoryData[3].GetHash() == cameraHash) return 3;
return -1; // new camera
}
public void UpdateCameraHistoryData()
{
bool cameraHasChanged = _cameraHistoryIndex == -1;
if (cameraHasChanged)
{
const int lastIndex = MaxCameraCount - 1;
if (_cameraHistoryData[lastIndex] is IDisposable disposable)
disposable.Dispose();
// Shift the camera history data back by one
Array.Copy(_cameraHistoryData, 0, _cameraHistoryData, 1, lastIndex);
_cameraHistoryIndex = 0;
_cameraHistoryData[0] = new T(); //it's critical
}
}
public ref T GetCameraData()
{
return ref _cameraHistoryData[_cameraHistoryIndex];
}
public T[] GetCameraDatas()
{
return _cameraHistoryData;
}
public void SetCameraData(T data)
{
_cameraHistoryData[_cameraHistoryIndex] = data;
}
public void Cleanup()
{
for (int index = 0; index < _cameraHistoryData.Length; index++)
{
_cameraHistoryData[index] = default;
}
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
namespace HTraceSSGI.Scripts.Extensions.CameraHistorySystem
{
public interface ICameraHistoryData
{
int GetHash();
void SetHash(int hashIn);
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 0c7d445abdf7490a9ce172328c1955e4
timeCreated: 1756743242
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Extensions/CameraHistorySystem/ICameraHistoryData.cs
uploadId: 840002

View File

@@ -0,0 +1,32 @@
//pipelinedefine
#define H_URP
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering.Universal;
#if UNITY_2023_3_OR_NEWER
using UnityEngine.Rendering.RenderGraphModule;
#endif
namespace HTraceSSGI.Scripts.Extensions
{
public class ExtensionsURP
{
#if UNITY_2023_3_OR_NEWER
public static TextureHandle CreateTexture(string name, RenderGraph rg, ref TextureDesc desc, GraphicsFormat format, DepthBits depthBufferBits = DepthBits.None,
bool enableRandomWrite = true, bool useMipMap = false, bool autoGenerateMips = false)
{
desc.name = name;
desc.format = format;
desc.depthBufferBits = depthBufferBits;
desc.enableRandomWrite = enableRandomWrite;
desc.useMipMap = useMipMap;
desc.autoGenerateMips = autoGenerateMips;
desc.msaaSamples = MSAASamples.None;
return rg.CreateTexture(desc);
}
#endif //UNITY_2023_3_OR_NEWER
}
}

View File

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

View File

@@ -0,0 +1,261 @@
//pipelinedefine
#define H_URP
using System;
using System.Reflection;
using HTraceSSGI.Scripts.Globals;
using HTraceSSGI.Scripts.Wrappers;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
#if UNITY_2021 || UNITY_2022
using UnityEngine.Experimental.Rendering;
#endif
namespace HTraceSSGI.Scripts.Extensions
{
public static class HExtensions
{
public static void DebugPrint(DebugType type, string msg)
{
msg = "HTrace log: " + msg;
switch (type)
{
case DebugType.Log:
Debug.Log(msg);
break;
case DebugType.Warning:
Debug.LogWarning(msg);
break;
case DebugType.Error:
Debug.LogError(msg);
break;
}
}
public static ComputeShader LoadComputeShader(string shaderName)
{
var computeShader = (ComputeShader)UnityEngine.Resources.Load($"HTraceSSGI/Computes/{shaderName}");
if (computeShader == null)
{
Debug.LogError($"{shaderName} is missing in HTraceSSGI/Computes folder");
return null;
}
return computeShader;
}
public static RayTracingShader LoadRayTracingShader(string shaderName)
{
var rtShader = (RayTracingShader)UnityEngine.Resources.Load($"HTraceSSGI/Computes/{shaderName}");
if (rtShader == null)
{
Debug.LogError($"{shaderName} is missing in HTraceSSGI/Computes folder");
return null;
}
return rtShader;
}
public static bool ContainsOnOfElement(this string str, string[] elements)
{
foreach (var element in elements)
{
if (str.Contains(element))
return true;
}
return false;
}
public static T NextEnum<T>(this T src) where T : struct
{
if (!typeof(T).IsEnum) throw new ArgumentException(String.Format("Argument {0} is not an Enum", typeof(T).FullName));
T[] Arr = (T[])Enum.GetValues(src.GetType());
int j = Array.IndexOf<T>(Arr, src) + 1;
src = (Arr.Length == j) ? Arr[0] : Arr[j];
return src;
}
public static bool IsUnityLTS(string version)
{
// 2023.1.5f1
if (!Version.TryParse(GetNumericVersion(version), out var current))
return false;
return
current >= new Version(6000, 3, 0) && current < new Version(6000, 3, 100) ||
current >= new Version(6000, 0, 23) && current < new Version(6000, 0, 100) ||
current >= new Version(2022, 3, 0) && current < new Version(2022, 3, 100) ||
current >= new Version(2023, 1, 0) && current < new Version(2023, 1, 100) ||
current >= new Version(2023, 2, 0) && current < new Version(2023, 2, 100);
}
private static string GetNumericVersion(string version)
{
int index = version.IndexOfAny(new[] { 'f', 'a', 'b' });
return index > 0 ? version.Substring(0, index) : version;
}
//custom Attributes
#if UNITY_EDITOR
/// <summary>
/// Read Only attribute.
/// Attribute is use only to mark ReadOnly properties.
/// </summary>
public class ReadOnlyAttribute : PropertyAttribute
{
}
/// <summary>
/// This class contain custom drawer for ReadOnly attribute.
/// </summary>
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
/// <summary>
/// Unity method for drawing GUI in Editor
/// </summary>
/// <param name="position">Position.</param>
/// <param name="property">Property.</param>
/// <param name="label">Label.</param>
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Saving previous GUI enabled value
var previousGUIState = GUI.enabled;
// Disabling edit for property
GUI.enabled = false;
// Drawing Property
EditorGUI.PropertyField(position, property, label);
// Setting old GUI enabled value
GUI.enabled = previousGUIState;
}
}
#endif
/// <summary>
/// <para>Attribute used to make a float or int variable in a script be restricted to a specific range.</para>
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class HRangeAttribute : Attribute
{
public readonly bool isFloat;
public readonly float minFloat;
public readonly float maxFloat;
public readonly int minInt;
public readonly int maxInt;
/// <summary>
/// <para>Attribute used to make a float or int variable in a script be restricted to a specific range.</para>
/// </summary>
/// <param name="minFloat">The minimum allowed value.</param>
/// <param name="maxFloat">The maximum allowed value.</param>
public HRangeAttribute(float minFloat, float maxFloat)
{
this.minFloat = minFloat;
this.maxFloat = maxFloat;
isFloat = true;
}
/// <summary>
/// <para>Attribute used to make a float or int variable in a script be restricted to a specific range.</para>
/// </summary>
/// <param name="minFloat">The minimum allowed value.</param>
/// <param name="maxFloat">The maximum allowed value.</param>
public HRangeAttribute(int minInt, int maxInt)
{
this.minInt = minInt;
this.maxInt = maxInt;
isFloat = false;
}
}
public struct HRangeAttributeElement
{
public bool isFloat;
public float minFloat;
public float maxFloat;
public int minInt;
public int maxInt;
}
public static float Clamp(float value, Type type, string nameOfField)
{
HRangeAttribute rangeAttribute = null;
var filed = type.GetField(nameOfField);
if (filed != null)
{
rangeAttribute = filed.GetCustomAttribute<HRangeAttribute>();
}
var property = type.GetProperty(nameOfField);
if (property != null)
{
rangeAttribute = property.GetCustomAttribute<HRangeAttribute>();
}
return Mathf.Clamp(value, rangeAttribute.minFloat, rangeAttribute.maxFloat);
}
public static int Clamp(int value, Type type, string nameOfField)
{
HRangeAttribute rangeAttribute = null;
var filed = type.GetField(nameOfField);
if (filed != null)
{
rangeAttribute = filed.GetCustomAttribute<HRangeAttribute>();
}
var property = type.GetProperty(nameOfField);
if (property != null)
{
rangeAttribute = property.GetCustomAttribute<HRangeAttribute>();
}
return Mathf.Clamp(value, rangeAttribute.minInt, rangeAttribute.maxInt);
}
public static void HRelease(this ComputeBuffer computeBuffer)
{
if (computeBuffer != null)
computeBuffer.Release();
}
public static void HRelease(this CommandBuffer commandBuffer)
{
if (commandBuffer != null)
{
commandBuffer.Clear();
commandBuffer.Release();
}
}
public static void HRelease(this GraphicsBuffer graphicsBuffer)
{
if (graphicsBuffer != null)
{
graphicsBuffer.Release();
}
}
public static void HRelease(this HDynamicBuffer hDynamicBuffer)
{
if (hDynamicBuffer != null)
{
hDynamicBuffer.Release();
}
}
public static void HRelease(this RayTracingAccelerationStructure rayTracingAccelerationStructure)
{
if (rayTracingAccelerationStructure != null)
{
rayTracingAccelerationStructure.Release();
}
}
}
}

View File

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

View File

@@ -0,0 +1,7 @@
namespace HTraceSSGI.Scripts.Extensions
{
public interface IHistoryData
{
void Update();
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 09c7949fa72d433aa944d9be383f2372
timeCreated: 1757489511
AssetOrigin:
serializedVersion: 1
productId: 336896
packageName: 'HTrace: Screen Space Global Illumination URP'
packageVersion: 1.2.0
assetPath: Assets/HTraceSSGI/Scripts/Extensions/IHistoryData.cs
uploadId: 840002