从 GLSL 顶点着色器检索数据
我有很多透明基元,我想在绘制之前对其进行排序,但为了获取 Z 坐标(排序键),我在软件中执行了由硬件中的顶点着色器执行的所有转换。
我认为我可以通过从着色器检索 Z 坐标并使用它对下一帧中的图元进行排序来优化该过程。由于基元的顺序预计不会在帧之间发生巨大变化,因此它应提供足够公平的排序。那么,我想知道如何从顶点着色器获取一批 Z 坐标?是否可以?
I have lots of transparent primitives I want to sort before drawing, but to get the Z coordinate, the sorting key, I have perform in software all the transformations performed by the vertex shader in hardware.
I thought I could optimize the process by retrieving the Z coordinate from the shader, and using it to sort the primitives in the next frame. Since the order of primitives is not expected to change drastically between frames, it shall provide fair enough ordering. So, I'd like to know how to get batch of Z coordinates back from the vertex shader? Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用变换反馈将数据从顶点着色器输出获取到您稍后可以阅读的缓冲区,但我认为这不会给您带来太多好处,您应该分析哪种解决方案是最好的(实验性的)。
You can use Transform Feedback to get data from the Vertex Shader output into a Buffer which you can later read, but i don't think this will gain you much, you should profile which solution is best (experimentally).
您应该根据连接的网格体的边界体积进行排序,而不是单独查看每个图元。如果您在 Kd 或 BSP 树等空间细分结构中组织几何图形,那么这种排序或多或少是免费的。然后,排序问题被简化为以正确的方向实现树的遍历——基本上它归结为深度优先遍历,分支以近←→远的方式遍历。
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.