153 lines
5.7 KiB
C++
153 lines
5.7 KiB
C++
|
#include <scene/simplescene.h>
|
||
|
|
||
|
#include <camera/perspectivecamera.h>
|
||
|
#include <shader/materialshader.h>
|
||
|
#include <primitive/sphere.h>
|
||
|
#include <light/ambientlight.h>
|
||
|
#include <light/pointlight.h>
|
||
|
#include <renderer/depthoffieldrenderer.h>
|
||
|
#include <post_processing/bloom.h>
|
||
|
#include <primitive/objmodel.h>
|
||
|
#include <shader/lambertshader.h>
|
||
|
#include <renderer/simplerenderer.h>
|
||
|
#include <shader/brdfshader.h>
|
||
|
#include <thread>
|
||
|
//#include <conio.h>
|
||
|
#include <shader/cooktorranceshader.h>
|
||
|
#include <shader/phongshader.h>
|
||
|
#include <primitive/infiniteplane.h>
|
||
|
#include <light/spotlight.h>
|
||
|
#include <shader/cloudshader.h>
|
||
|
#include <shader/mirrorshader.h>
|
||
|
#include <shader/refractionshader.h>
|
||
|
#include <primitive/triangle.h>
|
||
|
#include <shader/simpleshadowshader.h>
|
||
|
#include <light/sunlight.h>
|
||
|
#include "scene/fastscene.h"
|
||
|
#include "shader/toneshader.h"
|
||
|
#include "renderer/superrenderer.h"
|
||
|
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
SimpleScene scene;
|
||
|
scene.setEnvironmentMap(std::make_shared<Texture>("data/clear_red_sky.jpg"));
|
||
|
// scene.setEnvironmentMap(std::make_shared<Texture>("data/TychoSkymapII.t5_04096x02048.png"));
|
||
|
scene.setBackgroundColor(Color(0.2, 0.1, 0.1) * .5f);
|
||
|
|
||
|
// Light
|
||
|
auto mainLight = std::make_shared<SunLight>(Vector3d(-.9f, -.7f, .5f), 2.0f,
|
||
|
Color(1, 0.79f, 0.62f));
|
||
|
scene.add(mainLight);
|
||
|
// scene.add(std::make_shared<AmbientLight>(.1f));
|
||
|
|
||
|
// Set up the camera
|
||
|
PerspectiveCamera camera;
|
||
|
camera.setFovAngle(70.0f);
|
||
|
camera.setPosition(Vector3d(0.0f, 1.0f, 0.0f));
|
||
|
camera.setForwardDirection(Vector3d(1.0f, 0.0f, 0.0f));
|
||
|
// Final camera Position
|
||
|
// camera.setPosition(Vector3d(0.0f, -4.9f, 0.0f));
|
||
|
// camera.setForwardDirection(Vector3d(1.0f, 0.2f, 0.0f));
|
||
|
camera.setUpDirection(Vector3d(0.0f, 1.0f, 0.0f));
|
||
|
|
||
|
// Shader
|
||
|
auto church = std::make_shared<SimpleShadowShader>(Color(0.6f, 0.4f, 0.2f));
|
||
|
auto mirror = std::make_shared<MirrorShader>();
|
||
|
auto glass = std::make_shared<RefractionShader>(1.31f, 1.0f);
|
||
|
|
||
|
|
||
|
// Make Objects
|
||
|
auto house = std::make_shared<ObjModel>(church);
|
||
|
// auto temple = std::make_shared<ObjModel>(glass);
|
||
|
|
||
|
house->loadObj("data/NewObjects/house/objBuilding.obj", Vector3d(1.0f, 1.0f, 1.0f) * 0.7f,
|
||
|
Vector3d(43.0f, 1.5f, -9.0f));
|
||
|
// temple->loadObj("data/NewObjects/Random/Temple.obj", Vector3d(0.1f, 0.1f, 0.1f), Vector3d(30.0f, -6.0f, -10.0f));
|
||
|
|
||
|
|
||
|
// Setup ground and sky
|
||
|
// Add floor
|
||
|
// scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, -5.0f, 0.0f), Vector3d(0.0f, 1.0f, 0.0f), church));
|
||
|
|
||
|
|
||
|
|
||
|
// Add clouds
|
||
|
auto cloudSettings = CloudSettings();
|
||
|
cloudSettings.seed = 42;
|
||
|
cloudSettings.lightAbsorptionTowardsLight = 0.2f;
|
||
|
cloudSettings.lightAbsorptionThroughCloud = 1.9f;
|
||
|
cloudSettings.densityOffset = -0.65f;
|
||
|
cloudSettings.shadowIntensity = 0.4f;
|
||
|
auto cloudShader = std::make_shared<CloudShader>(cloudSettings);
|
||
|
scene.add(std::make_shared<Box>(Vector3d(0.0f, 15.0f, 0.0f), Vector3d(200.0f, 10.0f, 300.0f), cloudShader));
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// Insert Objects
|
||
|
scene.add(house);
|
||
|
//scene.add(temple);
|
||
|
//scene.add(std::make_shared<Sphere>(Vector3d(3.0f, -2.0f, -5.0f), 0.5f, mirror));
|
||
|
float f = 0.5;
|
||
|
scene.add(std::make_shared<Sphere>(Vector3d(10.0f, -6.5f, 5.5f), 5.0f,
|
||
|
std::make_shared<SimpleShadowShader>(Color(0.1f, 0.6f, 0.1f) * f)));
|
||
|
f *= 0.9f;
|
||
|
scene.add(std::make_shared<Sphere>(Vector3d(15.0f, -21.0f, -9.0f), 20.0f,
|
||
|
std::make_shared<SimpleShadowShader>(Color(0.1f, 0.6f, 0.1f) * f)));
|
||
|
f *= 0.9f;
|
||
|
scene.add(std::make_shared<Sphere>(Vector3d(23.0f, -12.0f, 5.0f), 10.0f,
|
||
|
std::make_shared<SimpleShadowShader>(Color(0.1f, 0.6f, 0.1f) * f)));
|
||
|
f *= 0.9f;
|
||
|
scene.add(std::make_shared<Sphere>(Vector3d(30.0f, -15.0f, 19.0f), 15.0f,
|
||
|
std::make_shared<SimpleShadowShader>(Color(0.1f, 0.6f, 0.1f) * f)));
|
||
|
f *= 0.9f;
|
||
|
scene.add(std::make_shared<Sphere>(Vector3d(45.0f, -38.0f, -9.0f), 40.0f,
|
||
|
std::make_shared<SimpleShadowShader>(Color(0.1f, 0.6f, 0.1f) * f)));
|
||
|
f *= 0.9f;
|
||
|
scene.add(std::make_shared<Sphere>(Vector3d(52.0f, -28.0f, 20.0f), 30.0f,
|
||
|
std::make_shared<SimpleShadowShader>(Color(0.1f, 0.6f, 0.1f) * f)));
|
||
|
|
||
|
// Render
|
||
|
SuperRenderer rendererTest;
|
||
|
rendererTest.setSuperSamplingFactor(1);
|
||
|
int width = 512;
|
||
|
Texture imageSceneToTest = rendererTest.renderImage(scene, camera, width, width / 16 * 9);
|
||
|
|
||
|
// 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, 70.0f);
|
||
|
|
||
|
// Use DOFRenderer to raytrace !!! careful more pixels lead to insane rendering times
|
||
|
// Texture image = renderer.renderImage(scene, camera, 1920, 1080);
|
||
|
|
||
|
// 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
|
||
|
imageSceneToTest.save("result.png");
|
||
|
// image.save("result.png");
|
||
|
// image.save("resultWithBloom");
|
||
|
|
||
|
// CImg<float> image = imageSceneToTest.getImage();
|
||
|
// CImg<unsigned char> img_8bit(image.width(), image.height(), 1, 3);
|
||
|
// cimg_forXYC(image, x, y, c) {
|
||
|
// img_8bit(x, y, c) = (unsigned char) std::round(image(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();
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
return 0;
|
||
|
}
|