#include #include #include #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" #include "light/ambientlight.h" #include "light/pointlight.h" #include "light/spotlight.h" #include "post_processing/bloom.h" 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)); // Add shaders auto mirror = std::make_shared(); auto white = std::make_shared(Color(0.9f, 0.9f, 0.9f)); auto red = std::make_shared(Color(1.0f, 0.3f, 0.2f)); auto blue = std::make_shared(Color(0.2f, 0.3f, 1.0f)); auto orange = std::make_shared(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(Color(0.83f, 0.69f, 0.22f), Color(1.0f, 1.0f, 0.0f), 1.2f, 0.2f); auto blueMetallic = std::make_shared("../data/blue-metallic-paint.binary", Color(7.0f, 7.0f, 7.0f)); auto darkRed = std::make_shared("../data/dark-red-paint.binary", Color(7.0f, 7.0f, 7.0f)); auto glass = std::make_shared(1.31f, 1.0f); // Set up the walls // --------------------------------------------------------------------------- scene.add(std::make_shared(Vector3d(0.0f, 0.0f, +5.0f), Vector3d(0.0f, 0.0f, -1.0f), mirror)); scene.add(std::make_shared(Vector3d(0.0f, 0.0f, -5.0f), Vector3d(0.0f, 0.0f, +1.0f), mirror)); scene.add(std::make_shared(Vector3d(0.0f, +5.0f, 0.0f), Vector3d(0.0f, -1.0f, 0.0f), white)); scene.add(std::make_shared(Vector3d(0.0f, -5.0f, 0.0f), Vector3d(0.0f, +1.0f, 0.0f), white)); scene.add(std::make_shared(Vector3d(+5.0f, 0.0f, 0.0f), Vector3d(-1.0f, 0.0f, 0.0f), blue)); scene.add(std::make_shared(Vector3d(-5.0f, 0.0f, 0.0f), Vector3d(+1.0f, 0.0f, 0.0f), red)); scene.add(std::make_shared(Vector3d(-5.0f, 0.0f, 0.0f), 1.0f, blueMetallic)); scene.add(std::make_shared(Vector3d(-2.0f, 5.0f, 0.0f), 1.0f, orange)); scene.add(std::make_shared(Vector3d(2.0f, 4.0f, 0.0f), 1.0f, orange)); scene.add(std::make_shared(Vector3d(3.0f, 4.0f, -2.0f), 1.0f, glass)); scene.add(std::make_shared(Vector3d(2.0f, 3.0f, 4.0f), 1.0f, orange)); scene.add(std::make_shared(Vector3d(-3.0f, 3.0f, 2.0f), 1.0f, orange)); scene.add(std::make_shared(Vector3d(2.0f, 1.0f, 0.0f), 1.0f, mirror)); scene.add(std::make_shared(Vector3d(3.0f, -3.0f, 0.0f), 1.0f, darkRed)); scene.add(std::make_shared(Vector3d(5.0f, 0.0f, 0.0f), 1.0f, darkRed)); scene.add(std::make_shared(Vector3d(-5.0f, -3.3f, -4.0f), 1.0f, mirror)); // Add the teapot auto ship = std::make_shared(gold); ship->loadObj("../data/NewObjects/Random/Ship.obj", Vector3d(0.07f, 0.07f, 0.07f), Vector3d(-1.0f, -5.0f, 0.0f)); scene.add(ship); // Add ambient light scene.add(std::make_shared(0.15f)); scene.add(std::make_shared(Vector3d(0.0f, 4.0f, -4.0f), 7.0f)); scene.add(std::make_shared(Vector3d(0.0f, 2.5f, -4.0f), 7.0f)); // 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, 50, 10.0f); // Use DOFRenderer to raytrace !!! careful more pixels lead to insane rendering times int width = 600; Texture image = renderer.renderImage(scene, camera, width, width / 16 * 9); // 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"); CImg CImgOfImage = image.getImage(); CImg img_8bit(image.width(), image.height(), 1, 3); cimg_forXYC(CImgOfImage,x,y,c) { img_8bit(x,y,c) = (unsigned char)std::round(CImgOfImage(x, y, c) * 255); } CImgDisplay disp(img_8bit, "My Rendered Image",0, false, false); while (!disp.is_closed()) { disp.wait(); disp.display(img_8bit); if (disp.is_resized()) { disp.resize(); } } // image.save("resultWithBloom"); return 0; }