252ec18cb5a23d0988a1f78c1a17205bf67078e0
5 #include "Triangle.hxx"
6 #include "InfinitePlane.hxx"
9 #include "PerspectiveCamera.hxx"
10 #include "FlatShader.hxx"
11 #include "EyeLightShader.hxx"
12 #include "ReflectiveEyeLightShader.hxx"
15 void RenderFrameFlat(const std::string
& fileName
)
17 /* Scene definition */
22 FlatShader
shd1(&scene
, Vec3f(1,0,0)); // red surface
23 FlatShader
shd2(&scene
, Vec3f(0,1,0)); // green surface
24 FlatShader
shd3(&scene
, Vec3f(0,0,1)); // blue surface
25 FlatShader
shd4(&scene
, Vec3f(1,1,0)); // yellow surface
26 FlatShader
shd5(&scene
, Vec3f(0,1,1)); // cyan surface
27 FlatShader
shd6(&scene
, Vec3f(1,1,1)); // white surface
30 Sphere
s1(Vec3f(-2,1.7,0), 2, &shd1
);
31 Sphere
s2(Vec3f(1,-1,1), 2.2, &shd2
);
32 Sphere
s3(Vec3f(3,0.8,-2), 2, &shd3
);
33 InfinitePlane
p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4
);
36 Triangle
t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5
);
46 Image
img(scene
.camera()->resX(),scene
.camera()->resY()); // image array
47 Ray ray
; // primary ray
49 for(int y
= 0; y
< scene
.camera()->resY(); y
++)
51 for (int x
= 0; x
< scene
.camera()->resX(); x
++)
54 /* Initialize your ray here */
55 // shoot four rays for antialiasing
56 scene
.camera()->InitRay(x
+0.5,y
+0.5, ray
); // initialize ray
57 Vec3f col1
= scene
.RayTrace(ray
);
58 scene
.camera()->InitRay(x
-0.5,y
+0.5, ray
); // initialize ray
59 Vec3f col2
= scene
.RayTrace(ray
);
60 scene
.camera()->InitRay(x
-0.5,y
-0.5, ray
); // initialize ray
61 Vec3f col3
= scene
.RayTrace(ray
);
62 scene
.camera()->InitRay(x
-0.5,y
-0.5, ray
); // initialize ray
63 Vec3f col4
= scene
.RayTrace(ray
);
65 img(x
,y
) = (col1
+ col2
+ col3
+ col4
) / 4.0; // store pixel color
66 //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
69 img
.WritePPM(fileName
); // write final image
73 void RenderFrameEyeLight(const std::string
& fileName
)
75 /* Scene definition */
80 EyeLightShader
shd1(&scene
, Vec3f(1,0,0)); // red surface
81 EyeLightShader
shd2(&scene
, Vec3f(0,1,0)); // green surface
82 EyeLightShader
shd3(&scene
, Vec3f(0,0,1)); // blue surface
83 EyeLightShader
shd4(&scene
, Vec3f(1,1,0)); // yellow surface
84 EyeLightShader
shd5(&scene
, Vec3f(0,1,1)); // cyan surface
85 EyeLightShader
shd6(&scene
, Vec3f(1,1,1)); // white surface
88 Sphere
s1(Vec3f(-2,1.7,0), 2, &shd1
);
89 Sphere
s2(Vec3f(1,-1,1), 2.2, &shd2
);
90 Sphere
s3(Vec3f(3,0.8,-2), 2, &shd3
);
91 InfinitePlane
p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4
);
94 Triangle
t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5
);
103 Image
img(scene
.camera()->resX(),scene
.camera()->resY()); // image array
104 Ray ray
; // primary ray
106 for(int y
= 0; y
< scene
.camera()->resY(); y
++)
108 for (int x
= 0; x
< scene
.camera()->resX(); x
++)
111 /* Initialize your ray here */
112 // shoot four rays for antialiasing
113 scene
.camera()->InitRay(x
+0.5,y
+0.5, ray
); // initialize ray
114 Vec3f col1
= scene
.RayTrace(ray
);
115 scene
.camera()->InitRay(x
-0.5,y
+0.5, ray
); // initialize ray
116 Vec3f col2
= scene
.RayTrace(ray
);
117 scene
.camera()->InitRay(x
-0.5,y
-0.5, ray
); // initialize ray
118 Vec3f col3
= scene
.RayTrace(ray
);
119 scene
.camera()->InitRay(x
-0.5,y
-0.5, ray
); // initialize ray
120 Vec3f col4
= scene
.RayTrace(ray
);
122 img(x
,y
) = (col1
+ col2
+ col3
+ col4
) / 4.0; // store pixel color
125 img
.WritePPM(fileName
); // write final image
128 void RenderFrameReflectiveEyeLight(const std::string
& fileName
)
130 /* Scene definition */
135 ReflectiveEyeLightShader
shd1(&scene
, 1.0, Vec3f(1,0,0)); // red surface
136 ReflectiveEyeLightShader
shd2(&scene
, 1.0, Vec3f(0.0,1.0,0.0)); // green surface
137 ReflectiveEyeLightShader
shd3(&scene
, 1.0, Vec3f(0,0,1)); // blue surface
138 ReflectiveEyeLightShader
shd4(&scene
, 0.8, Vec3f(1,1,0)); // yellow surface
139 ReflectiveEyeLightShader
shd5(&scene
, 1.0, Vec3f(0,1,1)); // cyan surface
140 ReflectiveEyeLightShader
shd6(&scene
, 0.0, Vec3f(1,1,1)); // white surface
143 Sphere
s1(Vec3f(-2,1.7,0), 2, &shd1
);
144 Sphere
s2(Vec3f(0.4,-1,1), 2.0, &shd2
);
145 Sphere
s3(Vec3f(3,0.8,-2), 2, &shd3
);
146 InfinitePlane
p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4
);
149 Triangle
t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5
);
159 Image
img(scene
.camera()->resX(),scene
.camera()->resY()); // image array
160 Ray ray
; // primary ray
162 for(int y
= 0; y
< scene
.camera()->resY(); y
++)
164 for (int x
= 0; x
< scene
.camera()->resX(); x
++)
166 /* Initialize your ray here */
167 // shoot four rays for antialiasing
168 scene
.camera()->InitRay(x
+0.5,y
+0.5, ray
); // initialize ray
169 Vec3f col1
= scene
.RayTrace(ray
);
170 scene
.camera()->InitRay(x
-0.5,y
+0.5, ray
); // initialize ray
171 Vec3f col2
= scene
.RayTrace(ray
);
172 scene
.camera()->InitRay(x
-0.5,y
-0.5, ray
); // initialize ray
173 Vec3f col3
= scene
.RayTrace(ray
);
174 scene
.camera()->InitRay(x
-0.5,y
-0.5, ray
); // initialize ray
175 Vec3f col4
= scene
.RayTrace(ray
);
177 img(x
,y
) = (col1
+ col2
+ col3
+ col4
) / 4.0; // store pixel color
178 //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
181 img
.WritePPM(fileName
); // write final image
186 #define RESX 640 // image x-resolution
187 #define RESY 480 // image y-resolution
189 int main(int, char**)
191 RenderFrameFlat("flatshaded.ppm");
192 RenderFrameEyeLight("eyelight.ppm");
193 RenderFrameReflectiveEyeLight("reflective.ppm");
This page took 0.059077 seconds and 3 git commands to generate.