|
|
@@ -16,6 +16,7 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
private readonly DelegateExpressionFfi _registry;
|
|
|
|
|
|
static float Lerp(float a, float b, float p) => p * (b - a) + a;
|
|
|
+ static double Lerp(double a, double b, double p) => p * (b - a) + a;
|
|
|
|
|
|
static Matrix3x2 Inverse(Matrix3x2 m)
|
|
|
{
|
|
|
@@ -34,6 +35,13 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
var t = MathUtilities.Clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
|
|
|
return t * t * (3.0f - 2.0f * t);
|
|
|
}
|
|
|
+
|
|
|
+ static double SmoothStep(double edge0, double edge1, double x)
|
|
|
+ {
|
|
|
+ var t = MathUtilities.Clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
|
|
|
+ return t * t * (3.0f - 2.0f * t);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
static Vector2 SmoothStep(Vector2 edge0, Vector2 edge1, Vector2 x)
|
|
|
{
|
|
|
@@ -43,6 +51,15 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ static Vector SmoothStep(Vector edge0, Vector edge1, Vector x)
|
|
|
+ {
|
|
|
+ return new (
|
|
|
+ SmoothStep(edge0.X, edge1.X, x.X),
|
|
|
+ SmoothStep(edge0.Y, edge1.Y, x.Y)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
static Vector3 SmoothStep(Vector3 edge0, Vector3 edge1, Vector3 x)
|
|
|
{
|
|
|
return new Vector3(
|
|
|
@@ -52,6 +69,15 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ static Vector3D SmoothStep(Vector3D edge0, Vector3D edge1, Vector3D x)
|
|
|
+ {
|
|
|
+ return new (
|
|
|
+ SmoothStep(edge0.X, edge1.X, x.X),
|
|
|
+ SmoothStep(edge0.Y, edge1.Y, x.Y),
|
|
|
+ SmoothStep(edge0.Z, edge1.Z, x.Z)
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
static Vector4 SmoothStep(Vector4 edge0, Vector4 edge1, Vector4 x)
|
|
|
{
|
|
|
@@ -69,7 +95,9 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
{
|
|
|
{"Abs", (float f) => Math.Abs(f)},
|
|
|
{"Abs", (Vector2 v) => Vector2.Abs(v)},
|
|
|
+ {"Abs", (Vector v) => v.Abs()},
|
|
|
{"Abs", (Vector3 v) => Vector3.Abs(v)},
|
|
|
+ {"Abs", (Vector3D v) => v.Abs()},
|
|
|
{"Abs", (Vector4 v) => Vector4.Abs(v)},
|
|
|
|
|
|
{"ACos", (float f) => (float) Math.Acos(f)},
|
|
|
@@ -79,7 +107,9 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
|
|
|
{"Clamp", (float a1, float a2, float a3) => MathUtilities.Clamp(a1, a2, a3)},
|
|
|
{"Clamp", (Vector2 a1, Vector2 a2, Vector2 a3) => Vector2.Clamp(a1, a2, a3)},
|
|
|
+ {"Clamp", (Vector a1, Vector a2, Vector a3) => Vector.Clamp(a1, a2, a3)},
|
|
|
{"Clamp", (Vector3 a1, Vector3 a2, Vector3 a3) => Vector3.Clamp(a1, a2, a3)},
|
|
|
+ {"Clamp", (Vector3D a1, Vector3D a2, Vector3D a3) => Vector3D.Clamp(a1, a2, a3)},
|
|
|
{"Clamp", (Vector4 a1, Vector4 a2, Vector4 a3) => Vector4.Clamp(a1, a2, a3)},
|
|
|
|
|
|
{"Concatenate", (Quaternion a1, Quaternion a2) => Quaternion.Concatenate(a1, a2)},
|
|
|
@@ -109,11 +139,15 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
},
|
|
|
|
|
|
{"Distance", (Vector2 a1, Vector2 a2) => Vector2.Distance(a1, a2)},
|
|
|
+ {"Distance", (Vector a1, Vector a2) => Vector.Distance(a1, a2)},
|
|
|
{"Distance", (Vector3 a1, Vector3 a2) => Vector3.Distance(a1, a2)},
|
|
|
+ {"Distance", (Vector3D a1, Vector3D a2) => Vector3D.Distance(a1, a2)},
|
|
|
{"Distance", (Vector4 a1, Vector4 a2) => Vector4.Distance(a1, a2)},
|
|
|
|
|
|
{"DistanceSquared", (Vector2 a1, Vector2 a2) => Vector2.DistanceSquared(a1, a2)},
|
|
|
+ {"DistanceSquared", (Vector a1, Vector a2) => Vector.DistanceSquared(a1, a2)},
|
|
|
{"DistanceSquared", (Vector3 a1, Vector3 a2) => Vector3.DistanceSquared(a1, a2)},
|
|
|
+ {"DistanceSquared", (Vector3D a1, Vector3D a2) => Vector3D.DistanceSquared(a1, a2)},
|
|
|
{"DistanceSquared", (Vector4 a1, Vector4 a2) => Vector4.DistanceSquared(a1, a2)},
|
|
|
|
|
|
{"Floor", (float v) => (float) Math.Floor(v)},
|
|
|
@@ -123,18 +157,24 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
|
|
|
|
|
|
{"Length", (Vector2 a1) => a1.Length()},
|
|
|
+ {"Length", (Vector a1) => a1.Length},
|
|
|
{"Length", (Vector3 a1) => a1.Length()},
|
|
|
+ {"Length", (Vector3D a1) => a1.Length},
|
|
|
{"Length", (Vector4 a1) => a1.Length()},
|
|
|
{"Length", (Quaternion a1) => a1.Length()},
|
|
|
|
|
|
{"LengthSquared", (Vector2 a1) => a1.LengthSquared()},
|
|
|
+ {"LengthSquared", (Vector a1) => a1*a1},
|
|
|
{"LengthSquared", (Vector3 a1) => a1.LengthSquared()},
|
|
|
+ {"LengthSquared", (Vector3D a1) => Vector3D.Dot(a1, a1)},
|
|
|
{"LengthSquared", (Vector4 a1) => a1.LengthSquared()},
|
|
|
{"LengthSquared", (Quaternion a1) => a1.LengthSquared()},
|
|
|
|
|
|
{"Lerp", (float a1, float a2, float a3) => Lerp(a1, a2, a3)},
|
|
|
{"Lerp", (Vector2 a1, Vector2 a2, float a3) => Vector2.Lerp(a1, a2, a3)},
|
|
|
+ {"Lerp", (Vector a1, Vector a2, float a3) => new Vector(Lerp(a1.X, a2.X, a3), Lerp(a1.Y, a2.Y, a3))},
|
|
|
{"Lerp", (Vector3 a1, Vector3 a2, float a3) => Vector3.Lerp(a1, a2, a3)},
|
|
|
+ {"Lerp", (Vector3D a1, Vector3D a2, float a3) => new Vector3D(Lerp(a1.X, a2.X, a3), Lerp(a1.Y, a2.Y, a3), Lerp(a1.Z, a2.Z, a3))},
|
|
|
{"Lerp", (Vector4 a1, Vector4 a2, float a3) => Vector4.Lerp(a1, a2, a3)},
|
|
|
|
|
|
|
|
|
@@ -173,24 +213,31 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
|
|
|
{"Max", (float a1, float a2) => Math.Max(a1, a2)},
|
|
|
{"Max", (Vector2 a1, Vector2 a2) => Vector2.Max(a1, a2)},
|
|
|
+ {"Max", (Vector a1, Vector a2) => Vector.Max(a1, a2)},
|
|
|
{"Max", (Vector3 a1, Vector3 a2) => Vector3.Max(a1, a2)},
|
|
|
+ {"Max", (Vector3D a1, Vector3D a2) => Vector3D.Max(a1, a2)},
|
|
|
{"Max", (Vector4 a1, Vector4 a2) => Vector4.Max(a1, a2)},
|
|
|
|
|
|
|
|
|
{"Min", (float a1, float a2) => Math.Min(a1, a2)},
|
|
|
{"Min", (Vector2 a1, Vector2 a2) => Vector2.Min(a1, a2)},
|
|
|
+ {"Min", (Vector a1, Vector a2) => Vector.Min(a1, a2)},
|
|
|
{"Min", (Vector3 a1, Vector3 a2) => Vector3.Min(a1, a2)},
|
|
|
+ {"Min", (Vector3D a1, Vector3D a2) => Vector3D.Min(a1, a2)},
|
|
|
{"Min", (Vector4 a1, Vector4 a2) => Vector4.Min(a1, a2)},
|
|
|
|
|
|
{"Mod", (float a, float b) => a % b},
|
|
|
|
|
|
{"Normalize", (Quaternion a) => Quaternion.Normalize(a)},
|
|
|
{"Normalize", (Vector2 a) => Vector2.Normalize(a)},
|
|
|
+ {"Normalize", (Vector a) => Vector.Normalize(a)},
|
|
|
{"Normalize", (Vector3 a) => Vector3.Normalize(a)},
|
|
|
+ {"Normalize", (Vector3D a) => Vector3D.Normalize(a)},
|
|
|
{"Normalize", (Vector4 a) => Vector4.Normalize(a)},
|
|
|
|
|
|
{"Pow", (float a, float b) => (float) Math.Pow(a, b)},
|
|
|
{"Quaternion.CreateFromAxisAngle", (Vector3 a, float b) => Quaternion.CreateFromAxisAngle(a, b)},
|
|
|
+ {"Quaternion.CreateFromAxisAngle", (Vector3D a, float b) => Quaternion.CreateFromAxisAngle(a.ToVector3(), b)},
|
|
|
{"Quaternion", (float a, float b, float c, float d) => new Quaternion(a, b, c, d)},
|
|
|
|
|
|
{"Round", (float a) => (float) Math.Round(a)},
|
|
|
@@ -198,14 +245,18 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
{"Scale", (Matrix3x2 a, float b) => a * b},
|
|
|
{"Scale", (Matrix4x4 a, float b) => a * b},
|
|
|
{"Scale", (Vector2 a, float b) => a * b},
|
|
|
+ {"Scale", (Vector a, float b) => a * b},
|
|
|
{"Scale", (Vector3 a, float b) => a * b},
|
|
|
+ {"Scale", (Vector3D a, float b) => Vector3D.Multiply(a, b)},
|
|
|
{"Scale", (Vector4 a, float b) => a * b},
|
|
|
|
|
|
{"Sin", (float a) => (float) Math.Sin(a)},
|
|
|
|
|
|
{"SmoothStep", (float a1, float a2, float a3) => SmoothStep(a1, a2, a3)},
|
|
|
{"SmoothStep", (Vector2 a1, Vector2 a2, Vector2 a3) => SmoothStep(a1, a2, a3)},
|
|
|
+ {"SmoothStep", (Vector a1, Vector a2, Vector a3) => SmoothStep(a1, a2, a3)},
|
|
|
{"SmoothStep", (Vector3 a1, Vector3 a2, Vector3 a3) => SmoothStep(a1, a2, a3)},
|
|
|
+ {"SmoothStep", (Vector3D a1, Vector3D a2, Vector3D a3) => SmoothStep(a1, a2, a3)},
|
|
|
{"SmoothStep", (Vector4 a1, Vector4 a2, Vector4 a3) => SmoothStep(a1, a2, a3)},
|
|
|
|
|
|
// I have no idea how to do a spherical interpolation for a scalar value, so we are doing a linear one
|
|
|
@@ -222,9 +273,13 @@ namespace Avalonia.Rendering.Composition.Expressions
|
|
|
{"Transform", (Vector2 a, Matrix3x2 b) => Vector2.Transform(a, b)},
|
|
|
{"Transform", (Vector3 a, Matrix4x4 b) => Vector3.Transform(a, b)},
|
|
|
|
|
|
- {"Vector2", (float a, float b) => new Vector2(a, b)},
|
|
|
- {"Vector3", (float a, float b, float c) => new Vector3(a, b, c)},
|
|
|
+ {"Vector2", (float a, float b) => new Vector(a, b)},
|
|
|
+ {"Vector2", (double a, double b) => new Vector(a, b)},
|
|
|
+ {"Vector3", (float a, float b, float c) => new Vector3D(a, b, c)},
|
|
|
+ {"Vector3", (double a, double b, double c) => new Vector3D(a, b, c)},
|
|
|
{"Vector3", (Vector2 v2, float z) => new Vector3(v2, z)},
|
|
|
+ {"Vector3", (Vector v2, float z) => new Vector3D(v2.X, v2.Y, z)},
|
|
|
+ {"Vector3", (Vector v2, double z) => new Vector3D(v2.X, v2.Y, z)},
|
|
|
{"Vector4", (float a, float b, float c, float d) => new Vector4(a, b, c, d)},
|
|
|
{"Vector4", (Vector2 v2, float z, float w) => new Vector4(v2, z, w)},
|
|
|
{"Vector4", (Vector3 v3, float w) => new Vector4(v3, w)},
|