Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get this "chroma-shift" effect with OpenGL shaders

I'd like to be able to produce this effect, to be specific, the color-crawl / color-shift.

color shift

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

I'm new to OpenGL and I'd like try this as a getting started exercise, however if there's a better way of doing this, ultimately I want to produce this effect.

FYI I'm using Cinder as my OpenGL framework.

I know this isn't much information, but I'm having trouble even finding out what this effect is really called, so I can't google it.

like image 582
ocodo Avatar asked Dec 28 '22 10:12

ocodo


1 Answers

I can't help you with the name of the effect, but I have an idea to produce this effect. My understanding is that each color component is shifted by some amount. A simple translation to the right of left of individual color components produced the black and white original image:

black and white image

Steps to get the image you want

  1. Get the source black and white image in a texture. If it's the result of other rendering, copy it to a texture.
  2. Render a full screen quad (or the size you want) with texture coordinates from (0,0) to (1,1) and with the texture attached.
  3. Apply a fragment shader that samples 3 times the input texture with a different shift in texture coordinates. e.g. -2 texels, 0 texel and +2 texel offsets. You can expirement and try more samples if you want and at different offsets.
  4. Combine those 3 samples by keeping only 1 color component of each.

Alternate if performance doesn't matter or shaders are not available

Don't use a pixel shader but instead on OpenGL blending with the ADD function. Render 3 times that same full screen quad with the texture attached and use the texture matrix to offset the lookups each time. Mask the output colormask differently for each pass and you get the same result: pass 1 => red, pass 2 => green, pass 3 => blue.

like image 111
bernie Avatar answered Jan 31 '23 07:01

bernie