shitty spice v2 cause i lost the first one :(
This commit is contained in:
1 parent
8cf63188da
commit
05e7aaf54c
10 files changed
+10706
-2687
No files matched your search
@@ -0,0 +1,76 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
using UnityEngine.VFX.Utility;
|
||||
using Assets.WasapiAudio.Scripts.Unity;
|
||||
|
||||
namespace Assets.WasapiAudio.Scripts.Unity
|
||||
{
|
||||
[AddComponentMenu("VFX/Property Binders/Spectre - VFX Binder")]
|
||||
[VFXBinder("Audio/Audio Spectrum Data to AttributeMap")]
|
||||
public class SpectreVfxBinder : VfxAudioVisualizationEffect
|
||||
{
|
||||
[VFXPropertyBinding("System.UInt32"), SerializeField]
|
||||
protected ExposedProperty SpectrumSizeParameter = "SpectrumSize";
|
||||
|
||||
[VFXPropertyBinding("UnityEngine.Texture2D"), SerializeField]
|
||||
protected ExposedProperty SpectrumDataTextureParameter = "SpectrumDataTexture";
|
||||
|
||||
public bool symmetric = false;
|
||||
|
||||
private Texture2D _texture;
|
||||
private Color[] _colorCache;
|
||||
|
||||
private void InitialiseTexture() {
|
||||
Debug.Log("Reinitialising spectrum texture...");
|
||||
if (symmetric) {
|
||||
_texture = new Texture2D(SpectrumSize * 2, 1, TextureFormat.RFloat, false);
|
||||
_colorCache = new Color[SpectrumSize * 2];
|
||||
} else {
|
||||
_texture = new Texture2D(SpectrumSize, 1, TextureFormat.RFloat, false);
|
||||
_colorCache = new Color[SpectrumSize];
|
||||
}
|
||||
|
||||
_texture.name = $"AudioSpectrumData{SpectrumSize}";
|
||||
}
|
||||
|
||||
private void UpdateTexture() {
|
||||
// init
|
||||
if (_texture == null) InitialiseTexture();
|
||||
|
||||
// has symmetric been toggled and the texture needs updating?
|
||||
if (symmetric && _texture.width != SpectrumSize * 2) InitialiseTexture();
|
||||
if (!symmetric && _texture.width != SpectrumSize) InitialiseTexture();
|
||||
|
||||
var spectrumData = GetSpectrumData();
|
||||
|
||||
if (symmetric) {
|
||||
for (int i = 0; i < SpectrumSize; i++) {
|
||||
_colorCache[SpectrumSize + i] = new Color(spectrumData[i], 0, 0, 0);
|
||||
_colorCache[SpectrumSize - (i + 1)] = new Color(spectrumData[i], 0, 0, 0);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < SpectrumSize; i++) {
|
||||
_colorCache[i] = new Color(spectrumData[i], 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
_texture.SetPixels(_colorCache);
|
||||
_texture.Apply();
|
||||
}
|
||||
|
||||
public override void UpdateBinding(VisualEffect component) {
|
||||
base.UpdateBinding(component);
|
||||
UpdateTexture();
|
||||
if (symmetric) {
|
||||
component.SetUInt(SpectrumSizeParameter, (uint) SpectrumSize * 2);
|
||||
} else {
|
||||
component.SetUInt(SpectrumSizeParameter, (uint) SpectrumSize);
|
||||
}
|
||||
component.SetTexture(SpectrumDataTextureParameter, _texture);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return "Audio Spectrum Data";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2c94a50cf5c1d2449fe8305e8a79075
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
using UnityEngine.VFX.Utility;
|
||||
|
||||
namespace Assets.WasapiAudio.Scripts.Unity
|
||||
{
|
||||
[AddComponentMenu("VFX/Property Binders/Spectre - VFX SDF Binder")]
|
||||
[VFXBinder("Audio/Audio Spectrum Data to 3d SDF AttributeMap")]
|
||||
public class SpectreVfxSdfBinder : VfxAudioVisualizationEffect
|
||||
{
|
||||
[VFXPropertyBinding("System.UInt32"), SerializeField]
|
||||
protected ExposedProperty SpectrumSizeParameter = "SpectrumSize";
|
||||
|
||||
[VFXPropertyBinding("UnityEngine.Texture3D"), SerializeField]
|
||||
protected ExposedProperty SpectrumDataTextureParameter = "SpectrumDataTexture";
|
||||
|
||||
private Texture3D _texture;
|
||||
private Color[] _colorCache;
|
||||
|
||||
private int z = 0;
|
||||
|
||||
private void UpdateTexture()
|
||||
{
|
||||
if (_texture == null)
|
||||
{
|
||||
_texture = new Texture3D(SpectrumSize * 2, SpectrumSize * 2, SpectrumSize * 2, TextureFormat.RFloat, false);
|
||||
_texture.name = $"AudioSpectrumDataSDF{SpectrumSize}";
|
||||
_colorCache = new Color[
|
||||
SpectrumSize * 2 *
|
||||
SpectrumSize * 2 *
|
||||
SpectrumSize * 2
|
||||
];
|
||||
}
|
||||
|
||||
var spectrumData = GetSpectrumData();
|
||||
|
||||
// go from 0 to end of spectrum
|
||||
for (int x = 0; x < SpectrumSize; x++) {
|
||||
float height = spectrumData[x] * SpectrumSize * 2;
|
||||
|
||||
// go from 0 to double the spectrum height
|
||||
for (int y = 0; y < SpectrumSize * 2; y++) {
|
||||
float distance = (y - height);
|
||||
|
||||
var z_part = z * (SpectrumSize * 2 * SpectrumSize * 2);
|
||||
var y_part = y * SpectrumSize * 2;
|
||||
|
||||
_colorCache[z_part + y_part + (SpectrumSize + x)] = new Color(distance, 0, 0, 0);
|
||||
_colorCache[z_part + y_part + (SpectrumSize - (x + 1))] = new Color(distance, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
z = (z + 1) % (SpectrumSize * 2);
|
||||
|
||||
// Debug.Log($"{z}");
|
||||
|
||||
_texture.SetPixels(_colorCache);
|
||||
_texture.Apply();
|
||||
}
|
||||
|
||||
public override void UpdateBinding(VisualEffect component)
|
||||
{
|
||||
base.UpdateBinding(component);
|
||||
UpdateTexture();
|
||||
component.SetUInt(SpectrumSizeParameter, (uint) SpectrumSize);
|
||||
component.SetTexture(SpectrumDataTextureParameter, _texture);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Audio Spectrum Data";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42ceea4a053d2f244b3c6dd469a1fdfb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user