AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
DistorterSimplex.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity.UX
7 {
8  public class DistorterSimplex : Distorter
9  {
10  public float ScaleMultiplier = 10f;
11  public float SpeedMultiplier = 1f;
12  public float StrengthMultiplier = 0.5f;
13  public Vector3 AxisStrength = Vector3.one;
14  public Vector3 AxisSpeed = Vector3.one;
15  public Vector3 AxisOffset = Vector3.zero;
16  public float ScaleDistort = 2f;
17  public bool UniformScaleDistort = true;
18 
19  protected override Vector3 DistortPointInternal(Vector3 point, float strength)
20  {
21  Vector3 scaledPoint = (point * ScaleMultiplier) + AxisOffset;
22 
23  point.x = (float)(point.x + (noise.Evaluate(scaledPoint.x, scaledPoint.y, scaledPoint.z, Time.unscaledTime * AxisSpeed.x)) * AxisStrength.x * StrengthMultiplier);
24  point.y = (float)(point.y + (noise.Evaluate(scaledPoint.x, scaledPoint.y, scaledPoint.z, Time.unscaledTime * AxisSpeed.y)) * AxisStrength.y * StrengthMultiplier);
25  point.z = (float)(point.z + (noise.Evaluate(scaledPoint.x, scaledPoint.y, scaledPoint.z, Time.unscaledTime * AxisSpeed.z)) * AxisStrength.z * StrengthMultiplier);
26  return point;
27  }
28 
29  protected override Vector3 DistortScaleInternal(Vector3 point, float strength)
30  {
31  if (UniformScaleDistort)
32  {
33  float scale = (float)(noise.Evaluate(point.x, point.y, point.z, Time.unscaledTime));
34  return Vector3.one + (Vector3.one * (scale * ScaleDistort));
35  }
36  else
37  {
38  point = DistortPointInternal(point, strength);
39  return Vector3.Lerp (Vector3.one, Vector3.Scale(Vector3.one, Vector3.one + (point * ScaleDistort)), strength);
40  }
41  }
42 
43  private FastSimplexNoise noise = new FastSimplexNoise();
44  }
45 }
A conglomeration of open-source simplex libraries in C# with an emphasis on performance ...
override Vector3 DistortPointInternal(Vector3 point, float strength)
Internal function where position distortion is done
override Vector3 DistortScaleInternal(Vector3 point, float strength)
Internal function where scale distortion is done