|
@@ -20,12 +20,15 @@ public class SampleImageNode : Node
|
|
|
|
|
|
public InputProperty<ColorSampleMode> SampleMode { get; }
|
|
|
|
|
|
+ public InputProperty<bool> NormalizedCoordinates { get; }
|
|
|
+
|
|
|
public SampleImageNode()
|
|
|
{
|
|
|
- Image = CreateInput<Texture>(nameof(Texture), "IMAGE", null);
|
|
|
- Coordinate = CreateFuncInput<Float2>(nameof(Coordinate), "UV", VecD.Zero);
|
|
|
- Color = CreateFuncOutput(nameof(Color), "COLOR", GetColor);
|
|
|
- SampleMode = CreateInput(nameof(SampleMode), "COLOR_SAMPLE_MODE", ColorSampleMode.ColorManaged);
|
|
|
+ Image = CreateInput<Texture>("Texture", "IMAGE", null);
|
|
|
+ Coordinate = CreateFuncInput<Float2>("Coordinate", "UV", VecD.Zero);
|
|
|
+ Color = CreateFuncOutput("Color", "COLOR", GetColor);
|
|
|
+ SampleMode = CreateInput("SampleMode", "COLOR_SAMPLE_MODE", ColorSampleMode.ColorManaged);
|
|
|
+ NormalizedCoordinates = CreateInput("NormalizedCoordinates", "NORMALIZED_COORDINATES", true);
|
|
|
}
|
|
|
|
|
|
private Half4 GetColor(FuncContext context)
|
|
@@ -39,11 +42,20 @@ public class SampleImageNode : Node
|
|
|
{
|
|
|
Expression uv = context.GetValue(Coordinate);
|
|
|
|
|
|
- return context.SampleSurface(Image.Value.DrawingSurface, uv, SampleMode.Value);
|
|
|
+ return context.SampleSurface(Image.Value.DrawingSurface, uv, SampleMode.Value, NormalizedCoordinates.Value);
|
|
|
}
|
|
|
|
|
|
Color color;
|
|
|
- VecI pixelCoordinate = (VecI)context.GetValue(Coordinate).ConstantValue.Round();
|
|
|
+
|
|
|
+ VecD coordinate = context.GetValue(Coordinate).ConstantValue;
|
|
|
+ VecI pixelCoordinate = (VecI)coordinate.Round();
|
|
|
+
|
|
|
+ if(NormalizedCoordinates.Value)
|
|
|
+ {
|
|
|
+ VecD size = Image.Value.Size;
|
|
|
+ pixelCoordinate = (VecI)(new VecD(coordinate.X * size.X, coordinate.Y * size.Y)).Round();
|
|
|
+ }
|
|
|
+
|
|
|
if (SampleMode.Value == ColorSampleMode.ColorManaged)
|
|
|
{
|
|
|
color = Image.Value.GetSRGBPixel(pixelCoordinate);
|