Commits

Anonymous committed 2e5cd3b

working sphere rendering

  • Participants
  • Parent commits d769348

Comments (0)

Files changed (1)

   match shape with
     | Sphere s -> sphere_intersect s src dir
 
-let closest_intersection_excluded (source_shape:shape option) 
+let closest_intersection_excluded (source_isect:intersection option) 
     (shapes:shape list) (src:vector3) (dir:normal) : intersection option =
-  let safe_shapes = match source_shape with
-      None -> shapes
-    | Some s -> List.filter (fun x -> not (compare_shapes s x)) shapes
-  in
   let isects =
     let filter_isect acc s =
       match shape_intersect src dir s with
 	  None -> acc
-	| Some isect -> isect::acc
+	| Some isect -> (
+	    match source_isect with
+	      | None -> isect::acc
+	      | Some orig_isect -> (
+		  if (compare_shapes orig_isect.obj s) &&
+		    ((v3_l2distsq orig_isect.location isect.location)
+		     < 0.0001) then acc else isect::acc))
     in
-      List.fold_left filter_isect [] safe_shapes
+      List.fold_left filter_isect [] shapes
   in
   let choose_closest (prev:intersection*float)
 			(next:intersection) =
 let illuminated (isect:intersection) (shapes:shape list) (light:light) : bool =
   let dir = v3_norm (v3_sub light.light_center isect.location) in
   let closest = 
-    closest_intersection_excluded (Some isect.obj) shapes isect.location dir
+    closest_intersection_excluded (Some isect) shapes isect.location dir
   in
     match closest with
 	None -> true
   let light_dir = v3_norm (v3_sub light.light_center isect.location) in
   let light_norm = match light_dir with Normal n -> n in
   let isect_norm = match isect.normal with Normal n -> n in
-  let lambertian_coeff = v3_dot light_norm isect_norm in
+  let lambertian_coeff = max (v3_dot light_norm isect_norm) 0.0 in
   let light_in = rgb_coeff light.light_color lambertian_coeff in
     rgb_mix light_in (shape_color isect.obj)
 
     dump_bitmap out camera colors;
     close_out out
 
-let shapes = [Sphere {center=(2.0,0.0,0.0); radius=1.0; color=rgb_green;
+let shapes = [Sphere {center=(10.0,0.0,0.0); radius=1.0; color=rgb_green;
 		      sph_id=0}]
-let lights = [{light_center=(0.75,0.0,0.0); light_color=rgb_white}]
+let lights = [{light_center=(10.0,10.0,0.0); light_color=rgb_white}]
 let camera = {origin=v3_origin; out=v3_norm (1.0,0.0,0.0);
 	      up=v3_norm (0.0,1.0,0.0); width=240; height=240;
 	      xangle=2.4; yangle=2.4}