Improved the culling result of HizCulling;

Added custom inspector for VolumeObject;
Change the name of AoVolume to VolumeObject;
This commit is contained in:
2025-02-24 00:22:04 +09:00
parent 833502f87c
commit 2f79df128e
23 changed files with 336 additions and 86 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Rendering;
@@ -12,11 +13,13 @@ namespace Misaki.AoVolume
private static VolumeDatabase _instance;
public static VolumeDatabase Instance => _instance ??= new VolumeDatabase();
private bool _disposed;
private int _capacity = _INITIAL_CAPACITY;
private NativeList<VolumeEntityInfo> _entitiesInfo = new(_INITIAL_CAPACITY, Allocator.Persistent);
private NativeArray<VolumeEntity> _entities = new(_INITIAL_CAPACITY, Allocator.Persistent);
private NativeQueue<int> _freeIndices = new(Allocator.Persistent);
private int _capacity = _INITIAL_CAPACITY;
// NativeQueue has a unfixed memory leak bug.
private Queue<int> _freeIndices = new();
private int _entityCount;
public int EntityCount => _entityCount;
@@ -31,6 +34,11 @@ namespace Misaki.AoVolume
public unsafe VolumeData* GetDataPtr(VolumeEntity entity)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
if (!entity.IsValid)
{
return VolumeDataPtr.Zero;
@@ -51,15 +59,18 @@ namespace Misaki.AoVolume
{
if (_entityCount >= _capacity)
{
var newCapacity = _capacity + _capacity / 2;
_volumeDatas.ResizeArray(newCapacity);
_entities.ResizeArray(newCapacity);
_entitiesInfo.Capacity = newCapacity;
_capacity = newCapacity;
_capacity += _capacity / 2;
_entitiesInfo.Capacity = _capacity;
_volumeDatas.ResizeArray(_capacity);
_entities.ResizeArray(_capacity);
}
var newIndex = _entityCount++;
return new VolumeEntityInfo(newIndex);
var newEntity = new VolumeEntityInfo(_entityCount);
_entityCount++;
return newEntity;
}
private void RemoveAtSwapBackArrays(int removeIndexAt)
@@ -73,9 +84,14 @@ namespace Misaki.AoVolume
public VolumeEntity CreateEntity(VolumeData data)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
var newEntityInfo = AllocateNewEntityInfo();
var newEntity = VolumeEntity.Invalid;
VolumeEntity newEntity;
if (_freeIndices.TryDequeue(out var newEntityIndex))
{
newEntity = new VolumeEntity(newEntityIndex);
@@ -95,6 +111,11 @@ namespace Misaki.AoVolume
public void DestroyEntity(ref VolumeEntity entity)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
if (!entity.IsValid)
{
return;
@@ -116,10 +137,17 @@ namespace Misaki.AoVolume
public void Dispose()
{
if (_disposed)
{
return;
}
_entitiesInfo.Dispose();
_entities.Dispose();
_freeIndices.Dequeue();
_volumeDatas.Dispose();
_disposed = true;
}
}
}