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.
25
camera.h
25
camera.h
@@ -10,7 +10,8 @@ class camera {
|
||||
double aspectRatio = 1.0; // Ratio of image width over height
|
||||
int imageWidth = 100; // Rendered image width in pixel count
|
||||
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)
|
||||
point3 lookFrom = point3(0, 0, 0); // Point camera is looking from.
|
||||
@@ -120,23 +121,17 @@ class camera {
|
||||
|
||||
hitRecord rec;
|
||||
|
||||
if (world.hit(r, interval(0.001, infinity), rec)) {
|
||||
ray scattered;
|
||||
colour attenuation;
|
||||
// if hte ray hits nothing, return the background colour.
|
||||
if (!world.hit(r, interval(0.001, infinity), rec)) return background;
|
||||
|
||||
if (rec.mat->scatter(r, rec, attenuation, scattered)) {
|
||||
return attenuation * rayColour(scattered, depth - 1, world);
|
||||
}
|
||||
return colour(0, 0, 0);
|
||||
}
|
||||
ray scattered;
|
||||
colour attenuation;
|
||||
colour colourFromEmission = rec.mat->emitted(rec.u, rec.v, rec.p);
|
||||
|
||||
vec3 unitDirection = unitVector(r.direction());
|
||||
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);
|
||||
if (!rec.mat->scatter(r, rec, attenuation, scattered)) return colourFromEmission;
|
||||
|
||||
// Red sky.
|
||||
//return (1.0-a) * colour(0.56, 0.08, 0.08) + a * colour(0.1, 0.0, 0.0);
|
||||
colour colourFromScatter = attenuation * rayColour(scattered, depth - 1, world);
|
||||
return colourFromEmission + colourFromScatter;
|
||||
}
|
||||
};
|
||||
#endif
|
6
main.cpp
6
main.cpp
@@ -64,6 +64,7 @@ void bouncingSpheres(void) {
|
||||
cam.imageWidth = 400;
|
||||
cam.samplesPerPixel = 100;
|
||||
cam.maxDepth = 50;
|
||||
cam.background = colour(0.70, 0.80, 1.00);
|
||||
|
||||
cam.vFieldOfView = 20;
|
||||
cam.lookFrom = point3(13,2,3);
|
||||
@@ -90,6 +91,7 @@ void checkeredSpheres(void) {
|
||||
cam.imageWidth = 800;
|
||||
cam.samplesPerPixel = 100;
|
||||
cam.maxDepth = 50;
|
||||
cam.background = colour(0.70, 0.80, 1.00);
|
||||
|
||||
cam.vFieldOfView = 20;
|
||||
cam.lookFrom = point3(13, 2, 3);
|
||||
@@ -111,6 +113,7 @@ void earth(void) {
|
||||
cam.imageWidth = 800;
|
||||
cam.samplesPerPixel = 100;
|
||||
cam.maxDepth = 50;
|
||||
cam.background = colour(0.70, 0.80, 1.00);
|
||||
|
||||
cam.vFieldOfView = 20;
|
||||
cam.lookFrom = point3(0,0,12);
|
||||
@@ -133,6 +136,7 @@ void funny() {
|
||||
cam.imageWidth = 800;
|
||||
cam.samplesPerPixel = 100;
|
||||
cam.maxDepth = 50;
|
||||
cam.background = colour(0.70, 0.80, 1.00);
|
||||
|
||||
cam.vFieldOfView = 20;
|
||||
cam.lookFrom = point3(0,0,12);
|
||||
@@ -157,6 +161,7 @@ void perlinSpheres() {
|
||||
cam.imageWidth = 800;
|
||||
cam.samplesPerPixel = 100;
|
||||
cam.maxDepth = 50;
|
||||
cam.background = colour(0.70, 0.80, 1.00);
|
||||
|
||||
cam.vFieldOfView = 20;
|
||||
cam.lookFrom = point3(13,2,3);
|
||||
@@ -191,6 +196,7 @@ void quads() {
|
||||
cam.imageWidth = 800;
|
||||
cam.samplesPerPixel = 100;
|
||||
cam.maxDepth = 50;
|
||||
cam.background = colour(0.70, 0.80, 1.00);
|
||||
|
||||
cam.vFieldOfView = 80;
|
||||
cam.lookFrom = point3(0, 0, 9);
|
||||
|
Reference in New Issue
Block a user