-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathTracer01.cpp
65 lines (55 loc) · 3.08 KB
/
PathTracer01.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include "Vector3D.h"
#include "Point3D.h"
#include "Ray.h"
#include "Color.h"
#include "Camera.h"
#include "CameraManager.h"
#include "Picture.h"
#include "Triangle.h"
#include "Scene.h"
#include "SimpleTracer.h"
#include "RecursiveRayTracer.h"
#include "Sphere.h"
#include "Triangle.h"
void renderPicture(Picture& picture, Camera* camera, Tracer& tracer, int samplesPerPixel)
{
for (int h = 0; h < picture.getHeight(); h++)
{
for (int w = 0; w < picture.getWidth(); w++)
{
for (int s = 0; s < samplesPerPixel; s++)
{
Ray sampleRay = camera->getSampleRayThroughPixel(w, h);
Color color = tracer.traceSingleRay(sampleRay);
picture.addPixelColor(w, h, color);
}
}
}
}
void savePictureAndExit(Picture& picture, const char* filename)
{
picture.printToFile(filename);
std::cout << "Rendering into " << filename << " finished" << std::endl;
std::cout << "Press enter to exit program!" << std::endl;
std::cin.get();
}
int main()
{
const int PIC_WIDTH = 600;
const int PIC_HEIGHT = 600;
const int SAMPLES_PER_PIXEL = 1;
Picture picture(PIC_WIDTH, PIC_HEIGHT);
CameraManager cameraManager;
cameraManager.setupDefaultCameras();
Camera* camera = cameraManager.getCamera(1);
Scene scene;
scene.buildTestScene02();
//SimpleTracer tracer;
RecursiveRayTracer tracer;
tracer.setScene(scene);
renderPicture(picture, camera, tracer, SAMPLES_PER_PIXEL);
const char* fileName = "render01.ppm";
savePictureAndExit(picture, fileName);
return 0;
}