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

@@ -9,9 +9,9 @@ namespace Misaki.AoVolume
public static readonly VolumeEntity Invalid = new(_INVALID_INDEX);
public VolumeEntity(int index)
public VolumeEntity(int entityIndex)
{
this.entityIndex = index;
this.entityIndex = entityIndex;
}
}

View File

@@ -1,21 +1,33 @@
using System.Runtime.CompilerServices;
using UnityEngine;
namespace Misaki.AoVolume
{
[ExecuteInEditMode]
internal class AoVolume : MonoBehaviour
[AddComponentMenu("Misaki/AO Volume/Local AO")]
public class VolumeObject : MonoBehaviour
{
private VolumeEntity _entity = VolumeEntity.Invalid;
[Tooltip("Should the volume data update every frame or not. You can always call ForceDataUpdate to update the data.")]
[PopupBoolean]
public bool dynamicVolume;
public VolumeData data;
public VolumeData data = VolumeData.Default;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void UpdateMatrixData()
{
data.worldMatrix = transform.localToWorldMatrix;
data.inverseWorldMatrix = transform.worldToLocalMatrix;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void UpdateVolumeData()
{
var oldData = VolumeDatabase.Instance.GetDataPtr(_entity);
*oldData = data;
}
private void OnEnable()
{
if (_entity.IsValid)
@@ -34,7 +46,7 @@ namespace Misaki.AoVolume
private void Update()
{
if (dynamicVolume && transform.hasChanged)
if (dynamicVolume)
{
if (transform.hasChanged)
{
@@ -42,16 +54,17 @@ namespace Misaki.AoVolume
transform.hasChanged = false;
}
ref var oldData = ref VolumeDatabase.Instance.GetDataRef(_entity);
oldData = data;
UpdateVolumeData();
}
}
private void OnDrawGizmos()
/// <summary>
/// Force the volume data to update
/// </summary>
public void ForceDataUpdate()
{
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.color = Color.green;
Gizmos.DrawWireCube(Vector3.zero, data.size);
UpdateMatrixData();
UpdateVolumeData();
}
}
}
}