且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有Vertex/Pixel着色器的通用计算(Open GL/DirectX)

更新时间:2023-01-05 11:48:13

我是否可以使用OpenGL顶点着色器进行GPGPU编程?

is there anyway I can use OpenGL vertex shaders for GPGPU programming?

从顶点着色器中取出的内容通常在光栅化阶段进行插值.在旧版本的openGL中,您可以指定是否应对特定变量进行这种插值.我不知道您是否仍然可以这样做...是的,您仍然可以(提示给datenwolf)...但是,我认为更好的方法是使用片段着色器.使用一个简单的顶点着色器渲染一个完整的帧,渲染两个覆盖整个帧的三角形(一个四边形)(对于任何后期处理效果),然后在片段着色器中进行计算.将要用作数据的数据放入纹理中,然后使用帧缓冲对象(FBO)将结果渲染为其他纹理.

The stuff that goes out of the vertex shader is generally interpolated at the raserization stage. In old versions of openGL you could specify if such interpolation should or should not happen for specific variables. I don't know if you can still do that... Yes you still can (thx to datenwolf for the tip)... but a better approach, in my opinion, is to use fragment shaders. Render to a full frame, using a simple vertex shader that renders two triangles that cover the whole frame (a quad), as for any post process effect, and do your computation in the fragment shader. Put the data you want to use as input in textures, and render your results to other textures using frame buffer objects (FBO).