From 5c71dff32543d8de82022334f446d007f141e3fe Mon Sep 17 00:00:00 2001 From: CNLohr Date: Sat, 28 Jan 2023 20:45:50 -0500 Subject: [PATCH] Further tweaks, to pull levels, etc. from self texture. --- .../Runtime/Shaders/AudioLink.shader | 57 ++++++++++++------- .../Shaders/AudioLinkSpectrumUI.shader | 21 ++----- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.shader b/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.shader index 53e0b460..f7d9c4a2 100644 --- a/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.shader +++ b/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.shader @@ -147,12 +147,12 @@ Shader "AudioLink/Internal/AudioLink" ); } - inline float Compute4BandRaw( int band, bool enableAutoLevel ) + inline float Compute4BandRaw( int band ) { const float audioThresholds[4] = {_Threshold0, _Threshold1, _Threshold2, _Threshold3}; const float audioBands[4] = {_X0, _X1, _X2, _X3}; - float threshold = audioThresholds[band]; - + float threshold = AudioLinkGetSelfPixelData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 0, band ) ).z; + // Get average of samples in the band float total = 0.; uint totalBins = AUDIOLINK_EXPBINS * AUDIOLINK_EXPOCT; @@ -166,11 +166,6 @@ Shader "AudioLink/Internal/AudioLink" } float magnitude = total / (binEnd - binStart); - if( enableAutoLevel ) - { - threshold -= AudioLinkGetSelfPixelData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 0, band ) ).z; - } - // Log attenuation magnitude = (magnitude * (log(1.1) / (log(1.1 + pow(_LogAttenuation, 4) * (1.0 - magnitude))))) / pow(threshold, 2); @@ -344,7 +339,7 @@ Shader "AudioLink/Internal/AudioLink" if (delay == 0) { // Is left-most pixel. - float magnitude = saturate( Compute4BandRaw( band, _EnableAutoLevel ) ); + float magnitude = saturate( Compute4BandRaw( band ) ); // Fade float lastMagnitude = AudioLinkGetSelfPixelData(ALPASS_AUDIOLINK + int2(0, band)).y; @@ -1270,12 +1265,22 @@ Shader "AudioLink/Internal/AudioLink" // Split into 4 columns. Each row is a band. int band = coordinateLocal.y; + const float4 audioBands = {_X0, _X1, _X2, _X3}; + const float4 audioThresholds = {_Threshold0, _Threshold1, _Threshold2, _Threshold3}; + switch( coordinateLocal.x ) { case 8: { // A basic recomputation of the 4-band. Except raw. - float magnitude = Compute4BandRaw(band, true); + // This first column of 4 rows is: + // R: Current raw band magnitude. + // G: Parameters + // Row 0: "Is Autoleveling Enabled" + // B: Threshold amount from auto-level. + // A: "Confidence" in this. If confidence is low, threshold will fall. + + float magnitude = Compute4BandRaw(band); float4 self = AudioLinkGetSelfPixelData( ALPASS_FILTEREDVU + coordinateLocal.xy ); float para = 0.0; @@ -1288,26 +1293,40 @@ Shader "AudioLink/Internal/AudioLink" float amt = self.z; float confidence = self.w; - // Compare the current value to "Magnitude" if it's very low, need to boost it. - if( magnitude < 0.5 ) + if( _EnableAutoLevel ) { - confidence = ( confidence - 0.05 * unity_DeltaTime.x ); - amt = lerp( amt + 0.1 * unity_DeltaTime.x, amt, saturate( confidence ) ); + // Compare the current value to "Magnitude" if it's very low, need to boost it. + if( magnitude < 0.5 ) + { + confidence = ( confidence - 0.05 * unity_DeltaTime.x ); + amt = lerp( amt - 0.1 * unity_DeltaTime.x, amt, saturate( confidence ) ); + } + else + { + // When we are above the threshold. + confidence = 1.1; // Make sure it can't slop down for a few seconds. + amt += 0.5 * unity_DeltaTime.x; + } + amt = clamp( amt, 0.1, audioThresholds[band] ); } else { - // When we are above the threshold. - confidence = 1.1; // Make sure it can't slop down for a few seconds. - amt -= 0.5 * unity_DeltaTime.x; + amt = audioThresholds[band]; } - amt = clamp( amt, 0, 0.4 ); return float4( magnitude, para, amt, confidence ); } case 9: + { + // Include configured bands and threshold. + if( band == 0 ) return audioBands; + if( band == 1 ) return audioThresholds; + return 0.0; + } case 10: case 11: - return 1.0; + // Reserved + return 0.0; } } return 1; diff --git a/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLinkSpectrumUI.shader b/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLinkSpectrumUI.shader index 73766159..0e9fcc93 100644 --- a/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLinkSpectrumUI.shader +++ b/Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLinkSpectrumUI.shader @@ -27,10 +27,6 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI" _X1("X1", Range(0.242, 0.387)) = 0.25 _X2("X2", Range(0.461, 0.628)) = 0.5 _X3("X3", Range(0.704, 0.953)) = 0.75 - _Threshold0("Threshold 0", Range(0.0, 1.0)) = 0.45 - _Threshold1("Threshold 1", Range(0.0, 1.0)) = 0.45 - _Threshold2("Threshold 2", Range(0.0, 1.0)) = 0.45 - _Threshold3("Threshold 3", Range(0.0, 1.0)) = 0.45 } SubShader @@ -67,10 +63,6 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI" uniform float _X1; uniform float _X2; uniform float _X3; - uniform float _Threshold0; - uniform float _Threshold1; - uniform float _Threshold2; - uniform float _Threshold3; float _SpectrumGain; float _SpectrumColorMix; @@ -121,13 +113,14 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI" fixed4 frag(v2f IN) : SV_Target { float2 iuv = IN.uv; - float audioBands[4] = {_X0, _X1, _X2, _X3}; - float audioThresholds[4] = {_Threshold0, _Threshold1, _Threshold2, _Threshold3}; float4 intensity = 0; uint totalBins = AUDIOLINK_EXPBINS * AUDIOLINK_EXPOCT; uint noteno = AudioLinkRemap(iuv.x, 0., 1., AUDIOLINK_4BAND_FREQFLOOR * totalBins, AUDIOLINK_4BAND_FREQCEILING * totalBins); float notenof = AudioLinkRemap(iuv.x, 0., 1., AUDIOLINK_4BAND_FREQFLOOR * totalBins, AUDIOLINK_4BAND_FREQCEILING * totalBins); + float4 audioBands = AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 1, 0 ) ); + float4 audioSetLevels = AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 1, 1 ) ); + { float4 spectrum_value_lower = AudioLinkData(float2(fmod(noteno, 128), (noteno/128)+4.0)); float4 spectrum_value_higher = AudioLinkData(float2(fmod(noteno+1, 128), ((noteno+1)/128)+4.0)); @@ -153,13 +146,7 @@ Shader "AudioLink/Internal/AudioLinkSpectrumUI" band += (iuv.x > audioBands[j]); } - float tHoldLevel = audioThresholds[band]; - - //ALPASS_FILTEREDVU_LEVELTIMING - if( AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING ).y ) - { - tHoldLevel -= AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 0, band ) ).z; - } + float tHoldLevel = AudioLinkData( ALPASS_FILTEREDVU_LEVELTIMING + uint2( 0, band ) ).z; threshold += saturate(_ThresholdThickness - abs(iuv.y - lerp(minHeight, maxHeight, tHoldLevel))) * 1000.; threshold = saturate(threshold) * (1. - round((iuv.x % _ThresholdDottedLine) / _ThresholdDottedLine)); threshold *= (iuv.x > _X0);