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

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

问题描述

我正在尝试在GPU上进行一些图像处理,例如中位数,模糊,亮度等。一般的想法是做一些像这个框架来自GPU宝石1.



我能够编写用于处理像素的GLSL片段着色器,因为我在效果设计器应用程序中尝试了不同的东西。 / p>

然而,我不确定如何完成任务的其他部分。也就是说,我想在图像坐标中处理图像,然后将结果输出到纹理。我知道 gl_FragCoords 变量。



据我所知,它是这样的:我需要以这样的方式设置一个视图(一个正交的可能?)和一个四边形,这样像素着色器将被应用到图像中的每个像素一次,以便它可以渲染到纹理或其他东西。但是我怎么能实现这一目标,考虑到深度可能会让我感觉有些尴尬......



如果有人能帮我这么简单,我会非常感激任务,因为我对自己感到非常沮丧。



更新:



我似乎必须使用FBO,得到这样一个: glBindFramebuffer(...)

解决方案

基本上,你需要4个顶点位置(如vec2)(四角(-1,-1)和(1,1))作为顶点属性传递。



你真的不需要投影,因为着色器不需要任何投影。



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



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

  #version 130 
in vec2 at_pos;
out vec2 tc;
void main(){
tc =(at_pos + vec2(1.0))* 0.5; //纹理坐标
gl_Position = vec4(at_pos,0.0,1.0); //无投影
}

片段着色器:

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


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.

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.

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.

UPDATE:

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

解决方案

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.

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
}

And a fragment shader:

#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天全站免登陆