Soft shadows.
[raymarcher.git] / raymarch.lua
index 5bace40..594645e 100644 (file)
@@ -11,7 +11,7 @@ require "Textures"
 local T = Textures
 
 local eps = 0.01
-local max_dist2 = 20^2
+local max_dist2 = 30^2
 local bg_col = {0.1,0.1,0.1}
 
 local function calculate_normal(sdf, l)
@@ -28,7 +28,9 @@ local function march(start, location, ray_dir, sdf, count)
    
    local p = sdf(location)
    if p.dist < eps then
-      return p.texture(location, ray_dir, calculate_normal(sdf, location-(ray_dir*eps)), count)
+      return p.texture(location, ray_dir,
+                       calculate_normal(sdf, location-(ray_dir*eps)),
+                       count, sdf)
    else
       return march(start, location + ray_dir*p.dist,
                    ray_dir, sdf, count+1)
@@ -76,20 +78,32 @@ local function render(scene, width, height, filename)
 end
 
 
+local lights = {V.new{3,-3,1}}
 
 local scene = {
    sdf =
       O.union(
-         P.make_sphere(V.new{0,0,0}, 1,
-                       T.make_phong_texture({V.new{2,-3,1}},
-                          T.make_solid_pigment({0,1,0}),
-                          0.2, 0.7, 1.0, 100)),
-         P.make_plane(V.new{0,0,-3.0}, V.new{0,0,1},
-                      T.make_flat_texture(T.make_checkered_pigment({0,0,1}, {1,1,1})))),
+         O.diff(
+            O.diff(
+               O.diff(
+                  P.make_sphere(V.new{0,0,0}, 1,
+                                T.make_phong_texture(lights,
+                                                     T.make_solid_pigment({0,1,0}),
+                                                     0.2, 0.7, 1.0, 100)),
+                  P.make_sphere(V.new{0,0,0}, 0.8)),
+               P.make_pipe(V.new{0,0,0}, 0.5, V.new{0,1,0})),
+            P.make_pipe(V.new{0,0,0}, 0.5, V.new{1,0,0})),
+
+         P.make_plane(V.new{0,0,-1.0}, V.new{0,0,1},
+                      T.make_phong_texture(lights,
+                         T.make_checkered_pigment({0.5,0,0.2}, {1,1,1}),
+                         0.2, 1.0, 0, 1))),
+                      -- T.make_flat_texture(T.make_checkered_pigment({0,0,1}, {1,1,1})))),
                                
-   camera = {location = V.new{0,-5,0},
+   camera = {location = V.new{2,-5,1},
              point_at = V.new{0,0,0},
-             right = V.new{1,0,0},
+             right = V.x,
              fov = 1}}
 
+-- render(scene, 320, 200, "test.ppm")
 render(scene, 640, 480, "test.ppm")