# HG changeset patch
# User Jeremy Hoon
# Date 1274300174 14400
# Node ID 2e5cd3b979c55aca2a410b56aa8ad9613fafa4b1
# Parent d7693486facc5b597ab30c496db1866e62eb1fa6
working sphere rendering
diff --git a/rays.ml b/rays.ml
--- a/rays.ml
+++ b/rays.ml
@@ -96,19 +96,21 @@
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) =
@@ -159,7 +161,7 @@
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
@@ -172,7 +174,7 @@
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)
@@ -255,9 +257,9 @@
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}