step_05.glsl Diff#

step_04.glsl to step_05.glsl diff#
--- /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/stable/doc/tutorials/raycasting/step_04.glsl
+++ /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/stable/doc/tutorials/raycasting/step_05.glsl
@@ -1,3 +1,5 @@
+#define N 500
+
 // x, y position of the light
 uniform vec2 lightPosition;
 // Size of light in pixels
@@ -19,12 +21,22 @@
 
     // Normalize the fragment coordinate from (0.0, 0.0) to (1.0, 1.0)
     vec2 normalizedFragCoord = fragCoord/iResolution.xy;
+    vec2 normalizedLightCoord = lightPosition.xy/iResolution.xy;
 
     // Start our mixing variable at 1.0
     float lightAmount = 1.0;
-
-    float shadowAmount = terrain(normalizedFragCoord);
-    lightAmount *= shadowAmount;
+    for(float i = 0.0; i < N; i++)
+    {
+        // A 0.0 - 1.0 ratio between where our current pixel is, and where the light is
+        float t = i / N;
+        // Grab a coordinate between where we are and the light
+        vec2 samplePoint = mix(normalizedFragCoord, normalizedLightCoord, t);
+        // Is there something there? If so, we'll assume we are in shadow
+	    float shadowAmount = terrain(samplePoint);
+        // Multiply the light amount.
+        // (Multiply in case we want to upgrade to soft shadows)
+        lightAmount *= shadowAmount;
+    }
 
     // Find out how much light we have based on the distance to our light
     lightAmount *= 1.0 - smoothstep(0.0, lightSize, distanceToLight);