1- #version 330
2-
3- // The texture holding the scene pixels
4- uniform sampler2D tex;
5-
6- // Read "assets/shaders/fullscreen.vert" to know what "tex_coord" holds;
7- in vec2 tex_coord;
8- out vec4 frag_color;
9-
10- // How far (in the texture space) is the distance (on the x-axis) between
11- // the pixels from which the red/green (or green/blue) channels are sampled
12- #define STRENGTH 0.005
13-
14- // Chromatic aberration mimics some old cameras where the lens disperses light
15- // differently based on its wavelength. In this shader, we will implement a
16- // cheap version of that effect
17-
18- void main(){
19- // TODO: Modify this shader to apply chromatic abberation
20- // To apply this effect, we only read the green channel from the correct pixel (as defined by tex_coord)
21- // To get the red channel, we move by amount STRENGTH to the left then sample another pixel from which we take the red channel
22- // To get the blue channel, we move by amount STRENGTH to the right then sample another pixel from which we take the blue channel
23- frag_color.r = texture(tex, tex_coord - vec2 (STRENGTH, 0.0 )).r;
24- frag_color.ga = texture(tex, tex_coord).ga;
25- frag_color.b = texture(tex, tex_coord + vec2 (STRENGTH, 0.0 )).b;
26- }
1+ #version 330
2+
3+ // The texture holding the scene pixels
4+ uniform sampler2D tex;
5+
6+ // Read "assets/shaders/fullscreen.vert" to know what "tex_coord" holds;
7+ in vec2 tex_coord;
8+ out vec4 frag_color;
9+
10+ // How far (in the texture space) is the distance (on the x-axis) between
11+ // the pixels from which the red/green (or green/blue) channels are sampled
12+ #define STRENGTH 0.005
13+
14+ // Chromatic aberration mimics some old cameras where the lens disperses light
15+ // differently based on its wavelength. In this shader, we will implement a
16+ // cheap version of that effect
17+
18+ void main() {
19+ // red = move by STRENGTH to the left, then sample the red channel
20+ // green = sample the green channel from the correct pixel
21+ // blue = move by STRENGTH to the right, then sample the blue channel
22+ frag_color.r = texture(tex, tex_coord - vec2 (STRENGTH, 0.0 )).r;
23+ frag_color.ga = texture(tex, tex_coord).ga;
24+ frag_color.b = texture(tex, tex_coord + vec2 (STRENGTH, 0.0 )).b;
25+ }
0 commit comments