step_03.glsl Diff#

step_02.glsl to step_03.glsl diff#
--- /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/latest/doc/tutorials/raycasting/step_02.glsl
+++ /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/latest/doc/tutorials/raycasting/step_03.glsl
@@ -1,11 +1,26 @@
+// x, y position of the light
+uniform vec2 lightPosition;
+// Size of light in pixels
+uniform float lightSize;
+
 void mainImage( out vec4 fragColor, in vec2 fragCoord )
 {
+    // Distance in pixels to the light
+    float distanceToLight = length(lightPosition - fragCoord);
+
+    // Normalize the fragment coordinate from (0.0, 0.0) to (1.0, 1.0)
     vec2 normalizedFragCoord = fragCoord/iResolution.xy;
-    vec4 inColor = texture(iChannel0, normalizedFragCoord);
-    if (inColor.a > 0.0)
-        // Set to a red color
-        fragColor = vec4(1.0, 0.0, 0.0, 1.0);
-    else
-        // Set to a blue color
-        fragColor = vec4(0.0, 0.0, 1.0, 1.0);
+
+    // Start our mixing variable at 1.0
+    float lightAmount = 1.0;
+
+    // Find out how much light we have based on the distance to our light
+    lightAmount *= 1.0 - smoothstep(0.0, lightSize, distanceToLight);
+
+    // We'll alternate our display between black and whatever is in channel 1
+    vec4 blackColor = vec4(0.0, 0.0, 0.0, 1.0);
+
+    // Our fragment color will be somewhere between black and channel 1
+    // dependent on the value of b.
+    fragColor = mix(blackColor, texture(iChannel1, normalizedFragCoord), lightAmount);
 }