- for (int x = 0; x < scene.camera()->resX(); x++)
- {
-
- /* Initialize your ray here */
-
- scene.camera()->InitRay(x+0.5,y+0.5,ray); // initialize ray
-
- Vec3f col = scene.RayTrace(ray);
-
- img(x,y) = col; // store pixel color
- //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
- }
+ for (int x = 0; x < scene.camera()->resX(); x++)
+ {
+
+ /* Initialize your ray here */
+ // shoot four rays for antialiasing
+ scene.camera()->InitRay(x+0.5,y+0.5, ray); // initialize ray
+ Vec3f col1 = scene.RayTrace(ray);
+ scene.camera()->InitRay(x-0.5,y+0.5, ray); // initialize ray
+ Vec3f col2 = scene.RayTrace(ray);
+ scene.camera()->InitRay(x-0.5,y-0.5, ray); // initialize ray
+ Vec3f col3 = scene.RayTrace(ray);
+ scene.camera()->InitRay(x-0.5,y-0.5, ray); // initialize ray
+ Vec3f col4 = scene.RayTrace(ray);
+
+ img(x,y) = (col1 + col2 + col3 + col4) / 4.0; // store pixel color
+ //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
+ }