splat added to working dir

This commit is contained in:
2024-04-02 13:55:27 +01:00
parent b90aefbf59
commit 914f1c8b79
38 changed files with 31850 additions and 2 deletions

View File

@@ -0,0 +1,70 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
namespace SplatVfx {
public sealed class SplatData : ScriptableObject
{
#region Public properties
public int SplatCount => PositionArray.Length;
public GraphicsBuffer PositionBuffer => GetCachedBuffers().position;
public GraphicsBuffer AxisBuffer => GetCachedBuffers().axis;
public GraphicsBuffer ColorBuffer => GetCachedBuffers().color;
#endregion
#region Serialized data
[field:SerializeField] public Vector3[] PositionArray { get; set; }
[field:SerializeField] public Vector3[] AxisArray { get; set; }
[field:SerializeField] public Color[] ColorArray { get; set; }
#endregion
#region Public methods
public void ReleaseGpuResources()
{
_cachedBuffers.position?.Release();
_cachedBuffers.axis?.Release();
_cachedBuffers.color?.Release();
_cachedBuffers = (null, null, null);
}
#endregion
#region GPU resource management
(GraphicsBuffer position, GraphicsBuffer axis, GraphicsBuffer color)
_cachedBuffers;
static unsafe GraphicsBuffer NewBuffer<T>(int count) where T : unmanaged
=> new GraphicsBuffer(GraphicsBuffer.Target.Structured, count, sizeof(T));
(GraphicsBuffer position, GraphicsBuffer axis, GraphicsBuffer color)
GetCachedBuffers()
{
if (_cachedBuffers.position == null)
{
_cachedBuffers.position = NewBuffer<Vector3>(SplatCount);
_cachedBuffers.axis = NewBuffer<Vector3>(SplatCount * 3);
_cachedBuffers.color = NewBuffer<Color>(SplatCount);
_cachedBuffers.position.SetData(PositionArray);
_cachedBuffers.axis.SetData(AxisArray);
_cachedBuffers.color.SetData(ColorArray);
}
return _cachedBuffers;
}
#endregion
#region ScriptableObject implementation
void OnDisable() => ReleaseGpuResources();
#endregion
}
} // namespace SplatVfx

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 99e8102f25e54bf4d89eb4309bb9901a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
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 AxisBufferProperty
{ get => (string)_axisBufferProperty;
set => _axisBufferProperty = value; }
public string ColorBufferProperty
{ get => (string)_colorBufferProperty;
set => _colorBufferProperty = value; }
[VFXPropertyBinding("System.UInt32"), SerializeField]
ExposedProperty _splatCountProperty = "SplatCount";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _positionBufferProperty = "PositionBuffer";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _axisBufferProperty = "AxisBuffer";
[VFXPropertyBinding("UnityEngine.GraphicsBuffer"), SerializeField]
ExposedProperty _colorBufferProperty = "ColorBuffer";
public override bool IsValid(VisualEffect component)
=> SplatData != null &&
component.HasUInt(_splatCountProperty) &&
component.HasGraphicsBuffer(_positionBufferProperty) &&
component.HasGraphicsBuffer(_axisBufferProperty) &&
component.HasGraphicsBuffer(_colorBufferProperty);
public override void UpdateBinding(VisualEffect component)
{
component.SetUInt(_splatCountProperty, (uint)SplatData.SplatCount);
component.SetGraphicsBuffer(_positionBufferProperty, SplatData.PositionBuffer);
component.SetGraphicsBuffer(_axisBufferProperty, SplatData.AxisBuffer);
component.SetGraphicsBuffer(_colorBufferProperty, SplatData.ColorBuffer);
}
public override string ToString()
=> $"Splat Data : {_splatCountProperty}, {_positionBufferProperty}, "
+ $"{_axisBufferProperty}, {_colorBufferProperty}";
}
} // namespace SplatVfx

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6b23e4c8461b80e458b0acda332b8a17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
{
"name": "SplatVfx.Runtime",
"rootNamespace": "",
"references": [
"GUID:d04eb9c554ad44ceab303cecf0c0cf82"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 57d6a1ae39d606347b1307f1eadefe70
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: