And what happens when you do this? I mean this will render single texture and you are actually overwriting texture you set as paramater with texture that is assigned by spriteBatch on draw call when flushing this:
spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);
Define overlay…
also again, what results are you getting atm? What´s the issue, do you have issue to render underlay texture? Or that part is working fine?
And again, you can do this, this will blend color between textures with 0.5f bias (half - half), if you want to pan one texture it is easy enough but we need to make sure we are on same page and everything else is working, results are as expected at that stage and everyone understand code so far.
good but that doesnt answer important question: Where are we right now, are you having trouble rendering single texture? If you want to replace based on alpha, so for instance you want to use second texture if alpha of first texture is 0.2 or lower then:
texture rainbowpic;
sampler Sampler0 : register(s0)
{
};
sampler Sampler1 : register(s1)
{
Texture = (rainbowpic);
};
float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
float4 color = tex2D(Sampler0, coords);
float4 rainbow_color = tex2D(Sampler1 , coords);
if(color.a < 0.2)
{
color = rainbow_color;
}
//or if based on second texture which is probably what you mean by overlay
//if(rainbow_color.a > 0.0)
//{
//color = rainbow_color;
//}
return color;
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}
So what you wanted to do was to use alpha of one texture as alpha of another, basically you wanted to mask second texture. Just for future reference.
Your code is very poorly optimized for such a simple task, I would like to recommend:
float4 PixelShaderFunction (float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
//sample alpha from first texture
float mask = tex2D (Sampler0, coords).a;
//sample rgb and alpha from second
float4 rainbow_color = tex2D (Sampler1 , coords);
//multiply alpha channels, only pixels that are visible on both should remain visible AND operation
rainbow_color.a *= mask;
//render
return rainbow_color;
}
This would also preserve antialiasing from original text if there would be any.
no what i wanted to do was use the alpha of one texture as a mask for the other texture, basically this…
if pixel from tex1 visible then use entire pixel from tex2
tex2 is basically going to be a background of anything i see fit to put on it, scroller, starfield, color bars, anything, probably moving in someway without a ton of graphic animation, i just needed to be able to use a shader to do it
Many thanks, once done i’ll upload a you-tube so you can see
In addition, using shaders like this allows me to have animation within animation, a bouncing ball with a fully random starfield or scrolling banner etc
the only reason i need the original alpha is to “cookie cut” another texture that i could mess with
Thanks
You probably meant ‘declare’ when you said ‘use’.
This has come up before… I think it’s a MojoShader bug, or maybe it’s a bug in how 2mgfx interprets MojoShader reflection data. Either way, it’s a bug.