5 #include "Triangle.hxx"
6 #include "InfinitePlane.hxx"
9 #include "PerspectiveCamera.hxx"
10 #include "FlatShader.hxx"
11 #include "EyeLightShader.hxx"
12 #include "ReflectiveEyeLightShader.hxx"
13 #include "PhongShader.hxx"
14 #include "PointLight.hxx"
15 #include "SpotLight.hxx"
19 void RenderFramePhongPointLight(const std::string
& fileName
)
21 /* Scene definition */
25 PhongShader
shd1(&scene
, Vec3f(1,0,0),Vec3f(1,0,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // red surface
26 PhongShader
shd2(&scene
, Vec3f(0,1,0),Vec3f(0,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // green surface
27 PhongShader
shd3(&scene
, Vec3f(0,0,1),Vec3f(0,0,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // blue surface
28 PhongShader
shd4(&scene
, Vec3f(1,1,0),Vec3f(1,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // yellow surface
29 PhongShader
shd5(&scene
, Vec3f(0,1,1),Vec3f(0,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // cyan surface
30 PhongShader
shd6(&scene
, Vec3f(1,1,1),Vec3f(1,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // white surface
33 Sphere
s1(Vec3f(-2,1.7,0), 2, &shd1
);
34 Sphere
s2(Vec3f(1,-1,1), 2.2, &shd2
);
35 Sphere
s3(Vec3f(3,0.8,-2), 2, &shd3
);
36 InfinitePlane
p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4
);
39 Triangle
t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5
);
49 Vec3f
lightPosition1(4,5,6);
50 Vec3f
lightPosition2(-3,5,4);
51 Vec3f
pointLightSourceIntensity(50,50,50);
53 PointLight
pointLight1(&scene
, lightPosition1
, pointLightSourceIntensity
);
54 PointLight
pointLight2(&scene
, lightPosition2
, pointLightSourceIntensity
);
56 scene
.Add(&pointLight1
);
57 scene
.Add(&pointLight2
);
60 Image
img(scene
.camera()->resX(),scene
.camera()->resY()); // image array
61 Ray ray
; // primary ray
63 for(int y
= 0; y
< scene
.camera()->resY(); y
++)
65 for (int x
= 0; x
< scene
.camera()->resX(); x
++)
68 /* Initialize your ray here */
70 scene
.camera()->InitRay(x
+0.5,y
+0.5,ray
); // initialize ray
72 Vec3f col
= scene
.RayTrace(ray
);
74 img(x
,y
) = col
; // store pixel color
75 //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
78 img
.WritePPM(fileName
); // write final image
81 void RenderFramePhongSpotLight(const std::string
& fileName
)
83 /* Scene definition */
87 PhongShader
shd1(&scene
, Vec3f(1,0,0),Vec3f(1,0,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // red surface
88 PhongShader
shd2(&scene
, Vec3f(0,1,0),Vec3f(0,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // green surface
89 PhongShader
shd3(&scene
, Vec3f(0,0,1),Vec3f(0,0,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // blue surface
90 PhongShader
shd4(&scene
, Vec3f(1,1,0),Vec3f(1,1,0),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // yellow surface
91 PhongShader
shd5(&scene
, Vec3f(0,1,1),Vec3f(0,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // cyan surface
92 PhongShader
shd6(&scene
, Vec3f(1,1,1),Vec3f(1,1,1),Vec3f(1,1,1), 0.1, 0.5, 0.5, 40); // white surface
95 Sphere
s1(Vec3f(-2,1.7,0), 2, &shd1
);
96 Sphere
s2(Vec3f(1,-1,1), 2.2, &shd2
);
97 Sphere
s3(Vec3f(3,0.8,-2), 2, &shd3
);
98 InfinitePlane
p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4
);
101 Triangle
t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5
);
111 Vec3f
lightPosition1(4,5,6);
112 Vec3f
lightPosition2(-3,5,4);
113 Vec3f
spotLightSourceIntensity(50,50,50);
114 Vec3f lightDir1
= lightPosition1
* (-1.0f
);
115 lightDir1
.normalize();
116 Vec3f lightDir2
= lightPosition2
*(-1.0f
);
117 lightDir2
.normalize();
118 float alpha_min
= 15.0f
;
119 float alpha_max
= 30.0f
;
121 SpotLight
spotLight1(&scene
, lightPosition1
, lightDir1
, spotLightSourceIntensity
, alpha_min
, alpha_max
);
122 SpotLight
spotLight2(&scene
, lightPosition2
, lightDir2
, spotLightSourceIntensity
, alpha_min
, alpha_max
);
124 scene
.Add(&spotLight1
);
125 scene
.Add(&spotLight2
);
128 Image
img(scene
.camera()->resX(),scene
.camera()->resY()); // image array
129 Ray ray
; // primary ray
131 for(int y
= 0; y
< scene
.camera()->resY(); y
++)
133 for (int x
= 0; x
< scene
.camera()->resX(); x
++)
136 /* Initialize your ray here */
138 scene
.camera()->InitRay(x
+0.5,y
+0.5,ray
); // initialize ray
140 Vec3f col
= scene
.RayTrace(ray
);
142 img(x
,y
) = col
; // store pixel color
143 //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
146 img
.WritePPM(fileName
); // write final image
149 #define RESX 640 // image x-resolution
150 #define RESY 480 // image y-resolution
152 int main(int, char**)
154 RenderFramePhongPointLight("phong_point.ppm");
155 RenderFramePhongSpotLight("phong_spot.ppm");