Exemplo n.º 1
0
 public static Vertex FastLerp(Vertex a, Vertex b, float t) => new Vertex
 {
     point   = Vector4.Lerp(a.point, b.point, t),
     onePerZ = Mathf.Lerp(a.onePerZ, b.onePerZ, t),
     //uv = Vector2.Lerp(a.uv, b.uv, t),
     color = Color32.Lerp(a.color, b.color, t),
 };
Exemplo n.º 2
0
 public static Vertex FastLerp(Vertex a, Vertex b, float t) => new Vertex
 {
     point        = Vector4.Lerp(a.point, b.point, t),
     onePerZ      = MathRaster.Lerp(a.onePerZ, b.onePerZ, t),
     uv           = Vector2.Lerp(a.uv, b.uv, t),
     normal       = Vector3.Lerp(a.normal, b.normal, t),
     color        = Color32.Lerp(a.color, b.color, t),
     distance2Cam = MathRaster.Lerp(a.distance2Cam, b.distance2Cam, t)
 };
Exemplo n.º 3
0
        /// <remarks>
        /// this assumes that steps have been sorted by GradientEditor
        /// </remarks>
        public Vector4 Sample(float t)
        {
            t = t.Clamp(0, 1);
            Step previousStep = null;

            foreach (var step in Steps)
            {
                if (step.NormalizedPosition >= t)
                {
                    if (previousStep == null || previousStep.NormalizedPosition >= step.NormalizedPosition)
                    {
                        return(step.Color);
                    }

                    float amount = 0;       // Hold
                    switch (Interpolation)
                    {
                    case Interpolations.Linear:
                        amount = MathUtils.RemapAndClamp(t, previousStep.NormalizedPosition, step.NormalizedPosition, 0, 1);
                        break;

                    case Interpolations.Smooth:
                        amount = MathUtils.RemapAndClamp(t, previousStep.NormalizedPosition, step.NormalizedPosition, 0, 1);
                        amount = MathUtils.SmootherStep(0, 1, amount);
                        break;

                    case Interpolations.OkLab:
                        amount = MathUtils.RemapAndClamp(t, previousStep.NormalizedPosition, step.NormalizedPosition, 0, 1);
                        return(OkLab.Mix(previousStep.Color, step.Color, amount));
                    }

                    return(Vector4.Lerp(previousStep.Color, step.Color, amount));
                }

                previousStep = step;
            }

            return(previousStep?.Color ?? Vector4.One);
        }