Reputation: 23
I have to reproduce an effect which consists of combining two textures (tiles + coin) to achieve the following:
The best result I achieved so far:
Visual Studio Solution to reproduce the problem
The link above will take you to the project and here what I tried to do in the pixel shader:
float4 PS(PS_INPUT input) : SV_Target
{
float4 color1;
float4 color2;
float4 blendColor;
// Get the pixel color from the first texture.
color1 = texTile.Sample(samLinear, input.Tex) * vMeshColor;
// Get the pixel color from the second texture.
color2 = texCoin.Sample(samLinear, input.Tex) * vMeshColor;
// Blend the two pixels together and multiply by the gamma value.
blendColor = color1 * color2;
// Saturate the final color.
blendColor = saturate(blendColor);
return blendColor;
}
But it does not seem the right way of doing this.
Which aproach should I take to have the expected result?
Upvotes: 0
Views: 116
Reputation: 91
Well firstly you are blending them but not blending using an alpha-mask, when the example image seems to have been blended with an alpha-mask.
An example could be something like below; provided the coin has got an alpha-channel.
(Otherwise you'll have to calculate an alpha or add one in an image editing software.
float3 blend(float4 CoinTex, float3 GridTex)
{
// Inverse of alpha, to get the area around the coin
// Alpha spans from [0,1] so the expression below would suffice
float1 inverseAlpha = (1 - CoinTex.a);
float3 blendedTex = 0;
// If-else that is evaluated to decide how they'll be overlayed
if (inverseAlpha > 0.0 ){
blendedTex = GridTex.rgb;
} else {blendedTex = CoinTex.rgb;}
return blendedTex;
}
Upvotes: 1