using System.Collections; using System.Collections.Generic; using Godot; using System; namespace Rokojori { public enum TextureCombinerBlendMode { Normal, Add, Multiply } public class TextureCombinerBlendModeAlgorithm { public static void Blend( TextureCombinerBlendMode blendMode, int x, int y, int w, int h, float topOpacity, TextureBuffer bottom, TextureBuffer top, TextureBuffer output ) { if ( TextureCombinerBlendMode.Normal == blendMode ) { BlendNormal( x, y, w, h, topOpacity, bottom, top, output ); } } static void BlendNormal( int x, int y, int w, int h, float topOpacity, TextureBuffer bottom, TextureBuffer top, TextureBuffer output ) { for ( int i = 0; i < w; i++ ) { var rx = x + i; for ( int j = 0; j < h; j++ ) { var ry = y + j; var index = output.ComputeIndexFromPosition( rx, ry ); var topColor = top.GetIndexed( index ).FadeAlpha( topOpacity ); var bottomColor = bottom.GetIndexed( index ); var outputColor = bottomColor.Blend( topColor ); output.SetIndexed( index, outputColor ); } } } } }