Step 3 GLSL#

../../_images/step_03.png
step_03.glsl#
 1// x, y position of the light
 2uniform vec2 lightPosition;
 3// Size of light in pixels
 4uniform float lightSize;
 5
 6void mainImage( out vec4 fragColor, in vec2 fragCoord )
 7{
 8    // Distance in pixels to the light
 9    float distanceToLight = length(lightPosition - fragCoord);
10
11    // Normalize the fragment coordinate from (0.0, 0.0) to (1.0, 1.0)
12    vec2 normalizedFragCoord = fragCoord/iResolution.xy;
13
14    // Start our mixing variable at 1.0
15    float lightAmount = 1.0;
16
17    // Find out how much light we have based on the distance to our light
18    lightAmount *= 1.0 - smoothstep(0.0, lightSize, distanceToLight);
19
20    // We'll alternate our display between black and whatever is in channel 1
21    vec4 blackColor = vec4(0.0, 0.0, 0.0, 1.0);
22
23    // Our fragment color will be somewhere between black and channel 1
24    // dependent on the value of b.
25    fragColor = mix(blackColor, texture(iChannel1, normalizedFragCoord), lightAmount);
26}