Change format of background sky in camera
This commit is contained in:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"random": "cpp"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
BIN
build/Raytracer
BIN
build/Raytracer
Binary file not shown.
23
camera.h
23
camera.h
@@ -11,6 +11,7 @@ class camera {
|
|||||||
int imageWidth = 100; // Rendered image width in pixel count
|
int imageWidth = 100; // Rendered image width in pixel count
|
||||||
int samplesPerPixel = 10; // Count of random samples for each pixel.
|
int samplesPerPixel = 10; // Count of random samples for each pixel.
|
||||||
int maxDepth = 10; // Maximum number of ray bounces into the scene.
|
int maxDepth = 10; // Maximum number of ray bounces into the scene.
|
||||||
|
colour background; // Scene background colour.
|
||||||
|
|
||||||
double vFieldOfView = 90; // Vertical view angle (field of view)
|
double vFieldOfView = 90; // Vertical view angle (field of view)
|
||||||
point3 lookFrom = point3(0, 0, 0); // Point camera is looking from.
|
point3 lookFrom = point3(0, 0, 0); // Point camera is looking from.
|
||||||
@@ -120,23 +121,17 @@ class camera {
|
|||||||
|
|
||||||
hitRecord rec;
|
hitRecord rec;
|
||||||
|
|
||||||
if (world.hit(r, interval(0.001, infinity), rec)) {
|
// if hte ray hits nothing, return the background colour.
|
||||||
ray scattered;
|
if (!world.hit(r, interval(0.001, infinity), rec)) return background;
|
||||||
colour attenuation;
|
|
||||||
|
|
||||||
if (rec.mat->scatter(r, rec, attenuation, scattered)) {
|
ray scattered;
|
||||||
return attenuation * rayColour(scattered, depth - 1, world);
|
colour attenuation;
|
||||||
}
|
colour colourFromEmission = rec.mat->emitted(rec.u, rec.v, rec.p);
|
||||||
return colour(0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 unitDirection = unitVector(r.direction());
|
if (!rec.mat->scatter(r, rec, attenuation, scattered)) return colourFromEmission;
|
||||||
auto a = 0.5 * (unitDirection.y() + 1.0);
|
|
||||||
// Blue sky.
|
|
||||||
return (1.0-a) * colour(1.0, 1.0, 1.0) + a * colour(0.5, 0.7, 1.0);
|
|
||||||
|
|
||||||
// Red sky.
|
colour colourFromScatter = attenuation * rayColour(scattered, depth - 1, world);
|
||||||
//return (1.0-a) * colour(0.56, 0.08, 0.08) + a * colour(0.1, 0.0, 0.0);
|
return colourFromEmission + colourFromScatter;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
6
main.cpp
6
main.cpp
@@ -64,6 +64,7 @@ void bouncingSpheres(void) {
|
|||||||
cam.imageWidth = 400;
|
cam.imageWidth = 400;
|
||||||
cam.samplesPerPixel = 100;
|
cam.samplesPerPixel = 100;
|
||||||
cam.maxDepth = 50;
|
cam.maxDepth = 50;
|
||||||
|
cam.background = colour(0.70, 0.80, 1.00);
|
||||||
|
|
||||||
cam.vFieldOfView = 20;
|
cam.vFieldOfView = 20;
|
||||||
cam.lookFrom = point3(13,2,3);
|
cam.lookFrom = point3(13,2,3);
|
||||||
@@ -90,6 +91,7 @@ void checkeredSpheres(void) {
|
|||||||
cam.imageWidth = 800;
|
cam.imageWidth = 800;
|
||||||
cam.samplesPerPixel = 100;
|
cam.samplesPerPixel = 100;
|
||||||
cam.maxDepth = 50;
|
cam.maxDepth = 50;
|
||||||
|
cam.background = colour(0.70, 0.80, 1.00);
|
||||||
|
|
||||||
cam.vFieldOfView = 20;
|
cam.vFieldOfView = 20;
|
||||||
cam.lookFrom = point3(13, 2, 3);
|
cam.lookFrom = point3(13, 2, 3);
|
||||||
@@ -111,6 +113,7 @@ void earth(void) {
|
|||||||
cam.imageWidth = 800;
|
cam.imageWidth = 800;
|
||||||
cam.samplesPerPixel = 100;
|
cam.samplesPerPixel = 100;
|
||||||
cam.maxDepth = 50;
|
cam.maxDepth = 50;
|
||||||
|
cam.background = colour(0.70, 0.80, 1.00);
|
||||||
|
|
||||||
cam.vFieldOfView = 20;
|
cam.vFieldOfView = 20;
|
||||||
cam.lookFrom = point3(0,0,12);
|
cam.lookFrom = point3(0,0,12);
|
||||||
@@ -133,6 +136,7 @@ void funny() {
|
|||||||
cam.imageWidth = 800;
|
cam.imageWidth = 800;
|
||||||
cam.samplesPerPixel = 100;
|
cam.samplesPerPixel = 100;
|
||||||
cam.maxDepth = 50;
|
cam.maxDepth = 50;
|
||||||
|
cam.background = colour(0.70, 0.80, 1.00);
|
||||||
|
|
||||||
cam.vFieldOfView = 20;
|
cam.vFieldOfView = 20;
|
||||||
cam.lookFrom = point3(0,0,12);
|
cam.lookFrom = point3(0,0,12);
|
||||||
@@ -157,6 +161,7 @@ void perlinSpheres() {
|
|||||||
cam.imageWidth = 800;
|
cam.imageWidth = 800;
|
||||||
cam.samplesPerPixel = 100;
|
cam.samplesPerPixel = 100;
|
||||||
cam.maxDepth = 50;
|
cam.maxDepth = 50;
|
||||||
|
cam.background = colour(0.70, 0.80, 1.00);
|
||||||
|
|
||||||
cam.vFieldOfView = 20;
|
cam.vFieldOfView = 20;
|
||||||
cam.lookFrom = point3(13,2,3);
|
cam.lookFrom = point3(13,2,3);
|
||||||
@@ -191,6 +196,7 @@ void quads() {
|
|||||||
cam.imageWidth = 800;
|
cam.imageWidth = 800;
|
||||||
cam.samplesPerPixel = 100;
|
cam.samplesPerPixel = 100;
|
||||||
cam.maxDepth = 50;
|
cam.maxDepth = 50;
|
||||||
|
cam.background = colour(0.70, 0.80, 1.00);
|
||||||
|
|
||||||
cam.vFieldOfView = 80;
|
cam.vFieldOfView = 80;
|
||||||
cam.lookFrom = point3(0, 0, 9);
|
cam.lookFrom = point3(0, 0, 9);
|
||||||
|
Reference in New Issue
Block a user