半透明物体渲染的顺序 [英] Order of translucent object rendering

查看:30
本文介绍了半透明物体渲染的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

渲染半透明物体时(使用glBlend),建议从后到前z顺序对物体进行排序.

When rendering a translucent object (using glBlend), it is advised to sort objects from back to front z order.

来自 opengl 文档:在应用程序中使用深度缓冲时,您需要注意渲染图元的顺序.完全不透明的图元需要先被渲染,然后是部分不透明的图元以从后到前的顺序.如果您不按此顺序渲染图元,则原本可以通过部分不透明图元看到的图元可能会完全失去深度测试.

From opengl docs: When using depth buffering in an application, you need to be careful about the order in which you render primitives. Fully opaque primitives need to be rendered first, followed by partially opaque primitives in back-to-front order. If you don't render primitives in this order, the primitives, which would otherwise be visible through a partially opaque primitive, might lose the depth test entirely.

因此,每当我在渲染不透明三角形后渲染半透明对象时,如果我根据视图方向"从后到前渲染半透明三角形,这是正确的吗?这里的从前到后到底是什么意思?我试图理解,如果我有一个经过 mvp 转换的场景对象,我是否需要专门查看世界坐标​​中的顺序以及与相机中心的关系?

So, whenever I'm rendering translucent objects after rendering opaque triangles, if I render translucent triangles from back to front in relation to the "view direction", is this correct? What exactly does back to front mean here? I'm trying to understand, if I have a scene objects that go through a mvp transformation, do I need to specifically look at the order in world coordinates, and in relation to the camera center?

此外,这是否会根据混合类型而改变?

Also, additionally does this change depending on the blend type?

推荐答案

无论何时渲染半透明三角形,都必须从后到前绘制它们.这里的从后到前意味着,您必须先绘制离屏幕更远的三角形(具有更高的深度值).

Whenever you render translucent triangles, you have to draw them back-to-front. Back-to-front here means, that you have to draw triangles first that are further away from the screen (that have a higher depth value).

这是必要的原因是大多数混合方程根据顺序产生不同的结果.在 OpenGL 中实现的方程通常是这样的,它们在从后到前渲染时会给出正确"的结果.

The reason why this is necessary is that most blending equations yield different results depending on the order. The equations as implemented in OpenGL are usually such that they give "correct" results when rendering back-to-front.

这篇关于半透明物体渲染的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆