#include "FlatShader.hxx"
#include "EyeLightShader.hxx"
#include "ReflectiveEyeLightShader.hxx"
+#include "PhongShader.hxx"
+#include "PointLight.hxx"
+#include "SpotLight.hxx"
#include "Scene.hxx"
-void RenderFrameFlat(const std::string& fileName)
+
+void RenderFramePhongPointLight(const std::string& fileName)
{
/* Scene definition */
-
Scene scene;
-
+
/* Flat shaders */
- FlatShader shd1(&scene, Vec3f(1,0,0)); // red surface
- FlatShader shd2(&scene, Vec3f(0,1,0)); // green surface
- FlatShader shd3(&scene, Vec3f(0,0,1)); // blue surface
- FlatShader shd4(&scene, Vec3f(1,1,0)); // yellow surface
- FlatShader shd5(&scene, Vec3f(0,1,1)); // cyan surface
- FlatShader shd6(&scene, Vec3f(1,1,1)); // white surface
+ PhongShader shd1(&scene, Vec3f(1,0,0),Vec3f(1,0,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // red surface
+ PhongShader shd2(&scene, Vec3f(0,1,0),Vec3f(0,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // green surface
+ PhongShader shd3(&scene, Vec3f(0,0,1),Vec3f(0,0,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // blue surface
+ PhongShader shd4(&scene, Vec3f(1,1,0),Vec3f(1,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // yellow surface
+ PhongShader shd5(&scene, Vec3f(0,1,1),Vec3f(0,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // cyan surface
+ PhongShader shd6(&scene, Vec3f(1,1,1),Vec3f(1,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // white surface
/* scene objects */
Sphere s1(Vec3f(-2,1.7,0), 2, &shd1);
Sphere s3(Vec3f(3,0.8,-2), 2, &shd3);
InfinitePlane p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4);
-
- Triangle t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5);
-
+
+ Triangle t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5);
+
/* add to scene */
scene.Add(&s1);
scene.Add(&s2);
scene.Add(&s3);
scene.Add(&p1);
scene.Add(&t1);
+
+ /* light sources */
+ Vec3f lightPosition1(4,5,6);
+ Vec3f lightPosition2(-3,5,4);
+ Vec3f pointLightSourceIntensity(50,50,50);
+
+ PointLight pointLight1(&scene, lightPosition1, pointLightSourceIntensity);
+ PointLight pointLight2(&scene, lightPosition2, pointLightSourceIntensity);
+
+ scene.Add(&pointLight1);
+ scene.Add(&pointLight2);
Image img(scene.camera()->resX(),scene.camera()->resY()); // image array
Ray ray; // primary ray
-
+
for(int y = 0; y < scene.camera()->resY(); y++)
{
- 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;
- }
+ 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;
+ }
}
img.WritePPM(fileName); // write final image
}
-
-void RenderFrameEyeLight(const std::string& fileName)
+void RenderFramePhongSpotLight(const std::string& fileName)
{
/* Scene definition */
-
Scene scene;
-
+
/* Flat shaders */
- EyeLightShader shd1(&scene, Vec3f(1,0,0)); // red surface
- EyeLightShader shd2(&scene, Vec3f(0,1,0)); // green surface
- EyeLightShader shd3(&scene, Vec3f(0,0,1)); // blue surface
- EyeLightShader shd4(&scene, Vec3f(1,1,0)); // yellow surface
- EyeLightShader shd5(&scene, Vec3f(0,1,1)); // cyan surface
- EyeLightShader shd6(&scene, Vec3f(1,1,1)); // white surface
+ PhongShader shd1(&scene, Vec3f(1,0,0),Vec3f(1,0,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // red surface
+ PhongShader shd2(&scene, Vec3f(0,1,0),Vec3f(0,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // green surface
+ PhongShader shd3(&scene, Vec3f(0,0,1),Vec3f(0,0,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // blue surface
+ PhongShader shd4(&scene, Vec3f(1,1,0),Vec3f(1,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // yellow surface
+ PhongShader shd5(&scene, Vec3f(0,1,1),Vec3f(0,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // cyan surface
+ PhongShader shd6(&scene, Vec3f(1,1,1),Vec3f(1,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // white surface
/* scene objects */
Sphere s1(Vec3f(-2,1.7,0), 2, &shd1);
Sphere s3(Vec3f(3,0.8,-2), 2, &shd3);
InfinitePlane p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4);
-
- Triangle t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5);
-
- /* add to scene */
- scene.Add(&s1);
- scene.Add(&s2);
- scene.Add(&s3);
- scene.Add(&p1);
- scene.Add(&t1);
-
- Image img(scene.camera()->resX(),scene.camera()->resY()); // image array
- Ray ray; // primary ray
-
- for(int y = 0; y < scene.camera()->resY(); y++)
- {
- 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
- }
- }
- img.WritePPM(fileName); // write final image
-}
-
-void RenderFrameReflectiveEyeLight(const std::string& fileName)
-{
- /* Scene definition */
-
- Scene scene;
-
- /* Flat shaders */
- ReflectiveEyeLightShader shd1(&scene, 1.0, Vec3f(1,0,0)); // red surface
- ReflectiveEyeLightShader shd2(&scene, 1.0, Vec3f(0.0,1.0,0.0)); // green surface
- ReflectiveEyeLightShader shd3(&scene, 1.0, Vec3f(0,0,1)); // blue surface
- ReflectiveEyeLightShader shd4(&scene, 0.8, Vec3f(1,1,0)); // yellow surface
- ReflectiveEyeLightShader shd5(&scene, 1.0, Vec3f(0,1,1)); // cyan surface
- ReflectiveEyeLightShader shd6(&scene, 0.0, Vec3f(1,1,1)); // white surface
-
- /* scene objects */
- Sphere s1(Vec3f(-2,1.7,0), 2, &shd1);
- Sphere s2(Vec3f(0.4,-1,1), 2.0, &shd2);
- Sphere s3(Vec3f(3,0.8,-2), 2, &shd3);
- InfinitePlane p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4);
-
-
- Triangle t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5);
-
+
+ Triangle t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5);
+
/* add to scene */
scene.Add(&s1);
scene.Add(&s2);
scene.Add(&s3);
scene.Add(&p1);
scene.Add(&t1);
+
+ /* light sources */
+ Vec3f lightPosition1(4,5,6);
+ Vec3f lightPosition2(-3,5,4);
+ Vec3f spotLightSourceIntensity(50,50,50);
+ Vec3f lightDir1 = lightPosition1 * (-1.0f);
+ lightDir1.normalize();
+ Vec3f lightDir2 = lightPosition2 *(-1.0f);
+ lightDir2.normalize();
+ float alpha_min = 15.0f;
+ float alpha_max = 30.0f;
+
+ SpotLight spotLight1(&scene, lightPosition1, lightDir1, spotLightSourceIntensity, alpha_min, alpha_max);
+ SpotLight spotLight2(&scene, lightPosition2, lightDir2, spotLightSourceIntensity, alpha_min, alpha_max);
+
+ scene.Add(&spotLight1);
+ scene.Add(&spotLight2);
Image img(scene.camera()->resX(),scene.camera()->resY()); // image array
Ray ray; // primary ray
-
+
for(int y = 0; y < scene.camera()->resY(); y++)
{
- for (int x = 0; x < scene.camera()->resX(); x++)
- {
- /* Initialize your ray here */ //int x = 319, y = 59;
- // 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;
- }
+ 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;
+ }
}
img.WritePPM(fileName); // write final image
}
-
-
#define RESX 640 // image x-resolution
#define RESY 480 // image y-resolution
int main(int, char**)
{
- //RenderFrameFlat("flatshaded.ppm");
- //RenderFrameEyeLight("eyelight.ppm");
- RenderFrameReflectiveEyeLight("reflective.ppm");
+ RenderFramePhongPointLight("phong_point.ppm");
+ RenderFramePhongSpotLight("phong_spot.ppm");
}