Skip to content

Instantly share code, notes, and snippets.

@ernesernesto
Created July 23, 2018 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ernesernesto/705c58f265df7d4be6d153ea0276276e to your computer and use it in GitHub Desktop.
Save ernesernesto/705c58f265df7d4be6d153ea0276276e to your computer and use it in GitHub Desktop.
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