XNA - 渲染到纹理的 Alpha 通道
我有一个纹理,我想在运行时修改它的 Alpha 通道。
有没有办法在纹理的 Alpha 通道上绘图?
或者也许用另一个纹理的通道替换通道?
谢谢,
西南。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,根据您的评论,您应该做的是使用像素着色器。您的源图像甚至不需要 Alpha 通道 - 让像素着色器应用 Alpha。
事实上,您可能还应该在 GPU 上计算 alpha 通道的值(即:运行流体解算器)。
您的着色器可能如下所示:
XNA 是一个不错的起点 精灵效果示例。
甚至还有与您正在做的类似的效果:
(来源:msdn.com)
示例中的效果从第二个纹理读取,以获取绘制第一个纹理时计算其 Alpha 通道的值。
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:
A good place to start would be the XNA Sprite Effects sample.
There's even an effect similar to what you are doing:
(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.