HLSL - Combining textures

Posted by b34r on Stack Overflow See other posts from Stack Overflow or by b34r
Published on 2011-03-15T08:06:55Z Indexed on 2011/03/15 8:10 UTC
Read the original article Hit count: 166

Filed under:
|
|

Hi All,

I'm trying to combine two textures in HLSL - specifically, I want to take the alpha values from a base image, and the color data from an overlay image.

My pixel shader for this looks like this:

float4 PixelShaderFunction(VertexOut input) : COLOR0
{
    float4 baseColor = tex2D( BaseSampler, input.baseCoords.xy ).rgba;
    float4 overlayColor = tex2D( OverlaySampler, input.overlayCoords.xy ).rgba;

    float4 color;
    color.r = overlayColor.r;
    color.g = overlayColor.g;
    color.b = overlayColor.b;
    color.a = baseColor.a;

    return color.rgba;
}

and my blend state looks like this:

    BlendState bs = new BlendState();
    bs.AlphaSourceBlend = Blend.SourceAlpha;
    bs.AlphaDestinationBlend = Blend.DestinationAlpha;
    bs.ColorSourceBlend = Blend.SourceColor;
    bs.ColorDestinationBlend = Blend.DestinationColor;

What this leaves me with is a washed out version of what should be the overlay color. I've tried numerous permutations of the BlendState settings, and played with the pixel shader math quite a bit, but to no avail.

Can anyone point me in the right direction?

Thanks in advance =)

© Stack Overflow or respective owner

Related posts about c#

Related posts about hlsl