Some beautiful scenes

This commit is contained in:
Maximilian Giller 2023-01-29 21:50:01 +01:00
parent a99159dc53
commit 8988af2e0f
7 changed files with 2964 additions and 48 deletions

1
.gitignore vendored
View file

@ -7,6 +7,7 @@ build/
/data/*
!/data/README.txt
!/data/fireplace
!/data/FancyPlane
!/data/Bus
!/data/subdiv
!/data/parallax

View file

@ -40,6 +40,12 @@ endif()
add_executable(beautifulScene beautifulScene.cpp)
target_link_libraries(beautifulScene tracey)
add_executable(beautifulSceneEpic beautifulSceneEpic.cpp)
target_link_libraries(beautifulSceneEpic tracey)
add_executable(beautifulSceneDark beautifulSceneDark.cpp)
target_link_libraries(beautifulSceneDark tracey)
add_executable(tracey_ex1 homeworkMains/ex1.cpp)
target_link_libraries(tracey_ex1 tracey)

View file

@ -12,7 +12,7 @@
#include <renderer/simplerenderer.h>
#include <shader/brdfshader.h>
#include <thread>
#include <conio.h>
//#include <conio.h>
#include <shader/cooktorranceshader.h>
#include <shader/phongshader.h>
#include <primitive/infiniteplane.h>
@ -25,19 +25,20 @@
#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_blue_sky.jpg"));
// scene.setEnvironmentMap(std::make_shared<Texture>("../data/TychoSkymapII.t5_04096x02048.png"));
scene.setEnvironmentMap(std::make_shared<Texture>("data/clear_blue_sky.jpg"));
// scene.setEnvironmentMap(std::make_shared<Texture>("data/TychoSkymapII.t5_04096x02048.png"));
scene.setBackgroundColor(Color(0.1, 0.1, 0.1));
// Light
auto mainLight = std::make_shared<SunLight>(Vector3d(-6.0f, -0.5f, 2.0f), 2.0f,
auto mainLight = std::make_shared<SunLight>(Vector3d(.5f, -.7f, .5f), 2.0f,
Color(1, 1, 1));//Color(1, 0.79f, 0.62f));
scene.add(mainLight);
scene.add(std::make_shared<AmbientLight>(0.1f));
scene.add(std::make_shared<AmbientLight>(.1f));
// Set up the camera
PerspectiveCamera camera;
@ -50,60 +51,59 @@ int main() {
camera.setUpDirection(Vector3d(0.0f, 1.0f, 0.0f));
// Shader
auto gold = std::make_shared<CookTorranceShader>(Color(0.83f, 0.69f, 0.22f), Color(1.0f, 0.08f, 0.58f), 1.2f, 0.2f);
auto green = std::make_shared<ToneShader>(mainLight, Color(1, 1, 1), Color(0.1f, 0.6f, 0.1f), Color(0,0,0));
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 white = std::make_shared<SimpleShadowShader>(Color(0.9f, 0.9f, 0.9f));
auto fiona_color = std::make_shared<PhongShader>(Color(0.4f, 1.0f, 0.f), 1.0f, Color(1.0f, 1.0f, 1.0f), 1.0f,
25.0f);
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);
// BRDF
auto gold_metallic_paint2 = std::make_shared<BrdfShader>("../data/BRDF/gold-metallic-paint2.binary",
Color(2.0f, 5.0f, 7.0f));
auto alumina_oxide = std::make_shared<BrdfShader>("../data/BRDF/alumina-oxide.binary", Color(7.0f, 0.0f, 5.0f));
auto chrome_steel = std::make_shared<BrdfShader>("../data/BRDF/chrome-steel.binary", Color(0.0f, 7.0f, 2.0f));
// Make Objects
auto house = std::make_shared<ObjModel>(alumina_oxide);
auto temple = std::make_shared<ObjModel>(gold_metallic_paint2);
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),
Vector3d(20.0f, -6.0f, 10.0f));
temple->loadObj("../data/NewObjects/Random/Temple.obj", Vector3d(0.1f, 0.1f, 0.1f), Vector3d(30.0f, -6.0f, -10.0f));
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), white));
// 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.6f;
cloudSettings.lightAbsorptionThroughCloud = 1.0f;
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(30.0f, 10.0f, 0.0f), Vector3d(75.0f, 10.0f, 75.0f), cloudShader));
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(house);
//scene.add(temple);
//scene.add(std::make_shared<Sphere>(Vector3d(3.0f, -2.0f, -5.0f), 0.5f, mirror));
scene.add(std::make_shared<Sphere>(Vector3d(6.0f, -2.0f, -1.0f), 5.0f, green));
float f = 0.7;
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
SimpleRenderer rendererTest;
SuperRenderer rendererTest;
rendererTest.setSuperSamplingFactor(1);
int width = 512;
Texture imageSceneToTest = rendererTest.renderImage(scene, camera, width, width / 16 * 9);
@ -122,24 +122,24 @@ int main() {
*/
// save images
imageSceneToTest.save("result1.png");
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();
}
}
// 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;
}

152
beautifulSceneDark.cpp Normal file
View file

@ -0,0 +1,152 @@
#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;
}

90
beautifulSceneEpic.cpp Normal file
View file

@ -0,0 +1,90 @@
#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()
{
FastScene scene;
scene.setEnvironmentMap(std::make_shared<Texture>("data/clear_blue_sky.jpg"));
// Light
// Alternative directio Vector3d(0, -.5f, -.5f)
auto mainLight = std::make_shared<SunLight>(Vector3d(0, -0.09f, 1), 2.0f, Color(1, 1, 1));
scene.add(mainLight);
// Set up the camera
PerspectiveCamera camera;
camera.setFovAngle(100.0f);
camera.setPosition(Vector3d(0, .5f, .5f) * 2);
camera.setForwardDirection(Vector3d(0, .5f, .5f));
camera.setUpDirection(Vector3d(0, .5f, -.5f));
// Shader
Vector3d planePosition = Vector3d(0, 3, 4);
auto plane = std::make_shared<ObjModel>(
std::make_shared<ToneShader>(mainLight, Color(1, 1, 1), Color(1, 0.5f, 0.5f), Color(1, 0.5f, 0.5f) * 0.5f));
plane->loadObj("data/FancyPlane/Plane.obj", Vector3d(1.0f, 1.0f, 1.0f) * 0.005f, planePosition);
scene.add(plane);
// Add clouds
auto cloudSettings = CloudSettings();
cloudSettings.seed = 10;
cloudSettings.scale = 40;
cloudSettings.noiseSize = 512;
cloudSettings.lightAbsorptionTowardsLight = 0.05f;
cloudSettings.lightAbsorptionThroughCloud = 1.9f;
cloudSettings.densityOffset = -0.61f;
auto cloudShader = std::make_shared<CloudShader>(cloudSettings);
scene.add(std::make_shared<Box>(Vector3d(0.0f, 15.0f, 30.0f), Vector3d(100.0f, 15.0f, 70.0f), cloudShader));
scene.buildTree();
// Render
// SuperRenderer rendererTest;
// rendererTest.setSuperSamplingFactor(1);
// int width = 512;
// Texture image = rendererTest.renderImage(scene, camera, width, width / 16 * 9);
// initialize renderer: aperture = lens thickness, secondaryRayCount = how many rays per pixel are created
float focalLength = length(camera.getPosition() - planePosition + Vector3d(0, 0, 2.6f));
DOFRenderer renderer(0.02, 100, focalLength);
float imageScalar = 2;
Texture image = renderer.renderImage(scene, camera, 1920 * imageScalar, 1080 * imageScalar);
// 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");
imageWithBloom.save("resultWithBloom.png");
return 0;
}

2667
data/FancyPlane/Plane.obj Normal file

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@ float const TRANSMITTANCE_BREAK = 0.0001f; // If transmittance goes below this
struct CloudSettings
{
int noiseSize = 512; // 64
int noiseSize = 128; // 64
unsigned int seed = 0; // 0 for random seed
float densitySteps = .2f; // .2f
float scale = 30; // 30