cloudy-raytracer/homeworkMains/ex4.cpp

102 lines
3.9 KiB
C++
Raw Normal View History

2022-11-25 14:58:29 +01:00
#include <iostream>
#include <string>
#include "camera/perspectivecamera.h"
#include "renderer/simplerenderer.h"
#include "scene/simplescene.h"
#include "primitive/box.h"
#include "primitive/infiniteplane.h"
#include "primitive/objmodel.h"
#include "primitive/sphere.h"
#include "shader/brdfshader.h"
#include "shader/lambertshader.h"
#include "shader/mirrorshader.h"
#include "shader/phongshader.h"
#include "shader/cooktorranceshader.h"
#include "renderer/depthoffieldrenderer.h"
2022-11-25 14:58:29 +01:00
#include "light/ambientlight.h"
#include "light/pointlight.h"
#include "light/spotlight.h"
#include "post_processing/bloom.h"
2022-11-25 14:58:29 +01:00
int main() {
// Let's create a simple scene...
SimpleScene scene;
// Set up the camera
PerspectiveCamera camera;
camera.setFovAngle(90.0f);
camera.setPosition(Vector3d(0.0f, 0.0f, -10.0f));
camera.setForwardDirection(Vector3d(0.0f, 0.0f, 1.0f));
camera.setUpDirection(Vector3d(0.0f, 1.0f, 0.0f));
2022-11-25 14:58:29 +01:00
// Add shaders
auto mirror = std::make_shared<MirrorShader>();
auto white = std::make_shared<LambertShader>(Color(0.9f, 0.9f, 0.9f));
auto red = std::make_shared<LambertShader>(Color(1.0f, 0.3f, 0.2f));
auto blue = std::make_shared<LambertShader>(Color(0.2f, 0.3f, 1.0f));
auto orange = std::make_shared<PhongShader>(Color(1.0f, 0.64f, 0.0f), 1.0f, Color(1.0f, 1.0f, 1.0f), 1.0f, 25.0f);
auto gold= std::make_shared<CookTorranceShader>(Color(0.83f, 0.69f, 0.22f), Color(1.0f, 1.0f, 0.0f), 1.2f, 0.2f);
auto blueMetallic = std::make_shared<BrdfShader>("../data/blue-metallic-paint.binary", Color(7.0f, 7.0f, 7.0f));
auto darkRed = std::make_shared<BrdfShader>("../data/dark-red-paint.binary", Color(7.0f, 7.0f, 7.0f));
// DOF Shader
bool dofShader = true;
2022-11-25 14:58:29 +01:00
// Set up the walls
// ---------------------------------------------------------------------------
2022-11-25 14:58:29 +01:00
scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, 0.0f, +5.0f), Vector3d(0.0f, 0.0f, -1.0f), mirror));
scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, 0.0f, -5.0f), Vector3d(0.0f, 0.0f, +1.0f), mirror));
scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, +5.0f, 0.0f), Vector3d(0.0f, -1.0f, 0.0f), white));
scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, -5.0f, 0.0f), Vector3d(0.0f, +1.0f, 0.0f), white));
scene.add(std::make_shared<InfinitePlane>(Vector3d(+5.0f, 0.0f, 0.0f), Vector3d(-1.0f, 0.0f, 0.0f), blue));
2022-11-25 14:58:29 +01:00
scene.add(std::make_shared<InfinitePlane>(Vector3d(-5.0f, 0.0f, 0.0f), Vector3d(+1.0f, 0.0f, 0.0f), red));
scene.add(std::make_shared<Sphere>(Vector3d(-3.0f, 0.0f, 0.0f), 1.0f, blueMetallic));
scene.add(std::make_shared<Sphere>(Vector3d(0.0f, 2.0f, 0.0f), 1.0f, orange));
scene.add(std::make_shared<Sphere>(Vector3d(3.0f, 0.0f, 0.0f), 1.0f, darkRed));
scene.add(std::make_shared<Sphere>(Vector3d(-3.0f, -3.3f, -4.0f), 1.0f, mirror));
2022-11-25 14:58:29 +01:00
// Add the teapot
auto teapot = std::make_shared<ObjModel>(gold);
teapot->loadObj("../data/teapot.obj", Vector3d(3.0f, 3.0f, 3.0f), Vector3d(0.0f, -5.0f, 0.0f));
2022-11-25 14:58:29 +01:00
scene.add(teapot);
// Add ambient light
scene.add(std::make_shared<AmbientLight>(0.15f));
//scene.add(std::make_shared<PointLight>(Vector3d(0.0f, 4.0f, -4.0f), 15.0f));
scene.add(std::make_shared<PointLight>(Vector3d(0.0f, 2.5f, -4.0f), 7.0f));
2022-11-25 14:58:29 +01:00
// Render the scene
// SimpleRenderer renderer;
// renderer.renderImage(scene, camera, 1024, 1024).save("result.png");
// initialize renderer: aperture = lens thickness, secondaryRayCount = how many rays per pixel are created
// focalLength = the area which is in focus
DOFRenderer renderer(0.2, 100, 10.0f);
// Use DOFRenderer to raytrace !!! careful more pixels lead to insane rendering times
Texture image = renderer.renderImage(scene, camera, 1024, 1024);
// Use post-processing Bloom effect
Bloom bloomEffect = Bloom(image.getImage());
Texture imageWithBloom = image;
imageWithBloom.setTexture(bloomEffect.bloom(0.55f, 5, 10.0f, 0.06f));
// save images
image.save("result.png");
image.save("resultWithBloom");
2022-11-25 14:58:29 +01:00
return 0;
}