I've been using the Canvas object in conjunction with Image Manipulator to store data in color (RGB) channels for later retrieval. I've reached a point where I require a fourth storage channel (Alpha) for this purpose, but I'm unable to paste to it, without destroying existing data in the color channels.
I've tried Erase, Mask and most of Fisholith's Effects, but as mentioned they destroy the RGB data.
An example of what I need would be pasting a pixel with RGBA values of 1 1 1 .3 onto a Canvas with .5 .8 .3 1 and getting .5 .8 .3 .3 as a result - the source RGB would be disgarded and the destination A would be replaced with source A.
I've started writing an Effect for this purpose, but I've hit a snag with relative Sprite sizes (I'm guessing):
// AlphaReplace
// Funky Koval
// PS 2.0
// Replaces BG alpha with FG alpha preserving color values.
// Foreground texture
texture ForegroundTexture;
// Foreground sampler
sampler2D foreground = sampler_state {
Texture = (ForegroundTexture);
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};
// Background texture
texture BackgroundTexture;
// Background sampler
sampler2D background = sampler_state {
Texture = (BackgroundTexture);
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};
// Effect function
float4 EffectProcess( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 bg = tex2D(background, Tex);
float4 fg = tex2D(foreground, Tex);
bg.a=fg.a;
return bg;
}
// ConstructEffect
technique ConstructEffect
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_2_0 EffectProcess();
}
}
Any help would be most appreciated.