pulse enemy graphics in time with music
This commit is contained in:
parent
8040a999be
commit
e4fcf297b6
|
@ -12,7 +12,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: c271cfa846431634db54fa41238b7b35, type: 3}
|
m_Script: {fileID: 11500000, guid: c271cfa846431634db54fa41238b7b35, type: 3}
|
||||||
m_Name: Accessibility Options
|
m_Name: Accessibility Options
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_mode: 0
|
_mode: 2
|
||||||
_calm:
|
_calm:
|
||||||
_tunnel: {fileID: 2100000, guid: 735a92a62479ffd458216009452fec2b, type: 2}
|
_tunnel: {fileID: 2100000, guid: 735a92a62479ffd458216009452fec2b, type: 2}
|
||||||
_vibe:
|
_vibe:
|
||||||
|
|
|
@ -12,9 +12,11 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: a918b83cb0f52b445bf4975f41eaf321, type: 3}
|
m_Script: {fileID: 11500000, guid: a918b83cb0f52b445bf4975f41eaf321, type: 3}
|
||||||
m_Name: Audio Visualiser
|
m_Name: Audio Visualiser
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
_distanceToNextBeat: {fileID: 11400000, guid: 8f05f93192443bc42b8523048bde0dc4, type: 2}
|
||||||
|
_distanceSinceLastBeat: {fileID: 11400000, guid: 8d22f3ed946820445adcc586d2cc6e5a, type: 2}
|
||||||
_fractalAnimations:
|
_fractalAnimations:
|
||||||
- name: _Fractality
|
- name: _Fractality
|
||||||
multiplier: 43
|
multiplier: 100
|
||||||
channel: 0
|
channel: 0
|
||||||
sample: 525
|
sample: 525
|
||||||
_tunnelAnimations:
|
_tunnelAnimations:
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d86361ffc5ae478d9e976629c5d651bd, type: 3}
|
||||||
|
m_Name: DistanceSinceLastBeat
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_initialValue: 0
|
||||||
|
_readOnly: 0
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8d22f3ed946820445adcc586d2cc6e5a
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d86361ffc5ae478d9e976629c5d651bd, type: 3}
|
||||||
|
m_Name: DistanceToNextBeat
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_initialValue: 0
|
||||||
|
_readOnly: 0
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8f05f93192443bc42b8523048bde0dc4
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -100,6 +100,7 @@ Material:
|
||||||
- _Metallic: 0
|
- _Metallic: 0
|
||||||
- _OcclusionStrength: 1
|
- _OcclusionStrength: 1
|
||||||
- _Parallax: 0.005
|
- _Parallax: 0.005
|
||||||
|
- _PulseIntensity: 0.5
|
||||||
- _QueueOffset: 0
|
- _QueueOffset: 0
|
||||||
- _ReceiveShadows: 1
|
- _ReceiveShadows: 1
|
||||||
- _Smoothness: 0.5
|
- _Smoothness: 0.5
|
||||||
|
@ -107,13 +108,14 @@ Material:
|
||||||
- _SpecularHighlights: 1
|
- _SpecularHighlights: 1
|
||||||
- _SrcBlend: 1
|
- _SrcBlend: 1
|
||||||
- _Surface: 0
|
- _Surface: 0
|
||||||
|
- _VertexDistortion: 0.1
|
||||||
- _WorkflowMode: 1
|
- _WorkflowMode: 1
|
||||||
- _ZWrite: 1
|
- _ZWrite: 1
|
||||||
m_Colors:
|
m_Colors:
|
||||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
- _Color1: {r: 0.06480328, g: 0, b: 0.06301003, a: 1}
|
- _Color1: {r: 0.7735849, g: 0.23718406, b: 0.58527553, a: 1}
|
||||||
- _Color2: {r: 0.4292453, g: 0.94931483, b: 1, a: 1}
|
- _Color2: {r: 0.9622642, g: 0.031772893, b: 0.041073136, a: 1}
|
||||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||||
m_BuildTextureStacks: []
|
m_BuildTextureStacks: []
|
||||||
|
|
|
@ -117,7 +117,7 @@ Material:
|
||||||
- _FractalPower: 1
|
- _FractalPower: 1
|
||||||
- _FractalRotateSpeed: 20
|
- _FractalRotateSpeed: 20
|
||||||
- _FractalScale: 6
|
- _FractalScale: 6
|
||||||
- _FractalWeight: 0.45
|
- _FractalWeight: 0.15
|
||||||
- _GlossMapScale: 0
|
- _GlossMapScale: 0
|
||||||
- _Glossiness: 0
|
- _Glossiness: 0
|
||||||
- _GlossyReflections: 0
|
- _GlossyReflections: 0
|
||||||
|
|
|
@ -531,7 +531,7 @@ PrefabInstance:
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
|
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
|
||||||
propertyPath: m_LocalScale.x
|
propertyPath: m_LocalScale.x
|
||||||
value: 2282.9778
|
value: 2298.391
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
|
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
|
||||||
propertyPath: m_LocalScale.y
|
propertyPath: m_LocalScale.y
|
||||||
|
@ -887,7 +887,13 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 30d54cd9cbc0b4024b4c5af11532f553, type: 3}
|
m_Script: {fileID: 11500000, guid: 30d54cd9cbc0b4024b4c5af11532f553, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
bpm: 180
|
_distanceToNextBeat: {fileID: 11400000, guid: 8f05f93192443bc42b8523048bde0dc4, type: 2}
|
||||||
|
_distanceToOffbeat: {fileID: 0}
|
||||||
|
_distanceToMeasure: {fileID: 0}
|
||||||
|
_distanceSinceLastBeat: {fileID: 11400000, guid: 8d22f3ed946820445adcc586d2cc6e5a, type: 2}
|
||||||
|
_distanceSinceOffbeat: {fileID: 0}
|
||||||
|
_distanceSinceMeasure: {fileID: 0}
|
||||||
|
bpm: 90
|
||||||
_onBeat:
|
_onBeat:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls:
|
m_Calls:
|
||||||
|
|
|
@ -4,12 +4,21 @@ using System.Collections.Generic;
|
||||||
using DG.Tweening;
|
using DG.Tweening;
|
||||||
using FMOD;
|
using FMOD;
|
||||||
using FMODUnity;
|
using FMODUnity;
|
||||||
|
using Ktyl.Util;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
using Debug = UnityEngine.Debug;
|
using Debug = UnityEngine.Debug;
|
||||||
|
|
||||||
public class AudioBeatManager : MonoBehaviour, IAudioBeatManager
|
public class AudioBeatManager : MonoBehaviour, IAudioBeatManager
|
||||||
{
|
{
|
||||||
|
[SerializeField] private SerialFloat _distanceToNextBeat;
|
||||||
|
// [SerializeField] private SerialFloat _distanceToOffbeat;
|
||||||
|
// [SerializeField] private SerialFloat _distanceToMeasure;
|
||||||
|
|
||||||
|
[SerializeField] private SerialFloat _distanceSinceLastBeat;
|
||||||
|
// [SerializeField] private SerialFloat _distanceSinceOffbeat;
|
||||||
|
// [SerializeField] private SerialFloat _distanceSinceMeasure;
|
||||||
|
|
||||||
[SerializeField] private float bpm;
|
[SerializeField] private float bpm;
|
||||||
public float TimeBetweenBeats => _secPerBeat;
|
public float TimeBetweenBeats => _secPerBeat;
|
||||||
|
|
||||||
|
@ -36,25 +45,49 @@ public class AudioBeatManager : MonoBehaviour, IAudioBeatManager
|
||||||
{
|
{
|
||||||
_bps = bpm / 60f;
|
_bps = bpm / 60f;
|
||||||
_secPerBeat = 60f / bpm;
|
_secPerBeat = 60f / bpm;
|
||||||
_timer = 0;
|
|
||||||
RuntimeManager.CoreSystem.getMasterChannelGroup(out _channelGroup);
|
RuntimeManager.CoreSystem.getMasterChannelGroup(out _channelGroup);
|
||||||
RuntimeManager.CoreSystem.getSoftwareFormat(out _sampleRate, out _, out _);
|
RuntimeManager.CoreSystem.getSoftwareFormat(out _sampleRate, out _, out _);
|
||||||
DOTween.SetTweensCapacity(2000,100);
|
DOTween.SetTweensCapacity(2000,100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
private void Start()
|
||||||
|
{
|
||||||
|
_timer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
_channelGroup.getDSPClock(out _dspClock, out _);
|
_channelGroup.getDSPClock(out _dspClock, out _);
|
||||||
_timer += Time.deltaTime;
|
// _timer += Time.deltaTime;
|
||||||
if (_timer >= TimeBetweenBeats)
|
|
||||||
|
// new beats
|
||||||
|
var beatsElapsed = (int)(DspTime / TimeBetweenBeats);
|
||||||
|
|
||||||
|
var lastBeatTime = beatsElapsed * TimeBetweenBeats;
|
||||||
|
|
||||||
|
var timeSinceLastBeat = DspTime - lastBeatTime;
|
||||||
|
_distanceSinceLastBeat.Value = timeSinceLastBeat / TimeBetweenBeats;
|
||||||
|
|
||||||
|
var timeToNextBeat = (lastBeatTime+TimeBetweenBeats) - DspTime;
|
||||||
|
_distanceToNextBeat.Value = timeToNextBeat / TimeBetweenBeats;
|
||||||
|
|
||||||
|
if (beatsElapsed > _currentBeat)
|
||||||
{
|
{
|
||||||
_timer = 0;
|
// a beat gone done did do happen
|
||||||
|
|
||||||
|
// account for this frame being a little bit past the beat!
|
||||||
|
_timer = timeSinceLastBeat;
|
||||||
|
|
||||||
++_currentBeat;
|
++_currentBeat;
|
||||||
OnBeat?.Invoke(_currentBeat);
|
OnBeat?.Invoke(_currentBeat);
|
||||||
OnBeatEvent?.Invoke(_currentBeat);
|
OnBeatEvent?.Invoke(_currentBeat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateTimings()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IAudioBeatManager
|
public interface IAudioBeatManager
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using FMOD;
|
using FMOD;
|
||||||
|
using Ktyl.Util;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using INITFLAGS = FMOD.Studio.INITFLAGS;
|
using INITFLAGS = FMOD.Studio.INITFLAGS;
|
||||||
|
|
||||||
|
@ -20,9 +21,9 @@ public class AudioVisualizer : ScriptableObject
|
||||||
public float Initial { get; set; }
|
public float Initial { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// private Material _fractal;
|
[SerializeField] private SerialFloat _distanceToNextBeat;
|
||||||
// private Material _tunnel;
|
[SerializeField] private SerialFloat _distanceSinceLastBeat;
|
||||||
// private Material _ship;
|
|
||||||
[SerializeField] private ShaderPropertyAnimation[] _fractalAnimations;
|
[SerializeField] private ShaderPropertyAnimation[] _fractalAnimations;
|
||||||
[SerializeField] private ShaderPropertyAnimation[] _tunnelAnimations;
|
[SerializeField] private ShaderPropertyAnimation[] _tunnelAnimations;
|
||||||
[SerializeField] private ShaderPropertyAnimation[] _shipAnimations;
|
[SerializeField] private ShaderPropertyAnimation[] _shipAnimations;
|
||||||
|
@ -51,6 +52,10 @@ public class AudioVisualizer : ScriptableObject
|
||||||
|
|
||||||
public void Update(DSP fft, Renderer fractal, Renderer tunnel, Renderer ship)
|
public void Update(DSP fft, Renderer fractal, Renderer tunnel, Renderer ship)
|
||||||
{
|
{
|
||||||
|
// update beat-based things
|
||||||
|
Shader.SetGlobalFloat("_DistanceSinceLastBeat", _distanceSinceLastBeat);
|
||||||
|
Shader.SetGlobalFloat("_DistanceToNextBeat", _distanceToNextBeat);
|
||||||
|
|
||||||
fft.getParameterData((int) FMOD.DSP_FFT.SPECTRUMDATA, out var unmanagedData, out var length);
|
fft.getParameterData((int) FMOD.DSP_FFT.SPECTRUMDATA, out var unmanagedData, out var length);
|
||||||
var fftData = (FMOD.DSP_PARAMETER_FFT) Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
|
var fftData = (FMOD.DSP_PARAMETER_FFT) Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,12 @@ Shader "custom/enemy"
|
||||||
// [HDR] _Color2("Color 2", Color) = (1,1,1,1)
|
// [HDR] _Color2("Color 2", Color) = (1,1,1,1)
|
||||||
// _FadeStrength("Fade Strength", Float) = 0.1
|
// _FadeStrength("Fade Strength", Float) = 0.1
|
||||||
// _VertexScale("Vertex Scale", Float) = 0
|
// _VertexScale("Vertex Scale", Float) = 0
|
||||||
|
_PulseIntensity("Pulse Intensity", Float) = 1.0
|
||||||
|
|
||||||
_M("M", Float) = 0.5
|
_M("M", Float) = 0.5
|
||||||
_C("C", Float) = 0.0
|
_C("C", Float) = 0.0
|
||||||
|
|
||||||
_NoiseMap("Noise Map", 2D) = "black"
|
_NoiseMap("Noise Map", 2D) = "black"
|
||||||
_VertexDistortion("Vertex Distortion", Float) = 1.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SubShader
|
SubShader
|
||||||
|
@ -55,9 +55,11 @@ Shader "custom/enemy"
|
||||||
float4 _Color1;
|
float4 _Color1;
|
||||||
float4 _Color2;
|
float4 _Color2;
|
||||||
float _Alpha;
|
float _Alpha;
|
||||||
float _TimeToNextBeat;
|
float _PulseIntensity;
|
||||||
|
|
||||||
|
float _DistanceToNextBeat;
|
||||||
|
float _DistanceFromLastBeat;
|
||||||
|
|
||||||
float _VertexDistortion;
|
|
||||||
// float _VertexScale;
|
// float _VertexScale;
|
||||||
// float _FadeStrength;
|
// float _FadeStrength;
|
||||||
|
|
||||||
|
@ -81,22 +83,30 @@ Shader "custom/enemy"
|
||||||
Varyings OUT;
|
Varyings OUT;
|
||||||
|
|
||||||
float3 vpos = IN.positionOS.xyz;
|
float3 vpos = IN.positionOS.xyz;
|
||||||
float3 wpos = TransformObjectToWorld(vpos);
|
|
||||||
OUT.wpos = wpos;
|
|
||||||
OUT.normal = IN.normal;
|
OUT.normal = IN.normal;
|
||||||
|
|
||||||
float d = 1.0+length(wpos)*0.5;
|
float beat = _DistanceToNextBeat*_DistanceToNextBeat;
|
||||||
float2 uv = wpos.zx;
|
vpos *= 1.0+beat*_PulseIntensity;
|
||||||
float noise = SAMPLE_TEXTURE2D_LOD(_NoiseMap, sampler_NoiseMap, uv, 0) - 0.5;
|
|
||||||
|
|
||||||
|
//float d = 1.0+length(wpos)*0.5;
|
||||||
|
//float2 uv = wpos.zx;
|
||||||
|
// float noise = SAMPLE_TEXTURE2D_LOD(_NoiseMap, sampler_NoiseMap, uv, 0) - 0.5;
|
||||||
// vpos += _VertexScale*float3(0,0,5)*d;
|
// vpos += _VertexScale*float3(0,0,5)*d;
|
||||||
vpos += float3(_VertexDistortion,0,0)*noise*d;
|
|
||||||
// vpos += sin(180)*sin(1800)*float3(0,0,5)*d;
|
// vpos += sin(180)*sin(1800)*float3(0,0,5)*d;
|
||||||
|
|
||||||
// noise *= d*d * 0.1;
|
// noise *= d*d * 0.1;
|
||||||
|
|
||||||
// vpos *= lerp (0.9,1.1,noise);
|
// vpos *= lerp (0.9,1.1,noise);
|
||||||
|
|
||||||
|
|
||||||
|
float3 wpos = TransformObjectToWorld(vpos);
|
||||||
|
float3 fromCentre = normalize(wpos);
|
||||||
|
float3 distanceFromCentre = length(wpos);
|
||||||
|
|
||||||
|
float3 wposOffset = float3(0,0,fromCentre.y*fromCentre.x)*distanceFromCentre*beat;
|
||||||
|
wpos += wpos;
|
||||||
|
vpos += wposOffset;
|
||||||
|
|
||||||
|
|
||||||
|
OUT.wpos = wpos;
|
||||||
OUT.positionHCS = TransformObjectToHClip(vpos);
|
OUT.positionHCS = TransformObjectToHClip(vpos);
|
||||||
// The TRANSFORM_TEX macro performs the tiling and offset
|
// The TRANSFORM_TEX macro performs the tiling and offset
|
||||||
// transformation.
|
// transformation.
|
||||||
|
|
Loading…
Reference in New Issue