OpenGL ES 2.0顶点着色器纹理无法从FBO读取吗? [英] OpenGL ES 2.0 Vertex Shader Texture Reads not possible from FBO?

查看:252
本文介绍了OpenGL ES 2.0顶点着色器纹理无法从FBO读取吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究使用OpenGL ES 2.0的GPGPU项目.我有一个使用帧缓冲对象(FBO)作为目标的渲染管道,即每次渲染过程的结果都保存在附加到FBO的纹理中.到目前为止,这在使用片段着色器时有效.例如,我必须遵循以下渲染管道:

I'm currently working on a GPGPU project that uses OpenGL ES 2.0. I have a rendering pipeline that uses framebuffer objects (FBOs) as targets, i.e. the result of each rendering pass is saved in a texture which is attached to an FBO. So far, this works when using fragment shaders. For example I have to following rendering pipeline:

Preprocessing (downscaling, grayscale conversion)
-> Adaptive Thresholding Pass 1  -> Adapt. Thresh. Pass 2
-> Copy back to CPU

但是,我想通过在预处理步骤之后添加灰度直方图计算来扩展此管道.据我所知,在OpenGL ES 2.0中,这仅适用于顶点着色器中的纹理读取[1].我可以确认我的着色器在不同的程序中工作,其中输入是真实"图像,而不是附加到FBO的渲染纹理.因此,我认为如果来自FBO,则无法在顶点着色器中读取纹理数据.任何人都可以确认这个假设还是我错过了什么?我在实验中使用的是Nexus 10.

However, I wanted to extend this pipeline by adding a grayscale histogram calculation after the proprocessing step. With OpenGL ES 2.0 this only works with texture reads in the vertex shader, as far as I know [1]. I can confirm that my shaders work in a different program where the input is a "real" image, not a rendered texture that is attached to an FBO. Hence I think it is not possible to read texture data in a vertex shader if it comes from an FBO. Can anyone confirm this assumption or am I missing something? I'm using a Nexus 10 for my experiments.

[1]:它的工作原理基本上是从顶点着色器中的纹理读取每个像素值,然后从中计算直方图bin,然后通过使用alpha混合将其添加"到片段着色器中.

[1]: It basically works by reading each pixel value from the texture in the vertex shader, then calculating of the histogram bin from it and "adding" it in the fragment shader by using alpha blending.

推荐答案

在OpenGL ES 2.0中,顶点着色器中的纹理读取不是必需的元素,因此您会发现一些支持它们的制造商.实际上,有

Texture reads within a vertex shader are not a required element in OpenGL ES 2.0, so you'll find some manufacturers supporting them and some not. In fact, there was a weird situation where iOS supported it on some devices for one version of iOS, but not the next (and it's now officially supported in iOS 7). That might be the source of the inconsistency you see here.

要解决此问题,请

To work around this, I implemented a histogram calculation by instead feeding the colors from the FBO (or its attached texture) in as vertices and using a scattering operation similar to what you describe. This doesn't require a texture read of any kind in the vertex shader, but it does involve a round-trip from and to the GPU and potentially a lot of vertices. It works on all OpenGL ES 2.0 hardware, but it can be costly.

这篇关于OpenGL ES 2.0顶点着色器纹理无法从FBO读取吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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