Created
July 23, 2018 06:53
-
-
Save ernesernesto/705c58f265df7d4be6d153ea0276276e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SpectrumJob : IJobParallelForTransform | |
{ | |
public float maxScale; | |
public float dynamics; | |
public float epsilon; | |
public NativeArray<float> currentSpectrums; | |
public NativeArray<float> prevSpectrums; | |
public NativeArray<Vector3> origins; | |
public void Execute(int index, TransformAccess transform) | |
{ | |
float current = currentSpectrums[index]; | |
float prev = prevSpectrums[index]; | |
float val = (dynamics*prev + (1 - dynamics)*current); | |
prevSpectrums[index] = val; | |
float valAdjusted = val*maxScale; | |
float halfHeight = valAdjusted*0.5f; | |
Vector3 origin = origins[index]; | |
if(val >= epsilon) | |
{ | |
transform.localPosition = new Vector3(origin.x, halfHeight, origin.z); | |
transform.localScale = new Vector3(1, valAdjusted, 1); | |
} | |
else | |
{ | |
transform.localScale = new Vector3(0, 0, 0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment