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

- Implemented anti-aliasing,

parent 802ef1b0
......@@ -158,9 +158,9 @@ void
ray_trace(void)
{
vec3 forward_vector, right_vector, up_vector;
int i, j;
int i, j, k, l;
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 ray_direction;
vec3 color;
......@@ -202,6 +202,30 @@ ray_trace(void)
for (j = 0; j < framebuffer_height; j++)
{
for (i = 0; i < framebuffer_width; i++)
{
if( do_antialiasing)
{
color.x = color.y = color.z = 0;
for( k = 0; k < 2; k++ )
{
for( l = 0; l < 2; l++ )
{
// 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));
......@@ -212,6 +236,7 @@ ray_trace(void)
// Determine ray color
color = ray_color(0, scene_camera_position, ray_direction);
}
// Output pixel color
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