feat: added htrace
This commit is contained in:
71
Assets/Plugins/HTraceSSGI/Scripts/Globals/HEnums.cs
Normal file
71
Assets/Plugins/HTraceSSGI/Scripts/Globals/HEnums.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
//pipelinedefine
|
||||
#define H_URP
|
||||
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace HTraceSSGI.Scripts.Globals
|
||||
{
|
||||
public enum ThicknessMode
|
||||
{
|
||||
Relative = 0,
|
||||
Uniform,
|
||||
}
|
||||
|
||||
public enum FallbackType
|
||||
{
|
||||
None = 0,
|
||||
Sky = 1,
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
APV = 2,
|
||||
#endif
|
||||
}
|
||||
|
||||
public enum BrightnessClamp
|
||||
{
|
||||
Manual = 0,
|
||||
Automatic = 1,
|
||||
}
|
||||
|
||||
public enum ReprojectionFilter
|
||||
{
|
||||
Linear4Taps = 0,
|
||||
Lanczos12Taps = 1,
|
||||
}
|
||||
|
||||
public enum AlphaCutout
|
||||
{
|
||||
Evaluate = 0,
|
||||
DepthTest = 1,
|
||||
}
|
||||
|
||||
public enum DebugMode
|
||||
{
|
||||
None = 0,
|
||||
MainBuffers = 1,
|
||||
DirectLighting = 2,
|
||||
GlobalIllumination = 3,
|
||||
TemporalDisocclusion = 4,
|
||||
}
|
||||
|
||||
public enum HBuffer
|
||||
{
|
||||
Multi,
|
||||
Depth,
|
||||
Diffuse,
|
||||
Normal,
|
||||
MotionMask,
|
||||
MotionVectors,
|
||||
}
|
||||
|
||||
public enum HInjectionPoint
|
||||
{
|
||||
}
|
||||
|
||||
public enum DebugType
|
||||
{
|
||||
Log,
|
||||
Warning,
|
||||
Error,
|
||||
}
|
||||
}
|
||||
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HEnums.cs.meta
Normal file
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HEnums.cs.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 597ae110d1b52354ba4a3f4c6452b96e
|
||||
timeCreated: 1661865051
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Globals/HEnums.cs
|
||||
uploadId: 840002
|
||||
183
Assets/Plugins/HTraceSSGI/Scripts/Globals/HMath.cs
Normal file
183
Assets/Plugins/HTraceSSGI/Scripts/Globals/HMath.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace HTraceSSGI.Scripts.Globals
|
||||
{
|
||||
public static class HMath
|
||||
{
|
||||
private static Vector2 RemapVoxelsCoeff = new Vector2(64f, 512f); //min - 64 VoxelResolution, max - 512 VoxelResolution
|
||||
|
||||
/// <summary>
|
||||
/// Remap from one range to another
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="oldLow"></param>
|
||||
/// <param name="oldHigh"></param>
|
||||
/// <param name="newLow"></param>
|
||||
/// <param name="newHigh"></param>
|
||||
/// <returns></returns>
|
||||
public static float Remap(float input, float oldLow, float oldHigh, float newLow, float newHigh)
|
||||
{
|
||||
float t = Mathf.InverseLerp(oldLow, oldHigh, input);
|
||||
return Mathf.Lerp(newLow, newHigh, t);
|
||||
}
|
||||
|
||||
// public static float RemapThickness(float thickness, ThicknessMode thicknessMode)
|
||||
// {
|
||||
// float result = 0f;
|
||||
// switch (thicknessMode)
|
||||
// {
|
||||
// case ThicknessMode.Standard:
|
||||
// result = Remap(thickness, 0f, 1f, 0f, 0.15f);
|
||||
// break;
|
||||
// case ThicknessMode.Accurate:
|
||||
// result = Remap(thickness, 0f, 1f, 0f, 0.05f);
|
||||
// break;
|
||||
// default:
|
||||
// Debug.LogError($"RemapThickness ERROR: thickness: {thickness}, ThicknessMode: {thicknessMode}");
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Thickness value pre-calculation for GI
|
||||
/// </summary>
|
||||
/// <param name="baseThickness"></param>
|
||||
/// <param name="camera"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2 ThicknessBias(float baseThickness, Camera camera)
|
||||
{
|
||||
baseThickness = Remap(baseThickness, 0f, 1f, 0f, 0.5f);
|
||||
float n = camera.nearClipPlane;
|
||||
float f = camera.farClipPlane;
|
||||
float thicknessScale = 1.0f / (1.0f + baseThickness);
|
||||
float thicknessBias = -n / (f - n) * (baseThickness * thicknessScale);
|
||||
return new Vector2((float)thicknessScale, (float)thicknessBias);
|
||||
}
|
||||
|
||||
public static Vector4 ComputeViewportScaleAndLimit(Vector2Int viewportSize, Vector2Int bufferSize)
|
||||
{
|
||||
return new Vector4(ComputeViewportScale(viewportSize.x, bufferSize.x), // Scale(x)
|
||||
ComputeViewportScale(viewportSize.y, bufferSize.y), // Scale(y)
|
||||
ComputeViewportLimit(viewportSize.x, bufferSize.x), // Limit(x)
|
||||
ComputeViewportLimit(viewportSize.y, bufferSize.y)); // Limit(y)
|
||||
}
|
||||
|
||||
public static float PixelSpreadTangent(float Fov, int Width, int Height)
|
||||
{
|
||||
return Mathf.Tan(Fov * Mathf.Deg2Rad * 0.5f) * 2.0f / Mathf.Min(Width, Height);
|
||||
}
|
||||
|
||||
public static float CalculateVoxelSizeInCM_UI(int bounds, float density)
|
||||
{
|
||||
float resolution = Mathf.CeilToInt(bounds / (bounds / HMath.Remap(density, 0f, 1f, HMath.RemapVoxelsCoeff.x, HMath.RemapVoxelsCoeff.y)));
|
||||
return bounds / resolution * 100f; //100 -> cm
|
||||
}
|
||||
|
||||
public static float TexturesSizeInMB_UI(int voxelBounds, float density, bool overrideGroundEnable, int GroundLevel)
|
||||
{
|
||||
float resolution = voxelBounds / (voxelBounds / HMath.Remap(density, 0f, 1f, HMath.RemapVoxelsCoeff.x, HMath.RemapVoxelsCoeff.y));
|
||||
float voxelSize = voxelBounds / resolution;
|
||||
float textureResolution = resolution * resolution;
|
||||
textureResolution *= overrideGroundEnable == true ? (GroundLevel / voxelSize) : resolution;
|
||||
float colorMemorySize = textureResolution * 32 / (1024 * 1024 * 8);
|
||||
float positionMemorySize = (textureResolution * 32 / (1024 * 1024 * 8)) + (textureResolution * 8 / (1024 * 1024 * 8));
|
||||
|
||||
return colorMemorySize + positionMemorySize;
|
||||
}
|
||||
|
||||
public static float TexturesSizeInMB_UI(Vector3Int voxelsRelosution)
|
||||
{
|
||||
float textureResolution = voxelsRelosution.x * voxelsRelosution.y * voxelsRelosution.z;
|
||||
float colorMemorySize = textureResolution * 32 / (1024 * 1024 * 8);
|
||||
float positionMemorySize = (textureResolution * 32 / (1024 * 1024 * 8)) + (textureResolution * 8 / (1024 * 1024 * 8));
|
||||
|
||||
return colorMemorySize + positionMemorySize;
|
||||
}
|
||||
|
||||
public static Vector3Int CalculateVoxelResolution_UI(int voxelBounds, float density, bool overrideGroundEnable, int GroundLevel)
|
||||
{
|
||||
Vector3Int resolutionResult = new Vector3Int();
|
||||
float resolution = HMath.Remap(density, 0f, 1f, HMath.RemapVoxelsCoeff.x, HMath.RemapVoxelsCoeff.y);
|
||||
resolutionResult.x = Mathf.CeilToInt(resolution);
|
||||
resolutionResult.y = Mathf.CeilToInt(resolution);
|
||||
|
||||
float height = (overrideGroundEnable == false ? voxelBounds : GroundLevel);
|
||||
resolutionResult.z = Mathf.CeilToInt(height / (voxelBounds / resolution));
|
||||
|
||||
resolutionResult.x = HMath.DevisionBy4(resolutionResult.x);
|
||||
resolutionResult.y = HMath.DevisionBy4(resolutionResult.y);
|
||||
resolutionResult.z = HMath.DevisionBy4(resolutionResult.z);
|
||||
|
||||
return resolutionResult;
|
||||
}
|
||||
|
||||
public static Vector3 Truncate(this Vector3 input, int digits)
|
||||
{
|
||||
return new Vector3(input.x.RoundTail(digits), input.y.RoundTail(digits), input.z.RoundTail(digits));
|
||||
}
|
||||
|
||||
public static Vector3 Ceil(this Vector3 input, int digits)
|
||||
{
|
||||
return new Vector3(input.x.RoundToCeilTail(digits), input.y.RoundToCeilTail(digits), input.z.RoundToCeilTail(digits));
|
||||
}
|
||||
|
||||
public static float RoundTail(this float value, int digits)
|
||||
{
|
||||
float mult = Mathf.Pow(10.0f, digits);
|
||||
float result = Mathf.Round(mult * value) / mult;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float RoundToCeilTail(this float value, int digits)
|
||||
{
|
||||
float mult = Mathf.Pow(10.0f, digits);
|
||||
float result = Mathf.Ceil(mult * value) / mult;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector2Int CalculateDepthPyramidResolution(Vector2Int screenResolution, int lowestMipLevel)
|
||||
{
|
||||
int lowestMipScale = (int)Mathf.Pow(2.0f, lowestMipLevel);
|
||||
Vector2Int lowestMipResolutiom = new Vector2Int(Mathf.CeilToInt( (float)screenResolution.x / (float)lowestMipScale),
|
||||
Mathf.CeilToInt( (float)screenResolution.y / (float)lowestMipScale));
|
||||
|
||||
Vector2Int paddedDepthPyramidResolution = lowestMipResolutiom * lowestMipScale;
|
||||
return paddedDepthPyramidResolution;
|
||||
}
|
||||
|
||||
public static int CalculateStepCountSSGI(float giRadius, float giAccuracy)
|
||||
{
|
||||
if (giRadius <= 25.0f)
|
||||
{
|
||||
//5 -> 16, 10 -> 20, 25 -> 25
|
||||
return Mathf.FloorToInt((-0.0233f * giRadius * giRadius + 1.15f * giRadius + 10.833f) * giAccuracy);
|
||||
}
|
||||
|
||||
//50 -> 35, 100 -> 50, 150 -> 64
|
||||
return Mathf.FloorToInt((-0.0002f * giRadius * giRadius + 0.33f * giRadius + 19f) * giAccuracy);
|
||||
}
|
||||
|
||||
private static int DevisionBy4(int value)
|
||||
{
|
||||
return value % 4 == 0 ? value : DevisionBy4(value + 1);
|
||||
}
|
||||
|
||||
private static float ComputeViewportScale(int viewportSize, int bufferSize)
|
||||
{
|
||||
float rcpBufferSize = 1.0f / bufferSize;
|
||||
|
||||
// Scale by (vp_dim / buf_dim).
|
||||
return viewportSize * rcpBufferSize;
|
||||
}
|
||||
|
||||
private static float ComputeViewportLimit(int viewportSize, int bufferSize)
|
||||
{
|
||||
float rcpBufferSize = 1.0f / bufferSize;
|
||||
|
||||
// Clamp to (vp_dim - 0.5) / buf_dim.
|
||||
return (viewportSize - 0.5f) * rcpBufferSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HMath.cs.meta
Normal file
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HMath.cs.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 120dbec02a6a0a4439d6623081e5ed7b
|
||||
timeCreated: 1661871568
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Globals/HMath.cs
|
||||
uploadId: 840002
|
||||
32
Assets/Plugins/HTraceSSGI/Scripts/Globals/HNames.cs
Normal file
32
Assets/Plugins/HTraceSSGI/Scripts/Globals/HNames.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace HTraceSSGI.Scripts.Globals
|
||||
{
|
||||
internal static class HNames
|
||||
{
|
||||
public const string ASSET_NAME = "HTraceSSGI";
|
||||
public const string ASSET_NAME_FULL = "HTrace Screen Space Global Illumination";
|
||||
public const string ASSET_NAME_FULL_WITH_DOTS = "HTrace: Screen Space Global Illumination";
|
||||
public const string HTRACE_SSGI_DOCUMENTATION_LINK = "https://ipgames.gitbook.io/htrace-ssgi";
|
||||
public const string HTRACE_SSGI_DOCUMENTATION_LINK_KNOWN_ISSUES = "https://ipgames.gitbook.io/htrace-ssgi/known-issues";
|
||||
public const string HTRACE_SSGI_DOCUMENTATION_LINK_FAQ = "https://ipgames.gitbook.io/htrace-ssgi/frequently-asked-questions";
|
||||
public const string HTRACE_DISCORD_LINK = "https://discord.com/invite/Nep56Efu7A";
|
||||
public const string HTRACE_DISCORD_BUGS_SSGI_LINK = "https://discord.gg/4FN9wsYt5T";
|
||||
public const string HTRACE_SSGI_VERSION = "1.2.0";
|
||||
|
||||
//Prefs
|
||||
public const string HTRACE_SHOW_KEY = "HTraceSSGI_ShowWelcomeWindow";
|
||||
public const string HTRACE_WELCOME_SHOW_SESSION = "HTraceSSGI_ShowWelcomeWindowSessions";
|
||||
public const string HTRACE_UNITY_VERSION_KEY = "HTraceSSGI_UnityVersion";
|
||||
|
||||
// ---------------- Profiling ----------------
|
||||
public const string HTRACE_PRE_PASS_NAME = "HTraceSSGI Pre Pass";
|
||||
public const string HTRACE_MV_PASS_NAME = "HTraceSSGI Motion Vectors Pass";
|
||||
public const string HTRACE_OBJECTS_MV_PASS_NAME = "HTraceSSGI Objects Motion Vectors Pass";
|
||||
public const string HTRACE_CAMERA_MV_PASS_NAME = "HTraceSSGI Camera Motion Vectors Pass";
|
||||
public const string HTRACE_GBUFFER_PASS_NAME = "HTraceSSGI GBuffer Pass";
|
||||
public const string HTRACE_SSGI_PASS_NAME = "HTraceSSGI SSGI Pass";
|
||||
public const string HTRACE_FINAL_PASS_NAME = "HTraceSSGI Final Pass";
|
||||
|
||||
public const string KEYWORD_SWITCHER = "HTRACEGI_OVERRIDE";
|
||||
//public const string INT_SWITCHER = "_HTRACE_INT_OVERRIDE";
|
||||
}
|
||||
}
|
||||
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HNames.cs.meta
Normal file
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HNames.cs.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a739df963d4e354f8d13ac9e5e6ee44
|
||||
timeCreated: 1691582446
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Globals/HNames.cs
|
||||
uploadId: 840002
|
||||
135
Assets/Plugins/HTraceSSGI/Scripts/Globals/HRenderer.cs
Normal file
135
Assets/Plugins/HTraceSSGI/Scripts/Globals/HRenderer.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
//pipelinedefine
|
||||
#define H_URP
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using HTraceSSGI.Scripts.Infrastructure.URP;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace HTraceSSGI.Scripts.Globals
|
||||
{
|
||||
public enum HRenderPipeline
|
||||
{
|
||||
None,
|
||||
BIRP,
|
||||
URP,
|
||||
HDRP
|
||||
}
|
||||
|
||||
public static class HRenderer
|
||||
{
|
||||
static HRenderPipeline s_CurrentHRenderPipeline = HRenderPipeline.None;
|
||||
|
||||
public static HRenderPipeline CurrentHRenderPipeline
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_CurrentHRenderPipeline == HRenderPipeline.None)
|
||||
{
|
||||
s_CurrentHRenderPipeline = GetRenderPipeline();
|
||||
}
|
||||
return s_CurrentHRenderPipeline;
|
||||
}
|
||||
}
|
||||
|
||||
private static HRenderPipeline GetRenderPipeline()
|
||||
{
|
||||
if (GraphicsSettings.currentRenderPipeline)
|
||||
{
|
||||
if (GraphicsSettings.currentRenderPipeline.GetType().ToString().Contains("HighDefinition"))
|
||||
return HRenderPipeline.HDRP;
|
||||
else
|
||||
return HRenderPipeline.URP;
|
||||
}
|
||||
|
||||
return HRenderPipeline.BIRP;
|
||||
}
|
||||
|
||||
public static bool SupportsInlineRayTracing
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
return SystemInfo.supportsInlineRayTracing;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SupportsRayTracing
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER // TODO: revert this to 2019 when raytracing issue in 2022 is resolved
|
||||
if (SystemInfo.supportsRayTracing == false)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int TextureXrSlices
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Application.isPlaying == false)
|
||||
return 1;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static RenderTexture emptyTexture;
|
||||
public static RenderTexture EmptyTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (emptyTexture == null)
|
||||
{
|
||||
emptyTexture = new RenderTexture(4, 4, 0);
|
||||
emptyTexture.enableRandomWrite = true;
|
||||
emptyTexture.dimension = TextureDimension.Tex2D;
|
||||
emptyTexture.format = RenderTextureFormat.ARGBFloat;
|
||||
emptyTexture.Create();
|
||||
}
|
||||
|
||||
return emptyTexture;
|
||||
}
|
||||
}
|
||||
|
||||
private static Mesh _fullscreenTriangle;
|
||||
public static Mesh FullscreenTriangle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_fullscreenTriangle != null)
|
||||
return _fullscreenTriangle;
|
||||
|
||||
_fullscreenTriangle = new Mesh { name = "Fullscreen Triangle" };
|
||||
|
||||
// Because we have to support older platforms (GLES2/3, DX9 etc) we can't do all of
|
||||
// this directly in the vertex shader using vertex ids :(
|
||||
_fullscreenTriangle.SetVertices(new List<Vector3>
|
||||
{
|
||||
new Vector3(-1f, -1f, 0f),
|
||||
new Vector3(-1f, 3f, 0f),
|
||||
new Vector3( 3f, -1f, 0f)
|
||||
});
|
||||
_fullscreenTriangle.SetIndices(new[] { 0, 1, 2 }, MeshTopology.Triangles, 0, false);
|
||||
_fullscreenTriangle.UploadMeshData(false);
|
||||
|
||||
return _fullscreenTriangle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HRenderer.cs.meta
Normal file
10
Assets/Plugins/HTraceSSGI/Scripts/Globals/HRenderer.cs.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 360412b93660c734f943ed19ba9c2e52
|
||||
timeCreated: 1727432136
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Globals/HRenderer.cs
|
||||
uploadId: 840002
|
||||
264
Assets/Plugins/HTraceSSGI/Scripts/Globals/HRendererURP.cs
Normal file
264
Assets/Plugins/HTraceSSGI/Scripts/Globals/HRendererURP.cs
Normal file
@@ -0,0 +1,264 @@
|
||||
//pipelinedefine
|
||||
#define H_URP
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using HTraceSSGI.Scripts.Infrastructure.URP;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace HTraceSSGI.Scripts.Globals
|
||||
{
|
||||
public static class HRendererURP
|
||||
{
|
||||
public static bool RenderGraphEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
return GraphicsSettings.GetRenderPipelineSettings<RenderGraphSettings>().enableRenderCompatibilityMode == false;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static UniversalRenderPipelineAsset UrpAsset =>
|
||||
GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset urpAsset ? urpAsset : null;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private static FieldInfo s_rendererDataListFieldInfo;
|
||||
private static FieldInfo s_defaultRendererIndexFieldInfo;
|
||||
|
||||
private static ScriptableRendererData[] GetRendererDataList()
|
||||
{
|
||||
var urpAsset = UrpAsset;
|
||||
if (urpAsset == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
if (s_rendererDataListFieldInfo == null)
|
||||
s_rendererDataListFieldInfo = typeof(UniversalRenderPipelineAsset)
|
||||
.GetField("m_RendererDataList", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
if (s_rendererDataListFieldInfo == null)
|
||||
return null;
|
||||
|
||||
return (ScriptableRendererData[])s_rendererDataListFieldInfo.GetValue(urpAsset);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Failed to get renderer data list: {e.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetDefaultRendererIndex()
|
||||
{
|
||||
var urpAsset = UrpAsset;
|
||||
if (urpAsset == null)
|
||||
return -1;
|
||||
|
||||
try
|
||||
{
|
||||
if (s_defaultRendererIndexFieldInfo == null)
|
||||
s_defaultRendererIndexFieldInfo = typeof(UniversalRenderPipelineAsset)
|
||||
.GetField("m_DefaultRendererIndex", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
if (s_defaultRendererIndexFieldInfo == null)
|
||||
return -1;
|
||||
|
||||
return (int)s_defaultRendererIndexFieldInfo.GetValue(urpAsset);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Failed to get default renderer index: {e.Message}");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static UniversalRendererData UniversalRendererData => GetUniversalRendererData();
|
||||
|
||||
/// <summary>
|
||||
/// Get UniversalRendererData by index or default
|
||||
/// </summary>
|
||||
/// <param name="rendererIndex">Renderer index. If -1 - than default</param>
|
||||
/// <returns></returns>
|
||||
private static UniversalRendererData GetUniversalRendererData(int rendererIndex = -1)
|
||||
{
|
||||
var rendererDataList = GetRendererDataList();
|
||||
if (rendererDataList == null || rendererDataList.Length == 0)
|
||||
return null;
|
||||
|
||||
if (rendererIndex == -1) rendererIndex = GetDefaultRendererIndex();
|
||||
|
||||
// Index validation
|
||||
if (rendererIndex < 0 || rendererIndex >= rendererDataList.Length)
|
||||
{
|
||||
Debug.LogWarning(
|
||||
$"Invalid renderer index {rendererIndex}. Available renderers: {rendererDataList.Length}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return rendererDataList[rendererIndex] as UniversalRendererData;
|
||||
}
|
||||
|
||||
public static bool IsSsaoNativeEnabled()
|
||||
{
|
||||
return HasRendererFeatureByTypeName("ScreenSpaceAmbientOcclusion");
|
||||
}
|
||||
|
||||
private static bool HasRendererFeatureByTypeName(string typeName, int rendererIndex = -1)
|
||||
{
|
||||
return GetRendererFeatureByTypeName(typeName, rendererIndex) != null;
|
||||
}
|
||||
|
||||
public static ScriptableRendererFeature GetRendererFeatureByTypeName(string typeName, int rendererIndex = -1)
|
||||
{
|
||||
var rendererDataList = GetRendererDataList();
|
||||
if (rendererDataList == null || rendererDataList.Length == 0)
|
||||
return null;
|
||||
|
||||
var renderersToSearch = new List<ScriptableRendererData>();
|
||||
|
||||
if (rendererIndex >= 0 && rendererIndex < rendererDataList.Length)
|
||||
renderersToSearch.Add(rendererDataList[rendererIndex]);
|
||||
else
|
||||
renderersToSearch.AddRange(rendererDataList);
|
||||
|
||||
foreach (var rendererData in renderersToSearch)
|
||||
{
|
||||
if (rendererData?.rendererFeatures == null) continue;
|
||||
|
||||
foreach (var feature in rendererData.rendererFeatures)
|
||||
{
|
||||
if (feature == null) continue;
|
||||
|
||||
if (feature.GetType().Name.Contains(typeName, StringComparison.OrdinalIgnoreCase)) return feature;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static T GetRendererFeature<T>(int rendererIndex = -1) where T : ScriptableRendererFeature
|
||||
{
|
||||
var rendererDataList = GetRendererDataList();
|
||||
if (rendererDataList == null || rendererDataList.Length == 0)
|
||||
return null;
|
||||
|
||||
var renderersToSearch = new List<ScriptableRendererData>();
|
||||
|
||||
if (rendererIndex >= 0 && rendererIndex < rendererDataList.Length)
|
||||
renderersToSearch.Add(rendererDataList[rendererIndex]);
|
||||
else
|
||||
renderersToSearch.AddRange(rendererDataList);
|
||||
|
||||
foreach (var rendererData in renderersToSearch)
|
||||
{
|
||||
if (rendererData?.rendererFeatures == null) continue;
|
||||
|
||||
foreach (var feature in rendererData.rendererFeatures)
|
||||
if (feature is T typedFeature)
|
||||
return typedFeature;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool ContainsRenderFeature(List<ScriptableRendererFeature> features, string name)
|
||||
{
|
||||
if (features == null) return false;
|
||||
|
||||
for (var i = 0; i < features.Count; i++)
|
||||
if (features[i]?.name == name)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void AddHTraceRendererFeatureToUniversalRendererData()
|
||||
{
|
||||
var universalRendererData = UniversalRendererData;
|
||||
if (universalRendererData?.rendererFeatures == null)
|
||||
{
|
||||
Debug.LogWarning("Universal Renderer Data not found or has no features list");
|
||||
return;
|
||||
}
|
||||
|
||||
var features = universalRendererData.rendererFeatures;
|
||||
|
||||
CleanupRendererFeatures(features);
|
||||
|
||||
if (!ContainsRenderFeature(features, nameof(HTraceSSGIRendererFeature)))
|
||||
AddHTraceRendererFeature(universalRendererData, features);
|
||||
|
||||
universalRendererData.SetDirty();
|
||||
}
|
||||
|
||||
private static void CleanupRendererFeatures(List<ScriptableRendererFeature> features)
|
||||
{
|
||||
for (var i = features.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var feature = features[i];
|
||||
|
||||
// Delete null elements
|
||||
if (feature == null)
|
||||
{
|
||||
features.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feature.GetType() == typeof(HTraceSSGIRendererFeature)) features.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddHTraceRendererFeature(UniversalRendererData universalRendererData, List<ScriptableRendererFeature> features)
|
||||
{
|
||||
try
|
||||
{
|
||||
var hTraceFeature = ScriptableObject.CreateInstance<HTraceSSGIRendererFeature>();
|
||||
AssetDatabase.AddObjectToAsset(hTraceFeature, universalRendererData);
|
||||
features.Add(hTraceFeature);
|
||||
|
||||
Debug.Log($"{HNames.ASSET_NAME} Renderer Feature added successfully");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Failed to add {HNames.ASSET_NAME} Renderer Feature: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all renderer features by Type in all RendererDatas
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Тип renderer feature</typeparam>
|
||||
/// <returns></returns>
|
||||
public static List<T> GetAllRendererFeatures<T>() where T : ScriptableRendererFeature
|
||||
{
|
||||
var result = new List<T>();
|
||||
var rendererDataList = GetRendererDataList();
|
||||
|
||||
if (rendererDataList == null) return result;
|
||||
|
||||
foreach (var rendererData in rendererDataList)
|
||||
{
|
||||
if (rendererData?.rendererFeatures == null) continue;
|
||||
|
||||
foreach (var feature in rendererData.rendererFeatures)
|
||||
if (feature is T typedFeature)
|
||||
result.Add(typedFeature);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int GetRenderersCount()
|
||||
{
|
||||
return GetRendererDataList()?.Length ?? 0;
|
||||
}
|
||||
#endif // UNITY_EDITOR
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c6ca928c19f4bff95978f4d91d3733e
|
||||
timeCreated: 1757343206
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Globals/HRendererURP.cs
|
||||
uploadId: 840002
|
||||
75
Assets/Plugins/HTraceSSGI/Scripts/Globals/HShaderParams.cs
Normal file
75
Assets/Plugins/HTraceSSGI/Scripts/Globals/HShaderParams.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace HTraceSSGI.Scripts.Globals
|
||||
{
|
||||
public static class HShaderParams
|
||||
{
|
||||
// ---------------------------------------------- Globals, "g_" prefix ----------------------------------------------
|
||||
public static readonly int g_HTraceGBuffer0 = Shader.PropertyToID("g_HTraceGBuffer0");
|
||||
public static readonly int g_HTraceGBuffer1 = Shader.PropertyToID("g_HTraceGBuffer1");
|
||||
public static readonly int g_HTraceGBuffer2 = Shader.PropertyToID("g_HTraceGBuffer2");
|
||||
public static readonly int g_HTraceGBuffer3 = Shader.PropertyToID("g_HTraceGBuffer3");
|
||||
public static readonly int g_HTraceRenderLayerMask = Shader.PropertyToID("g_HTraceRenderLayerMask");
|
||||
public static readonly int g_HTraceColor = Shader.PropertyToID("g_HTraceColor");
|
||||
public static readonly int g_HTraceDepth = Shader.PropertyToID("g_HTraceDepth");
|
||||
public static readonly int g_HTraceNormals = Shader.PropertyToID("g_HTraceNormals");
|
||||
public static readonly int g_HTraceSSAO = Shader.PropertyToID("g_HTraceSSAO");
|
||||
public static readonly int g_HTraceDepthPyramidSSGI = Shader.PropertyToID("g_HTraceDepthPyramidSSGI");
|
||||
public static readonly int g_HTraceStencilBuffer = Shader.PropertyToID("g_HTraceStencilBuffer");
|
||||
public static readonly int g_HTraceMotionVectors = Shader.PropertyToID("g_HTraceMotionVectors");
|
||||
public static readonly int g_HTraceMotionMask = Shader.PropertyToID("g_HTraceMotionMask");
|
||||
public static readonly int g_HTraceBufferAO = Shader.PropertyToID("_HTraceBufferAO");
|
||||
public static readonly int g_ScreenSpaceOcclusionTexture = Shader.PropertyToID("_ScreenSpaceOcclusionTexture");
|
||||
public static readonly int g_CameraDepthTexture = Shader.PropertyToID("_CameraDepthTexture");
|
||||
public static readonly int g_CameraNormalsTexture = Shader.PropertyToID("_CameraNormalsTexture");
|
||||
|
||||
|
||||
// ---------------------------------------------- GBuffer ----------------------------------------------
|
||||
public static readonly int _GBuffer0 = Shader.PropertyToID("_GBuffer0");
|
||||
public static readonly int _GBuffer1 = Shader.PropertyToID("_GBuffer1");
|
||||
public static readonly int _GBuffer2 = Shader.PropertyToID("_GBuffer2");
|
||||
public static readonly int _GBuffer3 = Shader.PropertyToID("_GBuffer3");
|
||||
public static readonly int _CameraRenderingLayersTexture = Shader.PropertyToID("_CameraRenderingLayersTexture");
|
||||
public static readonly int _GBufferTexture0 = Shader.PropertyToID("_GBufferTexture0");
|
||||
public static readonly int _RenderingLayerMaskTexture = Shader.PropertyToID("_RenderingLayersTexture");
|
||||
public static readonly int _CameraGBufferTexture0 = Shader.PropertyToID("_CameraGBufferTexture0");
|
||||
|
||||
public static readonly int _DepthPyramid_OutputMIP0 = Shader.PropertyToID("_DepthPyramid_OutputMIP0");
|
||||
public static readonly int _DepthPyramid_OutputMIP1 = Shader.PropertyToID("_DepthPyramid_OutputMIP1");
|
||||
public static readonly int _DepthPyramid_OutputMIP2 = Shader.PropertyToID("_DepthPyramid_OutputMIP2");
|
||||
public static readonly int _DepthPyramid_OutputMIP3 = Shader.PropertyToID("_DepthPyramid_OutputMIP3");
|
||||
public static readonly int _DepthPyramid_OutputMIP4 = Shader.PropertyToID("_DepthPyramid_OutputMIP4");
|
||||
|
||||
public static readonly int H_SHAr = Shader.PropertyToID("H_SHAr");
|
||||
public static readonly int H_SHAg = Shader.PropertyToID("H_SHAg");
|
||||
public static readonly int H_SHAb = Shader.PropertyToID("H_SHAb");
|
||||
public static readonly int H_SHBr = Shader.PropertyToID("H_SHBr");
|
||||
public static readonly int H_SHBg = Shader.PropertyToID("H_SHBg");
|
||||
public static readonly int H_SHBb = Shader.PropertyToID("H_SHBb");
|
||||
public static readonly int H_SHC = Shader.PropertyToID("H_SHC");
|
||||
|
||||
public static readonly string _GBUFFER_NORMALS_OCT = "_GBUFFER_NORMALS_OCT";
|
||||
public static readonly string _WRITE_RENDERING_LAYERS = "_WRITE_RENDERING_LAYERS";
|
||||
|
||||
public static readonly ShaderTagId UniversalGBufferTag = new ShaderTagId("UniversalGBuffer");
|
||||
|
||||
// ---------------------------------------------- Matrix ----------------------------------------------
|
||||
public static readonly int H_MATRIX_VP = Shader.PropertyToID("_H_MATRIX_VP");
|
||||
public static readonly int H_MATRIX_I_VP = Shader.PropertyToID("_H_MATRIX_I_VP");
|
||||
public static readonly int H_MATRIX_PREV_VP = Shader.PropertyToID("_H_MATRIX_PREV_VP");
|
||||
public static readonly int H_MATRIX_PREV_I_VP = Shader.PropertyToID("_H_MATRIX_PREV_I_VP");
|
||||
|
||||
// ---------------------------------------------- Additional ----------------------------------------------
|
||||
public static int HRenderScale = Shader.PropertyToID("_HRenderScale");
|
||||
public static int HRenderScalePrevious = Shader.PropertyToID("_HRenderScalePrevious");
|
||||
public static int FrameCount = Shader.PropertyToID("_FrameCount");
|
||||
public static int ScreenSize = Shader.PropertyToID("_ScreenSize");
|
||||
|
||||
// ---------------------------------------------- Shared Params Other ----------------------------------------------
|
||||
public static readonly int SliceXR = Shader.PropertyToID("_SliceXR");
|
||||
public static readonly int IndexXR = Shader.PropertyToID("_IndexXR");
|
||||
|
||||
public static readonly int RTAS = Shader.PropertyToID("_RTAS");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4df35d7b3e464734bb736f10640562a2
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Globals/HShaderParams.cs
|
||||
uploadId: 840002
|
||||
Reference in New Issue
Block a user