我应该如何进行深度无关混合?
我正在为名为 Gwen 的 GUI 工具包开发 OpenGL 3 渲染器。我几乎一切都正常工作,但在让一切正确混合方面遇到了一些问题。我已经根据它们使用的纹理对三角形进行了排序,并将它们打包到 VBO 中,因此通过单元测试,它基本上可以归结为 3 层:没有纹理的填充矩形、文本以及使用肌理。
填充矩形通常绘制在其他所有内容之上并混合在一起,但所有内容背后的背景也是填充矩形,所以我不能指望这一点。如果您最后绘制它们,则会出现 Z 值冲突(例如:窗口边缘周围有纹理阴影,由于背景未通过深度测试而变黑),如果您先绘制它们,则会出现混合/z 值冲突(例如:一些选择的突出显示被绘制在上面,而不是像他们应该的那样混合)。
我不能指望能够识别除填充矩形之外的任何特定图层。不同的图层混合了 z 值,因此我不能仅按特定顺序绘制它们以使事情正常工作。在写这篇文章时,我想到了一种简单的方法来绘制从后到前排序的三角形,但这可能意味着很多小的绘制调用,我希望避免这种情况。有没有一些涉及巫术魔法混合的方法可以让我保留大批量的三角形?
I'm working on an OpenGL 3 renderer for a GUI toolkit called Gwen. I nearly have everything working, but I'm having some issues getting everything to blend correctly. I've sorted the triangles by which texture they use and packed them into a VBO, so with the Unit Test, it basically boils down into 3 layers: Filled Rects with no texture, Text, and the windows, buttons, etc that use a skin texture.
The Filled Rects are usually drawn on top of everything else and blended in, but the background behind everything is also a Filled Rect, so I can't count on that. There is a Z-value conflict if you draw them last (ex: the windows have a textured shadow around the edges that turns black because the background fails the depth test) and a blending/z-value conflict if you draw them first (ex: some of the selection highlights get drawn on top of instead of blending like they're supposed to).
I can't count on being able to identify any specific layer except the Filled Rects. The different layers have a mix of z-values, so I can't just draw them in a certain order to make things work. While writing this, I thought of a simple method of drawing the triangles sorted back to front, but it could mean lots of little draw calls, which I'm hoping to avoid. Is there some method that involves some voodoo magic blending that would let me keep my big batches of triangles?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在绘制一个GUI;批处理不应该成为您的首要任务,因为 GUI 的作用并不大。 GUI 几乎永远不会成为您的性能瓶颈。这有点过早优化的味道;首先,让它发挥作用。然后,如果它太慢,就让它运行得更快。
没有简单的机制可以实现与订单无关的透明度。最好的选择是以正确的 Z 顺序渲染事物。
You're drawing a GUI; batching shouldn't be your first priority for the simple fact that a GUI just doesn't do much. A GUI will almost never be your performance bottleneck. This smells of premature optimization; first, get it to work. Then, if it's too slow, make it work faster.
There is no simple mechanism for order-independent transparency. Your best bet is to just render things in the proper Z order.