Skip to content

Instantly share code, notes, and snippets.

@attic-stuff
Created July 24, 2025 13:29
Show Gist options
  • Select an option

  • Save attic-stuff/4b5995e8677c2e9281062423cdccad82 to your computer and use it in GitHub Desktop.

Select an option

Save attic-stuff/4b5995e8677c2e9281062423cdccad82 to your computer and use it in GitHub Desktop.
chromatic aberration shader
//this is the vertex shader
attribute vec3 in_Position;
attribute vec4 in_Colour;
attribute vec2 in_Texture_Coordinate;
varying vec2 vertex_texture_coordinate;
void main() {
vec4 vertex_model_position = vec4(in_Position, 1.0);
vertex_texture_coordinate = in_Texture_Coordinate;
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * vertex_model_position;
}
//this is the fragment shader
varying vec2 vertex_texture_coordinate;
uniform vec2 texel_dimensions;
//x and y are vector components for direction -1 to 1, and z is the number of texels
uniform vec3 red_bleed;
uniform vec3 green_bleed;
uniform vec3 blue_bleed;
void main() {
float red = texture2D(gm_BaseTexture, vertex_texture_coordinate + ((red_bleed.xy * red_bleed.z) * texel_dimensions)).r;
float green = texture2D(gm_BaseTexture, vertex_texture_coordinate + ((green_bleed.xy * green_bleed.z) * texel_dimensions)).g;
float blue = texture2D(gm_BaseTexture, vertex_texture_coordinate + ((blue_bleed.xy * blue_bleed.z) * texel_dimensions)).b;
float alpha = texture2D(gm_BaseTexture, vertex_texture_coordinate).a;
gl_FragColor = vec4(red, green, blue, alpha);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment