maint: added htrace ssgi
This commit is contained in:
92
Assets/Plugins/HTraceSSGI/Scripts/Wrappers/HDynamicBuffer.cs
Normal file
92
Assets/Plugins/HTraceSSGI/Scripts/Wrappers/HDynamicBuffer.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace HTraceSSGI.Scripts.Wrappers
|
||||
{
|
||||
public enum BufferType
|
||||
{
|
||||
ComputeBuffer,
|
||||
GraphicsBuffer,
|
||||
}
|
||||
|
||||
public class HDynamicBuffer
|
||||
{
|
||||
private ComputeBuffer _computeBuffer;
|
||||
private GraphicsBuffer _graphicsBuffer;
|
||||
|
||||
private readonly BufferType _bufferType;
|
||||
private readonly int _stride;
|
||||
private int _count;
|
||||
private int _countScale;
|
||||
private Vector2Int _resolution;
|
||||
private readonly ComputeBufferType _computeBufferType;
|
||||
private readonly GraphicsBuffer.Target _graphicsBufferType;
|
||||
private readonly bool _avoidDownscale;
|
||||
|
||||
public ComputeBuffer ComputeBuffer => _computeBuffer;
|
||||
public GraphicsBuffer GraphicsBuffer => _graphicsBuffer;
|
||||
public int Count => _count;
|
||||
public Vector2Int Resolution => _resolution;
|
||||
|
||||
public bool IsCreated => _bufferType == BufferType.GraphicsBuffer ? _graphicsBuffer != null : _computeBuffer != null;
|
||||
|
||||
public HDynamicBuffer(BufferType bufferType, int stride, int countScale = 1,
|
||||
ComputeBufferType computeBufferType = ComputeBufferType.Default, GraphicsBuffer.Target graphicsBufferType = GraphicsBuffer.Target.Structured,
|
||||
bool avoidDownscale = false)
|
||||
{
|
||||
_countScale = Mathf.Max(1, countScale);
|
||||
_stride = stride;
|
||||
_bufferType = bufferType;
|
||||
_computeBufferType = computeBufferType;
|
||||
_graphicsBufferType = graphicsBufferType;
|
||||
_avoidDownscale = avoidDownscale;
|
||||
}
|
||||
|
||||
public void ReAllocIfNeeded(Vector2Int newResolution)
|
||||
{
|
||||
if (_resolution == newResolution)
|
||||
return;
|
||||
|
||||
if (_avoidDownscale == true && _resolution.x * _resolution.y > newResolution.x * newResolution.y)
|
||||
return;
|
||||
|
||||
Release();
|
||||
|
||||
_resolution = newResolution;
|
||||
_count = newResolution.x * newResolution.y * _countScale;
|
||||
|
||||
switch (_bufferType)
|
||||
{
|
||||
case BufferType.ComputeBuffer:
|
||||
_computeBuffer = new ComputeBuffer(_count, _stride, _computeBufferType);
|
||||
break;
|
||||
case BufferType.GraphicsBuffer:
|
||||
_graphicsBuffer = new GraphicsBuffer(_graphicsBufferType, _count, _stride);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBuffer(ComputeShader shader, string name, int kernelIndex)
|
||||
{
|
||||
switch (_bufferType)
|
||||
{
|
||||
case BufferType.ComputeBuffer:
|
||||
shader.SetBuffer(kernelIndex, name, _computeBuffer);
|
||||
break;
|
||||
case BufferType.GraphicsBuffer:
|
||||
shader.SetBuffer(kernelIndex, name, _graphicsBuffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
_computeBuffer?.Release();
|
||||
_computeBuffer = null;
|
||||
|
||||
_graphicsBuffer?.Release();
|
||||
_graphicsBuffer = null;
|
||||
|
||||
_resolution = Vector2Int.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a65c00cd4f01459a94fbdad28894645c
|
||||
timeCreated: 1745925251
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Wrappers/HDynamicBuffer.cs
|
||||
uploadId: 840002
|
||||
105
Assets/Plugins/HTraceSSGI/Scripts/Wrappers/RTWrapper.cs
Normal file
105
Assets/Plugins/HTraceSSGI/Scripts/Wrappers/RTWrapper.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
//pipelinedefine
|
||||
#define H_URP
|
||||
|
||||
using HTraceSSGI.Scripts.Globals;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace HTraceSSGI.Scripts.Wrappers
|
||||
{
|
||||
public class RTWrapper
|
||||
{
|
||||
private RenderTextureDescriptor _dscr;
|
||||
|
||||
public RTHandle rt;
|
||||
|
||||
|
||||
|
||||
public void HTextureAlloc(string name, Vector2 scaleFactor, GraphicsFormat graphicsFormat, int volumeDepthOrSlices = -1, int depthBufferBits = 0,
|
||||
TextureDimension textureDimension = TextureDimension.Unknown,
|
||||
bool useMipMap = false, bool autoGenerateMips = false, bool enableRandomWrite = true, bool useDynamicScale = true) //useDynamicScale default = true for Upscalers switch between Hardware and Software
|
||||
{
|
||||
volumeDepthOrSlices = volumeDepthOrSlices == -1 ? TextureXR.slices : volumeDepthOrSlices;
|
||||
textureDimension = textureDimension == TextureDimension.Unknown ? TextureXR.dimension : textureDimension;
|
||||
|
||||
rt = RTHandles.Alloc(scaleFactor, volumeDepthOrSlices, dimension: textureDimension, colorFormat: graphicsFormat, name: name,
|
||||
enableRandomWrite: enableRandomWrite, useMipMap: useMipMap, useDynamicScale: useDynamicScale, autoGenerateMips: autoGenerateMips,
|
||||
depthBufferBits: (DepthBits)depthBufferBits);
|
||||
}
|
||||
|
||||
public void HTextureAlloc(string name, ScaleFunc scaleFunc, GraphicsFormat graphicsFormat, int volumeDepthOrSlices = -1, int depthBufferBits = 0,
|
||||
TextureDimension textureDimension = TextureDimension.Unknown,
|
||||
bool useMipMap = false, bool autoGenerateMips = false, bool enableRandomWrite = true, bool useDynamicScale = true) //useDynamicScale default = true for Upscalers switch between Hardware and Software
|
||||
{
|
||||
volumeDepthOrSlices = volumeDepthOrSlices == -1 ? TextureXR.slices : volumeDepthOrSlices;
|
||||
textureDimension = textureDimension == TextureDimension.Unknown ? TextureXR.dimension : textureDimension;
|
||||
|
||||
rt = RTHandles.Alloc(scaleFunc, volumeDepthOrSlices, dimension: textureDimension, colorFormat: graphicsFormat, name: name,
|
||||
enableRandomWrite: enableRandomWrite, useMipMap: useMipMap, useDynamicScale: useDynamicScale, autoGenerateMips: autoGenerateMips,
|
||||
depthBufferBits: (DepthBits)depthBufferBits);
|
||||
}
|
||||
|
||||
public void HTextureAlloc(string name, int width, int height, GraphicsFormat graphicsFormat, int volumeDepthOrSlices = -1, int depthBufferBits = 0,
|
||||
TextureDimension textureDimension = TextureDimension.Unknown,
|
||||
bool useMipMap = false, bool autoGenerateMips = false, bool enableRandomWrite = true, bool useDynamicScale = true) //useDynamicScale default = true for Upscalers switch between Hardware and Software
|
||||
{
|
||||
volumeDepthOrSlices = volumeDepthOrSlices == -1 ? TextureXR.slices : volumeDepthOrSlices;
|
||||
textureDimension = textureDimension == TextureDimension.Unknown ? TextureXR.dimension : textureDimension;
|
||||
|
||||
rt = RTHandles.Alloc(width, height, volumeDepthOrSlices, dimension: textureDimension, colorFormat: graphicsFormat, name: name,
|
||||
enableRandomWrite: enableRandomWrite, useMipMap: useMipMap, useDynamicScale: useDynamicScale, autoGenerateMips: autoGenerateMips,
|
||||
depthBufferBits: (DepthBits)depthBufferBits);
|
||||
}
|
||||
|
||||
public void HRelease()
|
||||
{
|
||||
RTHandles.Release(rt);
|
||||
}
|
||||
|
||||
public void ReAllocateIfNeeded(string name, ref RenderTextureDescriptor inputDescriptor, GraphicsFormat graphicsFormat = GraphicsFormat.None,
|
||||
int width = -1, int height = -1, int volumeDepth = 1,
|
||||
TextureDimension dimension = TextureDimension.Tex2D,
|
||||
bool enableRandomWrite = true, bool useMipMap = false, bool autoGenerateMips = false,
|
||||
bool useDynamicScale = false)
|
||||
{
|
||||
if (dimension != TextureDimension.Tex2D || width > 0 || height > 0) //conditions to create new descriptor
|
||||
{
|
||||
RenderTextureDescriptor newDesc = inputDescriptor;
|
||||
|
||||
newDesc.width = width == -1 ? inputDescriptor.width : width;
|
||||
newDesc.height = height == -1 ? inputDescriptor.height : height;
|
||||
newDesc.volumeDepth = volumeDepth;
|
||||
newDesc.dimension = dimension;
|
||||
newDesc.graphicsFormat = graphicsFormat;
|
||||
newDesc.autoGenerateMips = autoGenerateMips;
|
||||
newDesc.useMipMap = useMipMap;
|
||||
newDesc.enableRandomWrite = enableRandomWrite;
|
||||
newDesc.msaaSamples = 1;
|
||||
newDesc.useDynamicScale = false;
|
||||
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
RenderingUtils.ReAllocateHandleIfNeeded(ref rt, newDesc, name: name);
|
||||
#else
|
||||
RenderingUtils.ReAllocateIfNeeded(ref rt, newDesc, name: name);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
inputDescriptor.volumeDepth = volumeDepth;
|
||||
inputDescriptor.graphicsFormat = graphicsFormat;
|
||||
inputDescriptor.autoGenerateMips = autoGenerateMips;
|
||||
inputDescriptor.useMipMap = useMipMap;
|
||||
inputDescriptor.enableRandomWrite = enableRandomWrite;
|
||||
inputDescriptor.msaaSamples = 1;
|
||||
inputDescriptor.useDynamicScale = false;
|
||||
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
RenderingUtils.ReAllocateHandleIfNeeded(ref rt, inputDescriptor, name: name);
|
||||
#else
|
||||
RenderingUtils.ReAllocateIfNeeded(ref rt, inputDescriptor, name: name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Plugins/HTraceSSGI/Scripts/Wrappers/RTWrapper.cs.meta
Normal file
10
Assets/Plugins/HTraceSSGI/Scripts/Wrappers/RTWrapper.cs.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36cadb88827714842b7a17d1c36ca0aa
|
||||
timeCreated: 1729184161
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 336896
|
||||
packageName: 'HTrace: Screen Space Global Illumination URP'
|
||||
packageVersion: 1.2.0
|
||||
assetPath: Assets/HTraceSSGI/Scripts/Wrappers/RTWrapper.cs
|
||||
uploadId: 840002
|
||||
Reference in New Issue
Block a user