rj-action-library/Runtime/Procedural/Textures/TextureCombiner/TextureCombinerBlendMode.cs

53 lines
1.2 KiB
C#
Raw Normal View History

2025-02-14 07:44:20 +00:00
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<Color> bottom, TextureBuffer<Color> top, TextureBuffer<Color> 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<Color> bottom, TextureBuffer<Color> top, TextureBuffer<Color> 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 );
}
}
}
}
}