Start working on Cluster;
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Misaki.AoVolume;
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
@@ -23,10 +24,13 @@ internal class AoVolumePass : CustomPass
|
||||
[ResourcePath("Packages/com.misaki.ao-volume/Runtime/Shader/AoVolume.compute")]
|
||||
public ComputeShader renderingShader;
|
||||
|
||||
private void ClearVisibleVolumeCounter()
|
||||
[Range(16, 256)]
|
||||
public int maxVolumeOnScreen = 64;
|
||||
|
||||
private void ClearCounterBuffer()
|
||||
{
|
||||
var zeroBuffer = new NativeArray<uint>(1, Allocator.Temp);
|
||||
zeroBuffer[0] = 0;
|
||||
zeroBuffer[0] = 0u;
|
||||
_visibleVolumeCountBuffer.SetData(zeroBuffer);
|
||||
zeroBuffer.Dispose();
|
||||
}
|
||||
@@ -37,48 +41,24 @@ internal class AoVolumePass : CustomPass
|
||||
// The render pipeline will ensure target setup and clearing happens in an performance manner.
|
||||
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
|
||||
{
|
||||
_volumeBounds = new NativeArray<OrientedBoundingBox>(64, Allocator.Persistent);
|
||||
_volumeBoundsBuffer = new ComputeBuffer(64, Marshal.SizeOf<OrientedBoundingBox>());
|
||||
_visibleIndicesBuffer = new ComputeBuffer(64, Marshal.SizeOf<uint>(), ComputeBufferType.Raw);
|
||||
_volumeBounds = new NativeArray<OrientedBoundingBox>(maxVolumeOnScreen, Allocator.Persistent);
|
||||
_volumeBoundsBuffer = new ComputeBuffer(maxVolumeOnScreen, Marshal.SizeOf<OrientedBoundingBox>());
|
||||
_visibleIndicesBuffer = new ComputeBuffer(maxVolumeOnScreen, Marshal.SizeOf<uint>(), ComputeBufferType.Raw);
|
||||
_visibleVolumeCountBuffer = new ComputeBuffer(1, Marshal.SizeOf<uint>(), ComputeBufferType.Counter);
|
||||
|
||||
_volumeDataBuffer = new ComputeBuffer(64, Marshal.SizeOf<VolumeData>());
|
||||
_volumeDataBuffer = new ComputeBuffer(maxVolumeOnScreen, Marshal.SizeOf<VolumeData>());
|
||||
|
||||
_volumeBuffer = RTHandles.Alloc(Vector2.one, useDynamicScale: true, dimension: TextureXR.dimension, enableRandomWrite: true, format: GraphicsFormat.R8_UNorm, name: "AO Volume Buffer");
|
||||
|
||||
ClearVisibleVolumeCounter();
|
||||
ClearCounterBuffer();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int GetDepthPyramidMaxMipLevel(HDCamera hDCamera)
|
||||
{
|
||||
return Mathf.FloorToInt(Mathf.Log(Mathf.Min(hDCamera.actualWidth, hDCamera.actualHeight), 2)) - 1;
|
||||
}
|
||||
|
||||
protected override void Execute(CustomPassContext ctx)
|
||||
{
|
||||
if (cullingShader == null || renderingShader == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Worth it to allocate a new buffer?
|
||||
//if (Shader.GetGlobalTexture("_AmbientOcclusionTexture") is not RenderTexture gtaoBuffer)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
var volumeCount = VolumeDatabase.Instance.EntityCount;
|
||||
if (volumeCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HierarchicalZCulling(ctx, volumeCount);
|
||||
RenderVisibleVolumes(ctx);
|
||||
//DebugVisibleVolumes();
|
||||
ClearVisibleVolumeCounter();
|
||||
}
|
||||
|
||||
private void HierarchicalZCulling(CustomPassContext ctx, int volumeCount)
|
||||
{
|
||||
for (var i = 0; i < volumeCount; i++)
|
||||
@@ -141,6 +121,31 @@ internal class AoVolumePass : CustomPass
|
||||
ArrayPool<uint>.Shared.Return(visibleVolumeIndices);
|
||||
}
|
||||
|
||||
protected override void Execute(CustomPassContext ctx)
|
||||
{
|
||||
if (cullingShader == null || renderingShader == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Worth it to allocate a new buffer?
|
||||
//if (Shader.GetGlobalTexture("_AmbientOcclusionTexture") is not RenderTexture gtaoBuffer)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
var volumeCount = VolumeDatabase.Instance.EntityCount;
|
||||
if (volumeCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HierarchicalZCulling(ctx, volumeCount);
|
||||
RenderVisibleVolumes(ctx);
|
||||
//DebugVisibleVolumes();
|
||||
ClearCounterBuffer();
|
||||
}
|
||||
|
||||
protected override void Cleanup()
|
||||
{
|
||||
_volumeBounds.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user