Update HzCulling

This commit is contained in:
2025-02-22 03:04:15 +09:00
parent c25ff0dd61
commit f0dbf8e581
8 changed files with 277 additions and 100 deletions

View File

@@ -5,34 +5,43 @@ namespace Misaki.AoVolume
[ExecuteInEditMode]
internal class AoVolume : MonoBehaviour
{
private VolumeEntity _entity = VolumeEntity.InvalidEntity;
private VolumeEntity _entity = VolumeEntity.Invalid;
public bool dynamicVolume;
public VolumeData data;
private void InitializeEntity()
private void UpdateMatrixData()
{
data.worldMatrix = transform.localToWorldMatrix;
data.inverseWorldMatrix = transform.worldToLocalMatrix;
}
private void OnEnable()
{
if (_entity.IsValid)
{
return;
}
_entity = VolumeDatabase.Instance.CreateEntity(this);
}
private void OnEnable()
{
InitializeEntity();
UpdateMatrixData();
_entity = VolumeDatabase.Instance.CreateEntity(data);
}
private void OnDisable()
{
VolumeDatabase.Instance.DestroyEntity(_entity);
VolumeDatabase.Instance.DestroyEntity(ref _entity);
}
private void Update()
{
data.worldMatrix = transform.localToWorldMatrix;
data.inverseWorldMatrix = data.worldMatrix.inverse;
if (dynamicVolume && transform.hasChanged)
{
UpdateMatrixData();
ref var oldData = ref VolumeDatabase.Instance.GetDataRef(_entity);
oldData = data;
transform.hasChanged = false;
}
}
private void OnDrawGizmos()

View File

@@ -7,11 +7,28 @@ namespace Misaki.AoVolume
public readonly int entityIndex;
public readonly bool IsValid => entityIndex != _INVALID_INDEX;
public static readonly VolumeEntity InvalidEntity = new(_INVALID_INDEX);
public static readonly VolumeEntity Invalid = new(_INVALID_INDEX);
public VolumeEntity(int index)
{
entityIndex = index;
this.entityIndex = index;
}
}
// Intermediate struct which holds the data index of an entity and other information.
internal readonly struct VolumeEntityInfo
{
private const int _INVALID_INDEX = -1;
public readonly int dataIndex;
public static readonly VolumeEntityInfo Invalid = new VolumeEntityInfo(_INVALID_INDEX);
public bool IsValid => dataIndex != _INVALID_INDEX;
public VolumeEntityInfo(int dataIndex)
{
this.dataIndex = dataIndex;
}
}
}