// Set scale of bars based on the values from analysis. public override void UpdateVisuals() { float[] spectrum = VisualizerCore.Spectrum(); int spectrumIndex = 0; int averageSize = (int)(spectrum.Length * KeepPercentage / AmountOfVisuals); for (int visualIndex = 0; visualIndex < AmountOfVisuals; visualIndex++) { float sum = 0; for (int j = 0; j < averageSize; j++) { sum += spectrum[spectrumIndex]; spectrumIndex++; } float audioScale = sum / averageSize * SizeModifier; float fallScale = Mathf.Clamp(_scales[visualIndex] - SmoothSpeed * Time.deltaTime, 0, MaxVisualScale); float finalScale = Mathf.Clamp(audioScale, fallScale, MaxVisualScale); _scales[visualIndex] = finalScale; _visuals[visualIndex].localScale = new Vector3(1 + finalScale, 1, 1); } }
// Set brightnesses of flares based on the values from analysis. public override void UpdateVisuals() { // Build a logarithmic spectrum float[] scaledSpectrum = new float[NumberOfFlares]; float b = Mathf.Pow(VisualizerCore.SpectrumSize, 1f / NumberOfFlares); float bPow = 1; for (int i = 0; i < NumberOfFlares; i++) { float prevBPow = bPow; bPow *= b; for (int j = (int)prevBPow; j < bPow - 1; j++) { scaledSpectrum[i] += VisualizerCore.Spectrum(j); } } // Set brightnesses of flares for (int i = 0; i < NumberOfFlares; i++) { // Smooth falling and sharp rising. float thisY = scaledSpectrum[i] * SizeModifier; _scales[i] -= SmoothSpeed * Time.deltaTime; _scales[i] = Mathf.Clamp(_scales[i], thisY, MaxVisualScale); _visuals[i].GetComponent <LensFlare>().brightness = _scales[i]; } }
public override void UpdateVisuals() { float sumSpectrum = VisualizerCore.Level(); // Build a logarithmic spectrum float[] scaledSpectrum = new float[FLAMES]; float b = Mathf.Pow(VisualizerCore.SpectrumSize, 1f / FLAMES); float bPow = 1; for (int i = 0; i < FLAMES; i++) { float prevBPow = bPow; bPow *= b; for (int j = (int)prevBPow; j < bPow - 1; j++) { scaledSpectrum[i] += VisualizerCore.Spectrum(j); } } // Update for (int i = 0; i < FLAMES; i++) { float nextPower = 0.2f + scaledSpectrum[i] * 6 + sumSpectrum * 0.5f; _powers[i] = Mathf.Max(_powers[i] * (1 - 10 * Time.deltaTime), nextPower); _flames[i].SetFloat("Power", _powers[i]); } }
// Called every frame public override void UpdateVisuals() { // Set up speeds float sum = Mathf.Clamp01(VisualizerCore.Level()) * 0.2f; float audioSpeed = Speed * Time.deltaTime * (sum + 0.01f) * Mathf.Sign(KillX); float thisSpeed = Mathf.Lerp(_lastSpeed, audioSpeed, AudioStrength); _lastSpeed = thisSpeed; // Set up spawns _spawnCooldown += CountPerSec * Time.deltaTime * Mathf.Abs(thisSpeed) * 20; for (; _spawnCooldown > 1; _spawnCooldown--) MaybeSpawnParticle(-KillX); // Apply speeds foreach (GameObject particle in _particles.ToList()) { // Calculate and apply speeds Vector3 position = particle.transform.position; float thisParticleXSpeedModifier = Mathf.Sin((position.y + _spawnCooldown) * 3); float thisParticleXSpeed = thisSpeed * (0.9f + 0.1f * thisParticleXSpeedModifier); float thisParticleYSpeed = Random.Range(-0.05f, 0.05f) * thisParticleXSpeed; position += new Vector3(thisParticleXSpeed, thisParticleYSpeed); particle.transform.position = position; // Apply scale //particle.transform.localScale = new Vector3(Size, Size, 1); // Kill if too far if (Mathf.Abs(particle.transform.position.x) > Mathf.Abs(KillX)) { _particles.Remove(particle); Destroy(particle); } } }
public override void UpdateVisuals() { // Build a logarithmic spectrum float[] scaledSpectrum = new float[NumberOfChunks]; float b = Mathf.Pow(VisualizerCore.SpectrumSize, 1f / NumberOfChunks); float bPow = 1; for (int i = 0; i < NumberOfChunks; i++) { float prevBPow = bPow; bPow *= b; for (int j = (int)prevBPow; j < bPow - 1 && j < VisualizerCore.SpectrumSize; j++) { scaledSpectrum[i] += Mathf.Abs(VisualizerCore.Spectrum(j)); } } // Update texture Graphics.CopyTexture(_blank, _texture); float[] samples = VisualizerCore.Samples(FilterType.Bypass); for (int i = 0; i < SampleBarCount && i < samples.Length; i++) { // Height between 2 and 32 float heightFrac = Mathf.Clamp01(Mathf.Abs(samples[i])) * SampleMultiplier; int height = (int)Mathf.Ceil(Mathf.Lerp(SampleBarMinHeight, SampleBarMaxHeight, heightFrac)); // Draw the rect on the texture buffer _texture.SetPixels( SampleBarDistance - height, (SampleBarWidth + SampleBarSeparation) * i, 2 * height, SampleBarWidth, Enumerable.Repeat(Color.white, 2 * SampleBarWidth * height).ToArray() ); } // Draw the texture buffer to the texture (no mipmaps) _texture.Apply(false); // Rotate and jump for (int i = 0; i < NumberOfChunks; i++) { _disks[i].transform.Rotate(Vector3.forward * RotationAmount(i)); float target = scaledSpectrum[i] * JumpPower; float height = Mathf.Clamp( Mathf.Lerp(-_disks[i].transform.localPosition.z, target, FallRate), target, 20 ); _disks[i].transform.localPosition = Vector3.back * height; } _subParent.transform.localRotation = Quaternion.Euler(_subRot + new Vector3(5 * Mathf.Sin(Time.time), 5 * Mathf.Sin(Time.time * 1.234f), 0)); }
public override void UpdateVisuals() { float[] low = VisualizerCore.Samples(FilterType.LowPass); float[] by = VisualizerCore.Samples(FilterType.Bypass); float sum = 0; for (int i = 0; i < low.Length; i++) { sum += (Mathf.Abs(by[i]) + 0.1f * Mathf.Abs(low[i])) / Mathf.Log(i + 2); // when i < 2, this is divide by zero } float scaledSum = sum * Strength; float framePower = Mathf.Max(scaledSum, Mathf.Lerp(scaledSum, _lastPower, Time.deltaTime)); // Let the bass kick _lastPower = framePower; _visualEffect.SetFloat("LerpSpeed", framePower); }
public override void UpdateVisuals() { // Set up speeds float sum = VisualizerCore.Level(); if (sum > _maxSum) { _maxSum = sum; } float audioSpeed = Speed * Time.deltaTime * (sum + 0.01f); _totalTime += audioSpeed; _totalTime %= 2; _animator.SetFloat(AnimationTime, Mathf.PingPong(_totalTime, 1)); //_anim.SetFloat("Time", 1f - sum / _maxSum); _light.intensity = Mathf.Max(sum * Brightness, _light.intensity * 0.95f); }
// Set scale of bars based on the values from analysis. public override void UpdateVisuals() { int spectrumIndex = 0; int averageSize = (int)(VisualizerCore.SpectrumSize * keepPercentage / (amountOfVisuals.x * amountOfVisuals.y)); for (int visualIndex = 0; visualIndex < visuals.Length; visualIndex++) { float sum = 0; for (int j = 0; j < averageSize; j++) { sum += VisualizerCore.Spectrum(spectrumIndex); spectrumIndex++; } float scale = sum / averageSize * sizeModifier; scales[visualIndex] -= smoothSpeed * Time.deltaTime; scales[visualIndex] = Mathf.Clamp(scale, minSize, maxVisualScale); colors[visualIndex].material.color = gradient.Evaluate(scale * 1.0f / maxVisualScale); visuals[visualIndex].localScale = Vector3.one * scales[visualIndex]; } }