GLSL如何在着色器处理后检索顶点位置? [英] GLSL How to retrieve vertex position after a shader process it?

查看:77
本文介绍了GLSL如何在着色器处理后检索顶点位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个使用弹簧模拟软体的程序.看起来不错,但问题是它占用大量CPU时间.因此,我无法在笔记本电脑或任何非高端PC上运行它.

I wrote a program that simulates soft bodies using springs. It looks nice but the problem is it consumes a lot of CPU time. So I can not run it on my laptop or any not high end PC.

我认为编写一个顶点着色器并将逻辑移到GPU上是个好主意.我已经阅读了一些教程并制作了一个卡通着色器,所以我认为(错误)我已经准备好了.

I thought It would be a good idea to write a vertex shader and move the logic to the GPU. I've read some tutorials and made a toon shader so I thought (wrong) I was ready to go.

我遇到的最大问题是,我需要知道顶点的旧位置才能计算出新的顶点.我不知道如何获取顶点位置,以便每帧将其发送回着色器?

The big problem I have is that I need to know the old position of a vertex to calculate the new one. I don't know how could I retrieve a vertex position so I could send it back to the shaders each frame?

我不太确定这是否有可能做,也许我正在尝试做一些着色器从未打算做的事情.我仍在研究,但我想可以问一问是否有人可以提供帮助.

I'm not really sure is this even possible to do and maybe I'm trying to do something that shaders are never meant to do. I am still researching but I thought I could ask an see if maybe someone can help.

推荐答案

如果您的硬件支持OpenGL 3.0或更高版本,则可以使用转换反馈机制.还有其他一些方法可以使顶点位置恢复原状,例如仔细地安排渲染,以便将三角形(或点图元)写入屏幕上的每个单独像素.这相当困难,您需要渲染到需要FBO支持的浮点缓冲区.

You can use the transform feedback mechanism if your hardware supports OpenGL 3.0 or above. There are also other techniques for getting the vertex position back, like carefully arranging your rendering so that you're writing a triangle (or point primitive) to each separate pixel on the screen. This is fairly difficult, and you need to render to a floating-point buffer, which requires FBO support.

这篇关于GLSL如何在着色器处理后检索顶点位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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