OpenGL 与源和目标 Alpha 混合

发布于 2024-10-05 08:01:05 字数 474 浏览 0 评论 0原文

我正在尝试将带有 alpha 的纹理渲染到带有 alpha 的帧缓冲区。我需要纹理的透明度由其自身的 Alpha 和已渲染到帧缓冲区的 Alpha 的组合来控制。

即:

正常透明度:

(src_colour * src_alpha) + (dst_colour * 1-src_alpha)

所需透明度:

(src_colour * src_alpha * dst_alphe) + (dst_colour * 1-(src_alpha * dst_alpha))

谁能弄清楚如何做到这一点?

我已经为此工作了 9 个小时:-)

我在 Android 上使用 OpenGL 1.0 和 GL11ExtensionPack,因此我可以访问 glBlendFunc 和 glBlendFuncSeparate。我不想使用着色器走 GLES20 路线,因为这需要重写大量代码。

谢谢, 安德鲁

I'm trying to render a texture with alpha to a frame buffer with alpha. I need the texture's transparency to be controlled by a combination of its own alpha, and the alpha already rendered to the frame buffer.

ie:

Normal transparency:

(src_colour * src_alpha) + (dst_colour * 1-src_alpha)

Required transparency:

(src_colour * src_alpha * dst_alphe) + (dst_colour * 1-(src_alpha * dst_alpha))

Can anyone figure out how to do this?

I've been working on it for 9 hours now :-)

I'm using OpenGL 1.0 with GL11ExtensionPack on Android, so I have access to glBlendFunc and glBlendFuncSeparate. I would prefer not to go the GLES20 route with shaders as that would require a lot of code to be rewritten.

Thanks,
Andrew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛放△進行李 2024-10-12 08:01:05

这是我使用过的解决方案:

  1. 启用颜色和 alpha 写入
  2. glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA)
  3. 渲染前景对象
  4. 禁用 alpha 写入
  5. 渲染阴影
  6. 渲染正在投射阴影的对象
  7. glBlendFunc(GL10.GL_ONE_MINUS_DST_ALPHA, GL10.GL_DST_ALPHA)
  8. 渲染背景对象

这会产生仅出现在前景对象上的阴影所需的效果。实际上,Alpha 缓冲区变成了具有可变不透明度的模板缓冲区。

幸运的是,我的背景对象没有透明度,就好像它们有透明度一样,我认为在不使用着色器的情况下没有任何方法可以实现这种效果。

This is the solution I've used:

  1. enable colour and alpha writes
  2. glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA)
  3. render foreground objects
  4. disabe alpha writes
  5. render shadows
  6. render objects that are casting shadows
  7. glBlendFunc(GL10.GL_ONE_MINUS_DST_ALPHA, GL10.GL_DST_ALPHA)
  8. render background objects

This produces the desired effect of shadows appearing only on foreground objects. Effectively the alpha buffer becomes a stencil buffer with variable opacity.

It's fortunate that my background objects don't have transparency, as if they did I don't think there would be any way to achieve this effect without using shaders.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文