使用 OpenGL ES 2.0 进行 GPGPU 编程 [英] GPGPU programming with OpenGL ES 2.0

查看:16
本文介绍了使用 OpenGL ES 2.0 进行 GPGPU 编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 GPU 上进行一些图像处理,例如中值、模糊、亮度等.一般的想法是做类似 这个框架 来自 GPU Gems 1.

I am trying to do some image processing on the GPU, e.g. median, blur, brightness, etc. The general idea is to do something like this framework from GPU Gems 1.

我能够编写 GLSL 片段着色器来处理像素,因为我一直在效果设计器应用程序中尝试不同的东西.

I am able to write the GLSL fragment shader for processing the pixels as I've been trying out different things in an effect designer app.

但是我不确定我应该如何完成任务的另一部分.也就是说,我想以图像坐标处理图像,然后将结果输出到纹理.我知道 gl_FragCoords 变量.

I am not sure however how I should do the other part of the task. That is, I'd like to be working on the image in image coords and then outputting the result to a texture. I am aware of the gl_FragCoords variable.

据我了解,它是这样的:我需要设置一个视图(可能是正交视图?)和一个四边形,以便像素着色器将应用于图像中的每个像素一次这样它就会渲染到纹理或其他东西上.但是,考虑到深度可能会让我觉得有些尴尬……

As far as I understand it it goes like that: I need to set up a view (an orthographic one maybe?) and a quad in such a way so that the pixel shader would be applied once to each pixel in the image and so that it would be rendering to a texture or something. But how can I achieve that considering there's depth that may make things somewhat awkward to me...

如果有人能帮助我完成这个相当简单的任务,我将不胜感激,因为我对自己感到非常沮丧.

I'd be very grateful if anyone could help me with this rather simple task as I am really frustrated with myself.

看来我必须使用 FBO,得到一个像这样的:glBindFramebuffer(...)

It seems I'll have to use an FBO, getting one like this: glBindFramebuffer(...)

推荐答案

基本上,您需要四边形的 4 个顶点位置(作为 vec2)(具有角 (-1,-1) 和 (1,1))传递为一个顶点属性.

Basically, you need 4 vertex positions (as vec2) of a quad (with corners (-1,-1) and (1,1)) passed as a vertex attribute.

您实际上并不需要投影,因为着色器不需要任何投影.

You don't really need a projection, because the shader will not need any.

创建一个 FBO,绑定它并附加目标表面.不要忘记检查完整性状态.绑定着色器,设置输入纹理并绘制四边形.

Create an FBO, bind it and attach the target surface. Don't forget to check the completeness status. Bind the shader, set up input textures and draw the quad.

您的顶点着色器可能如下所示:

Your vertex shader may look like this:

#version 130
in vec2 at_pos;
out vec2 tc;
void main() {
    tc = (at_pos+vec2(1.0))*0.5;        //texture coordinates
    gl_Position = vec4(at_pos,0.0,1.0); //no projection needed
}

还有一个片段着色器:

#version 130
in vec2 tc;
uniform sampler2D unit_in;
void main() {
    vec4 v = texture2D(unit_in,tc);
    gl_FragColor = do_something();
}

这篇关于使用 OpenGL ES 2.0 进行 GPGPU 编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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