开发者

XNA - Render to a texture's alpha channel

I have a texture that I want to modify it's alpha channel in runtime.

Is there a way to draw开发者_运维百科 on a texture's alpha channel ?

Or maybe replace the channel with that of another texture ?

Thanks,

SW.


Ok, based on your comment, what you should do is use a pixel shader. Your source image doesn't even need an alpha channel - let the pixel shader apply an alpha.

In fact you should probably calculate the values for the alpha channel (ie: run your fluid solver) on the GPU as well.

Your shader might look something like this:

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 c = tex2D(textureSampler, uv);
    c.A = /* calculate alpha value here */;
    return c;
}

A good place to start would be the XNA Sprite Effects sample.

There's even an effect similar to what you are doing:

XNA - Render to a texture's alpha channel


(source: msdn.com)

The effect in the sample reads from a second texture to get values for the calculation of the alpha channel of the first texture when it is drawn.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜