Finally - fixed ray origin so that phong shading works correctly!

This commit is contained in:
Zachary D. Rowitsch
2020-08-14 23:51:46 -04:00
parent 18cc1c21d9
commit f954f7cd16
3 changed files with 16 additions and 9 deletions

@ -1,14 +1,21 @@
# raytracer-c
## vector physics simulation
Current executables (and sample output) are:
## main/parabola
simple demonstration of tuple implementation, shooting a projectile with gravity & wind vectors...
![](images/parabola.png)
## first ray tracing
## main/sphere_shadow
Matrix implementation allow us to cast rays...and intersect them with a sphere
![](images/sphere_shadow.png)
## first shading
## main/phone_render_sphere
Not quite right yet...
Phone shading!
![](images/phong_render_sphere.png)
![](images/phong_render_sphere2.png)

Binary file not shown.

After

(image error) Size: 33 KiB

@ -37,9 +37,9 @@ int main(void) {
RAY_Ray r;
TUPLES_init_point(&position, world_x, world_y, wall_z);
TUPLES_subtract(&v_tmp, ray_origin, &position);
TUPLES_subtract(&v_tmp, &position, ray_origin);
TUPLES_normalize(&v_tmp);
RAY_init_from_tuples(&r, &position, &v_tmp);
RAY_init_from_tuples(&r, ray_origin, &v_tmp);
RAY_Intersections* xs = SPHERE_intersect(sphere, &r);
RAY_Xs* hit = RAY_hit(xs);
@ -57,7 +57,7 @@ int main(void) {
TUPLES_copy(&eyev, &r.direction);
TUPLES_negate(&eyev);
MATERIAL_lighting(&color, ((SPHERE_Sphere*)hit->object)->material, light, &point_of_intersection, &eyev, &normal);
MATERIAL_lighting(&color, SPHERE_get_material((SPHERE_Sphere*)hit->object), light, &point_of_intersection, &eyev, &normal);
CANVAS_write_pixel(canvas, x, y, &color);
}
RAY_delete_intersections(xs);