Change format of background sky in camera

This commit is contained in:
CJSatnarine
2024-07-10 19:14:56 -04:00
parent 7bb8a36f8b
commit 7a96c64c74
7 changed files with 360015 additions and 640009 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"files.associations": {
"random": "cpp"
}
}

Binary file not shown.

View File

@@ -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.
if (!world.hit(r, interval(0.001, infinity), rec)) return background;
ray scattered; ray scattered;
colour attenuation; colour attenuation;
colour colourFromEmission = rec.mat->emitted(rec.u, rec.v, rec.p);
if (rec.mat->scatter(r, rec, attenuation, scattered)) { if (!rec.mat->scatter(r, rec, attenuation, scattered)) return colourFromEmission;
return attenuation * rayColour(scattered, depth - 1, world);
}
return colour(0, 0, 0);
}
vec3 unitDirection = unitVector(r.direction()); colour colourFromScatter = attenuation * rayColour(scattered, depth - 1, world);
auto a = 0.5 * (unitDirection.y() + 1.0); return colourFromEmission + colourFromScatter;
// Blue sky.
return (1.0-a) * colour(1.0, 1.0, 1.0) + a * colour(0.5, 0.7, 1.0);
// Red sky.
//return (1.0-a) * colour(0.56, 0.08, 0.08) + a * colour(0.1, 0.0, 0.0);
} }
}; };
#endif #endif

999988
image.ppm

File diff suppressed because it is too large Load Diff

View File

@@ -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);