Radial Chromatic Aberration

Chromatic aberration shader that distorts from the center of the image outwards.

uniform sampler2D distance_curve; should be a curve texture, it indicates the intensity of the aberration as a function of the distance from the center of the image.

uniform float intensity = 1.0; indicates the overall intensity of the effect, if it’s zero, no matter distance curve, no aberration will be applied.

This code distorts the image by streching it outwards from the center. A way to look a it is that the shifted color shifted channels, red and blue, are those closest and furthest from the center while the green channel, the one that’s ‘unshifted’ is displaced half way to sit between the color shifted channels.
If this outward distortion is undesireable, replace the code under //Channel Shifting with the following code which distorts one channel inwards, one is kept still and one is shifted outwards.

	float green_channel = texture(TEXTURE, UV).g;
	float red_channel = texture(TEXTURE, UV - centered_uv * curve_distance_intensity * SCREEN_PIXEL_SIZE * intensity).r;
	float blue_channel = texture(TEXTURE, UV - centered_uv * curve_distance_intensity * SCREEN_PIXEL_SIZE * -intensity).b;
	COLOR.rgb = vec3(red_channel,green_channel,blue_channel);

Feel free to add any questions/correction on the comments! I’m not too experienced with shaders, any insight is appreciated 🙂

Shader code
shader_type canvas_item;

uniform sampler2D distance_curve;
uniform float intensity = 1.0;


void fragment() {
	vec2 centered_uv = UV - vec2(0.5,0.5);
	//centered_uv.x = pow(centered_uv.x, 3);
	//centered_uv.y = pow(centered_uv.y, 3);

	// Since offsetting the channels by the UVs will create no-information areas in the edges
	// all the color shifting will be done outwards rather than doing part of it inwards
	// thus, the shifted channels will be the one kept still and the one shifted the most
	float distance_from_center = abs(distance(vec2(0.0,0.0),centered_uv));
	float curve_distance_intensity = texture(distance_curve, vec2(distance_from_center)).r;

	// Channel Shifting
	float blue_channel = texture(TEXTURE, UV).b;
	float red_channel = texture(TEXTURE, UV - centered_uv * curve_distance_intensity * SCREEN_PIXEL_SIZE * intensity).r;
	float green_channel = texture(TEXTURE, UV - centered_uv * curve_distance_intensity * SCREEN_PIXEL_SIZE * intensity / 2.0).g;
	COLOR.rgb = vec3(red_channel,green_channel,blue_channel);
}
Live Preview
Tags
chromatic aberration, distortion, post process
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
bonejackal
8 months ago

wait so i added this to a ColorRect node that stretches over the screen, added the CurveTexture and a Curve to that object from values 0.0 to 1.0, and it only appears white no matter the intensity. what’s happening?

Yuop
7 months ago

I don’t know how to use it

Alex
Alex
6 months ago

Im a little confused on where the shader code goes. Do we put it on the camera a color rect?