GPU上的纹理图像处理? [英] Texture Image processing on the GPU?

查看:805
本文介绍了GPU上的纹理图像处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将某个场景渲染到纹理中,然后我需要以一种简单的方式处理该图像。我现在如何做这个是使用 glReadPixels()读取纹理,然后在CPU上处理它。然而这太慢了,所以我在考虑将处理转移到GPU。

I'm rendering a certain scene into a texture and then I need to process that image in some simple way. How I'm doing this now is to read the texture using glReadPixels() and then process it on the CPU. This is however too slow so I was thinking about moving the processing to the GPU.

我能想到的最简单的设置是显示一个简单的白色四边形,它在正交投影中占据整个视口,然后将图像处理位写为片段着色器。这将允许许多处理实例并行运行,以及访问处理所需纹理的任何像素。

The simplest setup to do this I could think of is to display a simple white quad that takes up the entire viewport in an orthogonal projection and then write the image processing bit as a fragment shader. This will allow many instances of the processing to run in parallel as well as to access any pixel of the texture it requires for the processing.

这是一个可行的行动方案吗? ?以这种方式做事是很常见的吗?
有没有更好的方法呢?

Is this a viable course of action? is it common to do things this way? Is there maybe a better way to do it?

推荐答案

是的,这是进行图像处理的常用方法。如果你要为每个像素设置颜色,四边形的颜色并不重要。根据您的应用,您可能需要注意像素采样问题(即确保您从源纹理上的正确像素进行采样,而不是在两个像素之间的中间进行采样)。

Yes, it's the normal way to do image processing. The color of the quad doesn't really matter if you'll be setting the color for every pixel. Depending on your application, you might need to careful about pixel sampling issues (i.e. ensuring that you sample from exactly the correct pixel on the source texture, rather than halfway between two pixels).

这篇关于GPU上的纹理图像处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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