16
Jan
08

Swizzling

My simplest effect yet. Simply mixes from original image to two different channel-shifted variants, then back to the original image.

The key is the ‘.’ swizzle operator, which allows the Red Blue, Green and Alpha channels of the image to be rearranged. Also notice that the Mix variable goes from 0.0 to just less than 3.0, and I use the fract function to extract the part of the number after the decimal point, and use this to mix between 2 variants, as well as to swap the start and end of the mix operation with values above 1.0 and 2.0.

Simple, but cool.

/*Inputs:
Image: input image
Mix: mix between original and channel-shifted variants. Range 0.0 > 2.999
*/

kernel vec4 swizzler(sampler Image, float Mix)
{
vec4 pix = unpremultiply(sample(Image, samplerCoord(Image)));
vec4 outPix = (Mix <= 1.0) ? mix(pix.rgba, pix.brga, fract(Mix)) : (Mix <= 2.0) ? mix(pix.brga, pix.gbra, fract(Mix)) : mix(pix.gbra, pix.rgba, fract(Mix)); return premultiply(outPix); }[/code]

Advertisements

0 Responses to “Swizzling”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Twitter

January 2008
M T W T F S S
« Dec   Feb »
 123456
78910111213
14151617181920
21222324252627
28293031  

Links

Blog Stats

  • 473,930 hits

%d bloggers like this: