开发者

Retrieving data from GLSL vertex shader

开发者 https://www.devze.com 2023-03-09 19:18 出处:网络
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

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 sor开发者_StackOverflow中文版t 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?


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号