Commit 20795120 authored by Taddeüs Kroes's avatar Taddeüs Kroes

- Implemented anti-aliasing,

parent 802ef1b0
...@@ -158,9 +158,9 @@ void ...@@ -158,9 +158,9 @@ void
ray_trace(void) ray_trace(void)
{ {
vec3 forward_vector, right_vector, up_vector; vec3 forward_vector, right_vector, up_vector;
int i, j; int i, j, k, l;
vec3 right_step, down_step; vec3 right_step, down_step;
float image_plane_width, image_plane_height; float image_plane_width, image_plane_height, diff[2] = {0.25, 0.75};
vec3 image_plane_topleft, image_plane_point; vec3 image_plane_topleft, image_plane_point;
vec3 ray_direction; vec3 ray_direction;
vec3 color; vec3 color;
...@@ -203,16 +203,41 @@ ray_trace(void) ...@@ -203,16 +203,41 @@ ray_trace(void)
{ {
for (i = 0; i < framebuffer_width; i++) for (i = 0; i < framebuffer_width; i++)
{ {
// Compute corresponding point on image plane if( do_antialiasing)
image_plane_point = v3_add(image_plane_topleft, v3_multiply(right_step, i+0.5)); {
image_plane_point = v3_add(image_plane_point, v3_multiply(down_step, j+0.5)); color.x = color.y = color.z = 0;
// Compute direction for shooting the ray for( k = 0; k < 2; k++ )
ray_direction = v3_subtract(image_plane_point, scene_camera_position); {
for( l = 0; l < 2; l++ )
// Determine ray color {
color = ray_color(0, scene_camera_position, ray_direction); // Compute corresponding point on image plane
image_plane_point = v3_add(image_plane_topleft, v3_multiply(right_step, i+diff[k]));
image_plane_point = v3_add(image_plane_point, v3_multiply(down_step, j+diff[l]));
// Compute direction for shooting the ray
ray_direction = v3_subtract(image_plane_point, scene_camera_position);
// Determine ray color
color = v3_add(color, ray_color(0, scene_camera_position, ray_direction));
}
}
color = v3_multiply(color, 0.25);
}
else
{
// Compute corresponding point on image plane
image_plane_point = v3_add(image_plane_topleft, v3_multiply(right_step, i+0.5));
image_plane_point = v3_add(image_plane_point, v3_multiply(down_step, j+0.5));
// Compute direction for shooting the ray
ray_direction = v3_subtract(image_plane_point, scene_camera_position);
// Determine ray color
color = ray_color(0, scene_camera_position, ray_direction);
}
// Output pixel color // Output pixel color
put_pixel(i, j, color.x, color.y, color.z); put_pixel(i, j, color.x, color.y, color.z);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment