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 */
56 scene
.camera()->InitRay(x
+0.5,y
+0.5,ray
); // initialize ray
58 Vec3f col
= scene
.RayTrace(ray
);
60 img(x
,y
) = col
; // store pixel color
61 //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
64 img
.WritePPM(fileName
); // write final image
68 void RenderFrameEyeLight(const std::string
& fileName
)
70 /* Scene definition */
75 EyeLightShader
shd1(&scene
, Vec3f(1,0,0)); // red surface
76 EyeLightShader
shd2(&scene
, Vec3f(0,1,0)); // green surface
77 EyeLightShader
shd3(&scene
, Vec3f(0,0,1)); // blue surface
78 EyeLightShader
shd4(&scene
, Vec3f(1,1,0)); // yellow surface
79 EyeLightShader
shd5(&scene
, Vec3f(0,1,1)); // cyan surface
80 EyeLightShader
shd6(&scene
, Vec3f(1,1,1)); // white surface
83 Sphere
s1(Vec3f(-2,1.7,0), 2, &shd1
);
84 Sphere
s2(Vec3f(1,-1,1), 2.2, &shd2
);
85 Sphere
s3(Vec3f(3,0.8,-2), 2, &shd3
);
86 InfinitePlane
p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4
);
89 Triangle
t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5
);
98 Image
img(scene
.camera()->resX(),scene
.camera()->resY()); // image array
99 Ray ray
; // primary ray
101 for(int y
= 0; y
< scene
.camera()->resY(); y
++)
103 for (int x
= 0; x
< scene
.camera()->resX(); x
++)
106 /* Initialize your ray here */
108 scene
.camera()->InitRay(x
+0.5,y
+0.5,ray
); // initialize ray
110 Vec3f col
= scene
.RayTrace(ray
);
112 img(x
,y
) = col
; // store pixel color
113 //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
116 img
.WritePPM(fileName
); // write final image
119 void RenderFrameReflectiveEyeLight(const std::string
& fileName
)
121 /* Scene definition */
126 ReflectiveEyeLightShader
shd1(&scene
, 1.0, Vec3f(1,0,0)); // red surface
127 ReflectiveEyeLightShader
shd2(&scene
, 1.0, Vec3f(0.0,1.0,0.0)); // green surface
128 ReflectiveEyeLightShader
shd3(&scene
, 1.0, Vec3f(0,0,1)); // blue surface
129 ReflectiveEyeLightShader
shd4(&scene
, 0.8, Vec3f(1,1,0)); // yellow surface
130 ReflectiveEyeLightShader
shd5(&scene
, 1.0, Vec3f(0,1,1)); // cyan surface
131 ReflectiveEyeLightShader
shd6(&scene
, 0.0, Vec3f(1,1,1)); // white surface
134 Sphere
s1(Vec3f(-2,1.7,0), 2, &shd1
);
135 Sphere
s2(Vec3f(0.4,-1,1), 2.0, &shd2
);
136 Sphere
s3(Vec3f(3,0.8,-2), 2, &shd3
);
137 InfinitePlane
p1(Vec3f(0,-1,0),Vec3f(0,1,0), &shd4
);
140 Triangle
t1(Vec3f(-2,3,1),Vec3f(1,2,1),Vec3f(3,2.8,3), &shd5
);
150 Image
img(scene
.camera()->resX(),scene
.camera()->resY()); // image array
151 Ray ray
; // primary ray
153 for(int y
= 0; y
< scene
.camera()->resY(); y
++)
155 for (int x
= 0; x
< scene
.camera()->resX(); x
++)
158 /* Initialize your ray here */
160 scene
.camera()->InitRay(x
+0.5,y
+0.5,ray
); // initialize ray
162 Vec3f col
= scene
.RayTrace(ray
);
164 img(x
,y
) = col
; // store pixel color
165 //std::cerr << "Main: Image color = " << img(x,y) << std::endl;
168 img
.WritePPM(fileName
); // write final image
173 #define RESX 640 // image x-resolution
174 #define RESY 480 // image y-resolution
176 int main(int, char**)
178 RenderFrameFlat("flatshaded.ppm");
179 RenderFrameEyeLight("eyelight.ppm");
180 RenderFrameReflectiveEyeLight("reflective.ppm");
This page took 0.055052 seconds and 5 git commands to generate.