Skip to content

Instantly share code, notes, and snippets.

@byungyoonc
Created July 2, 2015 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byungyoonc/78b0378fe90dacf521e4 to your computer and use it in GitHub Desktop.
Save byungyoonc/78b0378fe90dacf521e4 to your computer and use it in GitHub Desktop.
Simulates chromatic aberration to the input texture sampler2D tex.
#version 150
uniform sampler2D tex;
in vec2 f_texCoord;
out vec4 fColor;
vec3 refractiveIndex = vec3(1.03, 1.05, 1.08);
void main(void)
{
vec2 normalizedTexCoord = 2 * f_texCoord - 1; // [0, 1] -> [-1, 1]
vec3 texVec = vec3(normalizedTexCoord, 1.0);
vec3 normalVec = vec3(0.0, 0.0, -1.0);
vec3 redRefractionVec = refract(texVec, normalVec, refractiveIndex.r);
vec3 greenRefractionVec = refract(texVec, normalVec, refractiveIndex.g);
vec3 blueRefractionVec = refract(texVec, normalVec, refractiveIndex.b);
vec2 redTexCoord = ((redRefractionVec / redRefractionVec.z).xy + 1) / 2;
vec2 greenTexCoord = ((greenRefractionVec / greenRefractionVec.z).xy + 1) / 2;
vec2 blueTexCoord = ((blueRefractionVec / blueRefractionVec.z).xy + 1) / 2;
fColor = vec4
(
texture(tex, redTexCoord).r,
texture(tex, greenTexCoord).g,
texture(tex, blueTexCoord).b,
1.0
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment