Is it possible to get this effect "color shift" using OpenGL shaders

I would like to be able to produce this effect to be specific, color-bypass / color change.

color shift

Is this possible with OpenGL shaders, or do I need to use a different technique?

I am new to OpenGL and I would like to try this as a start to work, but if there is a better way to do this, in the end I want to create this effect.

FYI I use Cinder as my OpenGL framework.

I know that this is not a lot of information, but I am having problems even figuring out what this effect is really called, so I can’t use it.

+4
source share
3 answers

I cannot help you with the name of the effect, but I have an idea to produce this effect. I understand that each color component is shifted by a certain amount. A simple translation to the right of the individual color components produced a black and white source image:

black and white image

Steps to get the desired image.

  • Get the original black and white image in the texture. If this is the result of another rendering, copy it to the texture.
  • Display a full-screen square (or the size you want) with texture coordinates from (0,0) to (1,1) and with the texture attached.
  • Apply a fragment shader that produces 3 times the input texture with a different shift in the texture coordinates. for example -2 texels, 0 texels and +2 texels. You can expire and try more samples if you want, and at different offsets.
  • Combine these 3 patterns while retaining only one color component of each.

Alternative if performance doesn't matter or shaders are unavailable

Do not use a pixel shader, but instead on an OpenGL mix using the ADD function. Render 3 times the same full-screen quad-core processor with an attached texture and use the texture matrix to compensate for the search each time. Mask the color code of the output differently for each pass, and you will get the same result: pass 1 => red, pass 2 => green, pass 3 => blue.

+4
source

The effect you are looking for is called chromatic aberration, which you can see on Wikipedia. You have already received a solution, but I consider it my duty to be a physicist to give you a deeper understanding of what is happening and how the effect can be generalized.

Remember that each camera has a certain aperture, and light is usually described as waves. The interaction of the waves with the aperture is called diffraction, but when this happens mathematically, it is just a convolution of the wave function with the Fourier transform of the aperture function. Diffraction depends on the wavelength, so this creates a spatial shift depending on the color. Another effect is dispersion, i.e. Dependence on the refraction of the wavelength. Again, diffraction can be described by convolution.

Now convolutions can be connected by a chain, which gives a complete convolution kernel. In the case of a Gaussian smearing filter, the convolution core is a Gaussian distribution that is identical across all channels. But you may have different convolution kernels for each target channel. That @bernie actually offers kernel convolution boxes shifted by a few pixels in each channel.

This is a good GLSL convolution filtering tutorial. You can use for loops, not for unrolling loops. http://www.ozone3d.net/tutorials/image_filtering_p2.php

I suggest you use some Gaussian kernels, and the blurriness for red and blue will be stronger than green and, of course, slightly offset central points.

+4
source

GeexLab has a demo of Chromatic Abberation with a source in their shader library here .

+2
source

Source: https://habr.com/ru/post/1382632/


All Articles