Browse Source

Renamed FullSizeByteConstant to AsConstantColorByte() and clamp values between 0 and 1

CPKreuz 11 months ago
parent
commit
dda80a9362

+ 6 - 6
src/PixiEditor.ChangeableDocument/Changeables/Graph/Context/FuncContext.cs

@@ -99,10 +99,10 @@ public class FuncContext
         if (!HasContext && r is Float1 firstFloat && g is Float1 secondFloat && b is Float1 thirdFloat && a is Float1 fourthFloat)
         {
             Half4 constantHalf4 = new Half4("");
-            byte rByte = firstFloat.FullSizeByteConstant;
-            byte gByte = secondFloat.FullSizeByteConstant;
-            byte bByte = thirdFloat.FullSizeByteConstant;
-            byte aByte = fourthFloat.FullSizeByteConstant;
+            byte rByte = firstFloat.AsConstantColorByte();
+            byte gByte = secondFloat.AsConstantColorByte();
+            byte bByte = thirdFloat.AsConstantColorByte();
+            byte aByte = fourthFloat.AsConstantColorByte();
             constantHalf4.ConstantValue = new Color(rByte, gByte, bByte, aByte);
             return constantHalf4;
         }
@@ -118,7 +118,7 @@ public class FuncContext
             var hValue = firstFloat.ConstantValue * 360;
             var sValue = secondFloat.ConstantValue * 100;
             var vValue = thirdFloat.ConstantValue * 100;
-            byte aByte = fourthFloat.FullSizeByteConstant;
+            byte aByte = fourthFloat.AsConstantColorByte();
             constantHalf4.ConstantValue = Color.FromHsv((float)hValue, (float)sValue, (float)vValue, aByte);
             return constantHalf4;
         }
@@ -134,7 +134,7 @@ public class FuncContext
             var hValue = firstFloat.ConstantValue * 360;
             var sValue = secondFloat.ConstantValue * 100;
             var lValue = thirdFloat.ConstantValue * 100;
-            byte aByte = fourthFloat.FullSizeByteConstant;
+            byte aByte = fourthFloat.AsConstantColorByte();
             constantHalf4.ConstantValue = Color.FromHsl((float)hValue, (float)sValue, (float)lValue, aByte);
             return constantHalf4;
         }

+ 4 - 2
src/PixiEditor.DrawingApi.Core/Shaders/Generation/Expressions/Float1.cs

@@ -1,4 +1,6 @@
-namespace PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
+using System;
+
+namespace PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
 
 /// <summary>
 ///     This is a shader type that represents a high precision floating point value. For medium precision see Short type.
@@ -16,5 +18,5 @@ public class Float1(string name) : ShaderExpressionVariable<double>(name)
 
     public static explicit operator double(Float1 value) => value.ConstantValue;
 
-    public byte FullSizeByteConstant => (byte)(ConstantValue * 255);
+    public byte AsConstantColorByte() => (byte)(Math.Clamp(ConstantValue, 0, 1) * 255);
 }