-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (62 loc) · 2.47 KB
/
main.cpp
File metadata and controls
73 lines (62 loc) · 2.47 KB
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
66
67
68
69
70
71
72
73
#include "scene.h"
#include "bmp_output.h"
#include "denoiser.h"
#include "vector.h"
#include "lights.h"
#include <iostream>
#include <vector>
#include <thread>
Vector3** createCheckerboardPattern(int width, int height, int checkSize, const Vector3& color1, const Vector3& color2) {
Vector3** texture = new Vector3 * [height];
for (int y = 0; y < height; y++) {
texture[y] = new Vector3[width];
for (int x = 0; x < width; x++) {
int checkX = x / checkSize;
int checkY = y / checkSize;
if ((checkX + checkY) % 2 == 0) {
texture[y][x] = color1;
} else {
texture[y][x] = color2;
}
}
}
return texture;
}
int main() {
Scene scene;
// Create scene
scene.camera_position = Vector3(0, 0, 0);
scene.width = 600;
scene.height = 450;
scene.samples_per_pixel = 500;
scene.max_bounces = 10;
// Add shapes to the scene
Sphere* sphere1 = new Sphere(Vector3(0, 0, -5), 1);
sphere1->material = Material(Vector3(1, 0.05, 0.05), 1); // Red diffuse
sphere1->material.specular_color = Vector3(1, 1, 1); // Slight specular
sphere1->material.specular_probability = 0.04;
scene.addShape(sphere1);
Sphere* sphere2 = new Sphere(Vector3(2.1, 0, -5), 1);
sphere2->material = Material(Vector3(1, 1, 1), 0); // White reflective
scene.addShape(sphere2);
SphereLight* light = new SphereLight(Vector3(2, 5, 2), 1, 50, Vector3(1, 1, 1));
scene.addLight(light);
Box* box = new Box(Vector3(-2, 1, -5), Vector3(0.5, 0.5, 0.5), Vector3(-35, 45, 0));
box->material = Material(Vector3(0.05, 0.05, 1), 1); // Blue diffuse
scene.addShape(box);
Plane* ground = new Plane(Vector3(0, 1, 0), Vector3(0, -1, 0));
ground->material = Material(Vector3(1, 1, 1), 0.9); // White diffuse
int check_width = 512;
int check_height = 512;
ground->material.texture = createCheckerboardPattern(check_width, check_height, 64, Vector3(1, 1, 1), Vector3(0.05, 0.05, 0.05));
ground->material.has_texture = true;
ground->material.textures_width = check_width;
ground->material.textures_height = check_height;
scene.addShape(ground);
// Render the scene
std::vector<Vector3> framebuffer = scene.renderThreaded(std::thread::hardware_concurrency());
// Denoise the image
Denoiser::bilateralFilter(framebuffer, scene.width, scene.height);
saveBMP("output.bmp", scene.width, scene.height, framebuffer);
return 0;
}