Files
vfx-graph-gs/Assets/vfx-graph-gs/Scripts/SplatDataBinder.cs
T
2026-03-13 17:35:32 +08:00

94 lines
3.4 KiB
C#

using System.Collections;
using UnityEngine;
using UnityEngine.VFX;
using UnityEngine.VFX.Utility;
namespace SplatVfx
{
[AddComponentMenu("VFX/Property Binders/Splat Data Binder")]
[VFXBinder("Splat Data")]
public sealed class VFXSplatDataBinder : VFXBinderBase
{
public SplatData SplatData = null;
public string SplatCountProperty
{ get => (string)_splatCountProperty;
set => _splatCountProperty = value; }
public string PositionBufferProperty
{
get => (string)_positionBufferProperty;
set => _positionBufferProperty = value;
}
public string ScaleBufferProperty
{
get => (string)_scaleBufferProperty;
set => _scaleBufferProperty = value;
}
public string ColorBufferProperty
{
get => (string)_colorBufferProperty;
set => _colorBufferProperty = value;
}
public string OpacityBufferProperty
{
get => (string)_opacityBufferProperty;
set => _opacityBufferProperty = value;
}
// public string RotationBufferProperty
// {
// get => (string)_rotationBufferProperty;
// set => _rotationBufferProperty = value;
// }
[VFXPropertyBinding("System.UInt32"), SerializeField]
ExposedProperty _splatCountProperty = "SplatCount";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _positionBufferProperty = "PositionBuffer";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _scaleBufferProperty = "ScaleBuffer";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _colorBufferProperty = "ColorBuffer";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _opacityBufferProperty = "OpacityBuffer";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _rotationBufferProperty = "RotationBuffer";
public override bool IsValid(VisualEffect component)
=> SplatData != null &&
// component.HasUInt(_splatCountProperty) &&
component.HasGraphicsBuffer(_positionBufferProperty) &&
component.HasGraphicsBuffer(_scaleBufferProperty) &&
component.HasGraphicsBuffer(_colorBufferProperty) &&
component.HasGraphicsBuffer(_opacityBufferProperty); // &&
// component.HasGraphicsBuffer(_rotationBufferProperty);
public override void UpdateBinding(VisualEffect component)
{
component.SetUInt(_splatCountProperty, (uint)SplatData.SplatCount);
component.SetGraphicsBuffer(_positionBufferProperty, SplatData.PositionBuffer);
component.SetGraphicsBuffer(_scaleBufferProperty, SplatData.ScaleBuffer);
component.SetGraphicsBuffer(_colorBufferProperty, SplatData.ColorBuffer);
component.SetGraphicsBuffer(_opacityBufferProperty, SplatData.OpacityBuffer);
component.SetGraphicsBuffer(_rotationBufferProperty, SplatData.RotationBuffer);
}
// public override string ToString()
// => $"Splat Data : {_splatCountProperty}, {_positionBufferProperty}, "
// // + $"{_axisBufferProperty}, {_colorBufferProperty}";
// + $"{_colorBufferProperty}";
}
} // namespace SplatVfx