diff --git a/Runtime/Rendering/TextureAttributes/SetTextureAttributeChannel.cs b/Runtime/Rendering/TextureAttributes/SetTextureAttributeChannel.cs index 3b3241a..ba10d0a 100644 --- a/Runtime/Rendering/TextureAttributes/SetTextureAttributeChannel.cs +++ b/Runtime/Rendering/TextureAttributes/SetTextureAttributeChannel.cs @@ -21,6 +21,9 @@ namespace Rokojori [Export] public TextureAttributes.Channel channel = TextureAttributes.Channel.Red; + [Export] + public TextureAttributes.OperatorType operatorType = TextureAttributes.OperatorType.Set; + protected override void _OnTrigger() { var ta = textureAttributes; @@ -37,7 +40,7 @@ namespace Rokojori } this.LogInfo( "Index", index, "Value:", value, "Channel:", channel ); - ta.SetChannel( index, value, channel ); + ta.SetChannel( index, value, channel, operatorType ); } } } \ No newline at end of file diff --git a/Runtime/Rendering/TextureAttributes/TextureAttributes.cs b/Runtime/Rendering/TextureAttributes/TextureAttributes.cs index f7aa0fb..3693062 100644 --- a/Runtime/Rendering/TextureAttributes/TextureAttributes.cs +++ b/Runtime/Rendering/TextureAttributes/TextureAttributes.cs @@ -26,6 +26,11 @@ namespace Rokojori Red, Green, Blue, Alpha } + public enum OperatorType + { + Set, Add, Subtract, Multiply + } + [Export] public Size sizeType =Size._64; @@ -132,7 +137,33 @@ namespace Rokojori ); } - public void SetChannel( int index, float value, Channel channel ) + float ApplyOperator( float leftValue, float rightValue, OperatorType operatorType ) + { + if ( OperatorType.Set == operatorType ) + { + return rightValue; + } + + if ( OperatorType.Add == operatorType ) + { + return leftValue + rightValue; + } + + if ( OperatorType.Subtract == operatorType ) + { + return leftValue - rightValue; + } + + if ( OperatorType.Multiply == operatorType ) + { + return leftValue * rightValue; + } + + return leftValue; + + } + + public void SetChannel( int index, float value, Channel channel, OperatorType operatorType = OperatorType.Set ) { Update( ( Image i ) => @@ -142,19 +173,19 @@ namespace Rokojori if ( channel == Channel.Red ) { - currentValue.R = value; + currentValue.R = ApplyOperator( currentValue.R, value, operatorType ); } else if ( channel == Channel.Green ) { - currentValue.G = value; + currentValue.G = ApplyOperator( currentValue.G, value, operatorType ); } else if ( channel == Channel.Blue ) { - currentValue.B = value; + currentValue.B = ApplyOperator( currentValue.B, value, operatorType ); } else if ( channel == Channel.Alpha ) { - currentValue.A = value; + currentValue.A = ApplyOperator( currentValue.A, value, operatorType ); } i.SetPixelv( uv, currentValue ); diff --git a/Runtime/Structures/Spatial/Voronoi/Voronoi2D.cs b/Runtime/Structures/Spatial/Voronoi/Voronoi2D.cs index 4fc7575..2cc1eb3 100644 --- a/Runtime/Structures/Spatial/Voronoi/Voronoi2D.cs +++ b/Runtime/Structures/Spatial/Voronoi/Voronoi2D.cs @@ -43,6 +43,9 @@ namespace Rokojori { return boundaries.Map( b => _voronoi2D.boundaryPoints[ b ] ); } + + public Vector2 center => _voronoi2D.cellPoints[ index ]; + }