如何执行2张通行证在OpenGL ES 2.0的模糊效果 [英] How to execute 2 passes for a blur effect in openGL ES 2.0

查看:374
本文介绍了如何执行2张通行证在OpenGL ES 2.0的模糊效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了创建一个模糊效果的理论说,创建2个顶点着色器,一个用于横向传球,第二个为纵向传球。再一个片段着色器的实际采样。

In order to create a blur effect the theory says to create 2 vertex shaders, one for the horizontal pass, and the second for the vertical pass. And then one fragment shader for actual sampling.

我的问题是,如何实际执行2顶点着色器?我需要渲染,然后通过glReadPixels找回像素,然后再次进行渲染?

My question is, how to actually to execute the 2 vertex shaders? Do I need to render, then get back the pixels via the glReadPixels and then to render again?

我的环境是机器人,OpenGL ES 2.0的

My environment is Android, OpenGL ES 2.0

感谢

推荐答案

您可以渲染的第一道关口到FBO,然后使第二个传递给默认的framebuffer使用时所产生的纹理。

You can render the first pass to an FBO, and then use the resulting texture when rendering the second pass to the default framebuffer.

如果您要模糊的形象与名称的质感 inputTexId ,以下是如何在code可以看看大纲。如果你使用C ++或Java,你没有指定。下面使用C ++绑定,但它看起来在Java中非常相似。

If the image you want to blur is in a texture with name inputTexId, the following is an outline of how the code could look. You didn't specify if you use C++ or Java. The following uses C++ bindings, but it will look very similar in Java.

有一次,在安装过程中,您创建一个FBO和将用于包含第一渲染过程结果的质地:

Once, during setup, you create an FBO and a texture that will be used to contain the result of the first rendering pass:

GLuint pass1TexId = 0;
glGenTextures(1, &pass1TexId);
glBindTexture(GL_TEXTURE_2D, pass1TexId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,
             GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);

GLuint fboId = 0;
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                       GL_TEXTURE_2D, pass1TexId, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

要应用模糊滤镜时,都会使用该FBO作为渲染目标为第一渲染过程,与你的原始图像输入:

Every time you want to apply the blur filter, you use this FBO as the render target for the first render pass, with your original image as input:

glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glBindTexture(GL_TEXTURE_2D, inputTexId);
// Set up shaders and state for first blur pass, and render.

然后,对于第二次通过,在渲染到默认帧缓冲区,并使用由所述第一通产生的纹理作为输入:

Then for the second pass, you render to the default framebuffer, and use the texture produced by the first pass as input:

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, pass1TexId);
// Set up shaders and state for second blur pass, and render.

这篇关于如何执行2张通行证在OpenGL ES 2.0的模糊效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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