ocean
This commit is contained in:
1 parent
f9a48f2695
commit
cf55d7034d
17 files changed
+7775
-3582
No files matched your search
@@ -0,0 +1,71 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
using UnityEngine.VFX.Utility;
|
||||
|
||||
namespace Assets.WasapiAudio.Scripts.Unity
|
||||
{
|
||||
[AddComponentMenu("VFX/Property Binders/VFX Audio Spectrum Data Binder SDF")]
|
||||
[VFXBinder("Audio/Audio Spectrum Data to 3d AttributeMap")]
|
||||
public class VfxAudioSpectrumDataBinder3d : 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, SpectrumSize, SpectrumSize, TextureFormat.RFloat, false);
|
||||
_texture.name = $"AudioSpectrumDataSDF{SpectrumSize}";
|
||||
_colorCache = new Color[SpectrumSize * SpectrumSize * SpectrumSize];
|
||||
}
|
||||
|
||||
var spectrumData = GetSpectrumData();
|
||||
|
||||
// go from 0 to end of spectrum
|
||||
for (int x = 0; x < SpectrumSize; x++) {
|
||||
float height = spectrumData[x] * SpectrumSize;
|
||||
|
||||
// go from 0 to the height of the spectrum
|
||||
for (int y = 0; y < SpectrumSize; y++) {
|
||||
float distance = y - height;
|
||||
|
||||
// _colorCache[(z * SpectrumSize * SpectrumSize) + (y * SpectrumSize) + x] = new Color(distance, 0, 0, 0);
|
||||
if (x == SpectrumSize - 1) {
|
||||
_colorCache[(z * SpectrumSize * SpectrumSize) + (y * SpectrumSize) + x] = new Color(Mathf.Infinity, 0, 0, 0);
|
||||
} else {
|
||||
_colorCache[(z * SpectrumSize * SpectrumSize) + (y * SpectrumSize) + x] = new Color(distance, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
z = (z + 1) % SpectrumSize;
|
||||
|
||||
// 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user