0

我有很多透明基元要在绘制之前进行排序,但是为了获得 Z 坐标、排序键,我已经在软件中执行了硬件中顶点着色器执行的所有转换。

我认为我可以通过从着色器中检索 Z 坐标并使用它对下一帧中的图元进行排序来优化该过程。由于原语的顺序预计不会在帧之间发生剧烈变化,因此它应提供足够公平的顺序。那么,我想知道如何从顶点着色器中获取一批 Z 坐标?可能吗?

4

2 回答 2

2

您可以使用变换反馈将数据从顶点着色器输出获取到缓冲区中,稍后您可以读取该缓冲区,但我认为这不会给您带来太多好处,您应该分析哪种解决方案是最好的(实验性的)。

于 2011-05-30T16:14:16.723 回答
1

Instead of looking at each primitive individually you should sort based on connected meshes' bounding volumes. This kind of sorting comes more or less for free if you organize the geometry in a spatial subdivision structure like Kd or BSP tree. Then the sorting problem is reduced to implementing a traversal of the tree in the right direction -- basically it boils down to a depth first traversal with the branches traversed in a near←→far fashion.

于 2011-05-30T16:22:14.413 回答