Texture Image Processing on a GPU?

I create a specific scene in the texture, and then I need to process this image in the simplest way. The way I do it now is to read the texture using glReadPixels() and then process it on the CPU. This, however, is too slow, so I thought about porting processing to the GPU.

The simplest setting for this that I could think of is to show a simple white square that occupies the entire viewport in the orthogonal projector, and then writes the image processing bit as a fragment shader. This will allow many processing instances to work in parallel, as well as access any texture pixel that is required for processing.

Is this a viable course of action? Is this usually the case? Maybe the best way to do this?

+6
image-processing gpu opengl textures
source share
2 answers

Yes, this is the usual way of doing things.

  • Add something to the texture.
  • Draw a full-screen quad-core processor with a shader that reads this texture and performs some operations.

Simple effects (for example, shades of gray, color correction, etc.) can be performed by reading one pixel and outputting one pixel in the fragment shader. More complex operations (for example, swirling patterns) can be performed by reading one pixel from the offset location and outputting one pixel. Even more complex operations can be performed by reading a few pixels.

In some cases, several temporary textures will be required. For example. High radius blurring is often done as follows:

  • Paste texture.
  • Render to another (smaller) texture with a shader that calculates each output pixel as the average of several source pixels.
  • Use this smaller texture to render into another small texture with a shader that does the correct Gaussian blur or something like that.
  • ... repeat

In all of the above cases, each output pixel must be independent of other output pixels. It can use another additional input pixel.

An example of a processing operation that is poorly displayed is the Summed Area Table, where each output pixel depends on the input pixel and the value of the adjacent output pixel. However, this can be done on the GPU ( pdf example ).

+2
source share

Yes, this is a common way to process images. The color of the square does not matter much if you set the color for each pixel. Depending on your application, you may need to be careful about problems with selecting pixels (that is, to ensure that the pixel in the original texture is correctly selected, and not halfway between two pixels).

+2
source share

All Articles