Compare commits
11 commits
9608281164
...
4994a23a8a
Author | SHA1 | Date | |
---|---|---|---|
4994a23a8a | |||
159e9ca843 | |||
8988af2e0f | |||
|
2d996602a4 | ||
|
e4305190ea | ||
|
a99159dc53 | ||
4baf2901bb | |||
a4d7ccc1a5 | |||
9b07411ebd | |||
9837920c38 | |||
|
ed47dc2b9b |
25 changed files with 3456 additions and 141 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,6 +7,7 @@ build/
|
|||
/data/*
|
||||
!/data/README.txt
|
||||
!/data/fireplace
|
||||
!/data/FancyPlane
|
||||
!/data/Bus
|
||||
!/data/subdiv
|
||||
!/data/parallax
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
@ -78,6 +84,12 @@ endif()
|
|||
add_executable(fancy1 fancy1.cpp)
|
||||
target_link_libraries(fancy1 tracey)
|
||||
|
||||
add_executable(bloom bloom.cpp)
|
||||
target_link_libraries(bloom tracey)
|
||||
|
||||
add_executable(DOFScene DOFScene.cpp)
|
||||
target_link_libraries(DOFScene tracey)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
|
||||
|
|
123
DOFScene.cpp
Normal file
123
DOFScene.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <shader/refractionshader.h>
|
||||
|
||||
#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<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));
|
||||
auto glass = std::make_shared<RefractionShader>(1.31f, 1.0f);
|
||||
|
||||
|
||||
|
||||
|
||||
// Set up the walls
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
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));
|
||||
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(-5.0f, 0.0f, 0.0f), 1.0f, blueMetallic));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(-2.0f, 5.0f, 0.0f), 1.0f, orange));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(2.0f, 4.0f, 0.0f), 1.0f, orange));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(3.0f, 4.0f, -2.0f), 1.0f, glass));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(2.0f, 3.0f, 4.0f), 1.0f, orange));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(-3.0f, 3.0f, 2.0f), 1.0f, orange));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(2.0f, 1.0f, 0.0f), 1.0f, mirror));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(3.0f, -3.0f, 0.0f), 1.0f, darkRed));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(5.0f, 0.0f, 0.0f), 1.0f, darkRed));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(-5.0f, -3.3f, -4.0f), 1.0f, mirror));
|
||||
|
||||
// Add the teapot
|
||||
auto ship = std::make_shared<ObjModel>(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<AmbientLight>(0.15f));
|
||||
scene.add(std::make_shared<PointLight>(Vector3d(0.0f, 4.0f, -4.0f), 7.0f));
|
||||
scene.add(std::make_shared<PointLight>(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<float> CImgOfImage = image.getImage();
|
||||
CImg<unsigned char> 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;
|
||||
}
|
|
@ -1,20 +1,145 @@
|
|||
#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()
|
||||
{
|
||||
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.setBackgroundColor(Color(0.1, 0.1, 0.1));
|
||||
|
||||
// Light
|
||||
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>(.1f));
|
||||
|
||||
// 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.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.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
|
||||
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;
|
||||
}
|
152
beautifulSceneDark.cpp
Normal file
152
beautifulSceneDark.cpp
Normal 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;
|
||||
}
|
88
beautifulSceneEpic.cpp
Normal file
88
beautifulSceneEpic.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
#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 = 1;
|
||||
Texture image = renderer.renderImage(scene, camera, 1920 * imageScalar, 1080 * imageScalar);
|
||||
|
||||
image.save("result.png");
|
||||
|
||||
// Use post-processing Bloom effect
|
||||
Bloom bloomEffect = Bloom(image.getImage(), 0.88f, image);
|
||||
image.setTexture(bloomEffect.bloom(50, 20.0f, 0.5f));
|
||||
image.save("resultWithBloom.png");
|
||||
|
||||
return 0;
|
||||
}
|
60
bloom.cpp
Normal file
60
bloom.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <post_processing/bloom.h>
|
||||
#include <shader/phongshader.h>
|
||||
#include <shader/simpleshadowshader.h>
|
||||
#include <light/pointlight.h>
|
||||
|
||||
#include "camera/perspectivecamera.h"
|
||||
|
||||
#include "renderer/simplerenderer.h"
|
||||
|
||||
#include "scene/simplescene.h"
|
||||
|
||||
#include "primitive/box.h"
|
||||
#include "primitive/infiniteplane.h"
|
||||
#include "primitive/sphere.h"
|
||||
#include "primitive/triangle.h"
|
||||
|
||||
|
||||
int main() {
|
||||
SimpleScene scene;
|
||||
|
||||
scene.setBackgroundColor(Color(0, 0, 0));
|
||||
|
||||
// Add shaders
|
||||
auto red = std::make_shared<SimpleShadowShader>(Color(1.0f, 0.3f, 0.2f));
|
||||
auto gray = std::make_shared<SimpleShadowShader>(Color(0.78f, 0.78f, 0.78f));
|
||||
auto blue = std::make_shared<SimpleShadowShader>(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);
|
||||
|
||||
|
||||
scene.add(std::make_shared<Box>(Vector3d(5.0f, -5.0f, 0.0f), Vector3d(4.0f, 4.0f, 4.0f), red));
|
||||
scene.add(std::make_shared<Box>(Vector3d(-5.0f, -3.0f, 1.0f), Vector3d(1.0f, 6.0f, 1.0f), blue));
|
||||
scene.add(std::make_shared<Box>(Vector3d(-3.5f, 4.0f, -2.0f), Vector3d(2.0f, 2.0f, 2.0f), orange));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(2.0f, 4.0f, 0.0f), 1.0f, orange));
|
||||
|
||||
scene.add(std::make_shared<PointLight>(Vector3d(0.0f, 0.0f, -11.0f), 100.0f));
|
||||
|
||||
|
||||
|
||||
// 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));
|
||||
|
||||
// Render the scene
|
||||
SimpleRenderer renderer;
|
||||
Texture img = renderer.renderImage(scene, camera, 512, 512);
|
||||
|
||||
img.save("beforeBloom.png");
|
||||
|
||||
Bloom bloom = Bloom(img.getImage(), 0.88f, img);
|
||||
img.setTexture(bloom.bloom(100, 300.0f, 1.5f));
|
||||
|
||||
img.save("afterBloom.png");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,21 +1,50 @@
|
|||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include "cloudnoise.h"
|
||||
#include "worleynoise.h"
|
||||
#include "perlinnoise.h"
|
||||
|
||||
CloudNoise::CloudNoise(int size, unsigned int seed) : Noise(size)
|
||||
CloudNoise::CloudNoise(int size, unsigned int seed) : Noise(size), worleyNoise1(WorleyNoise(std::min(LOWRES_SIZE, size), 3, seed)),
|
||||
worleyNoise3(WorleyNoise(size, 15, seed)),
|
||||
perlinNoise1(PerlinNoise(std::min(LOWRES_SIZE, size), 3, seed)),
|
||||
perlinNoise2(PerlinNoise(size, 15, seed))
|
||||
{
|
||||
int minSize = std::min(32, size);
|
||||
|
||||
// Some worley noises
|
||||
WorleyNoise worleyNoise1(minSize, 3, seed);
|
||||
WorleyNoise worleyNoise3(size, 15, seed);
|
||||
|
||||
// Some perlin noises
|
||||
PerlinNoise perlinNoise1(minSize, 3, seed);
|
||||
PerlinNoise perlinNoise2(size, 15, seed);
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Generate the noise
|
||||
for (int x = 0; x < size; x++)
|
||||
int const nThreads = (int) std::thread::hardware_concurrency() - 1;
|
||||
int threadSize = std::floor((float) size / (float) nThreads);
|
||||
int remaining = size - nThreads * threadSize;
|
||||
std::vector<std::thread> threads;
|
||||
for (int n = 0; n < nThreads; n++)
|
||||
{
|
||||
threads.emplace_back(runCloudNoiseInThread, n * threadSize, threadSize, this);
|
||||
}
|
||||
|
||||
renderNoiseThread(nThreads * threadSize, remaining);
|
||||
|
||||
// Rejoin the threads
|
||||
for (int t = 0; t < nThreads; ++t)
|
||||
{
|
||||
threads[t].join();
|
||||
}
|
||||
|
||||
// Duration of computation
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(stop - start);
|
||||
|
||||
std::cout << "Finished computing Cloud noise for size " << size << " in "
|
||||
<< duration.count() << " seconds" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void CloudNoise::runCloudNoiseInThread(int xOffset, int xSize, CloudNoise *noise)
|
||||
{
|
||||
noise->renderNoiseThread(xOffset, xSize);
|
||||
}
|
||||
|
||||
void CloudNoise::renderNoiseThread(int xOffset, int xSize)
|
||||
{
|
||||
for (int x = xOffset; x < xOffset + xSize; x++)
|
||||
{
|
||||
for (int y = 0; y < size; y++)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
|
||||
#include "noise.h"
|
||||
#include "worleynoise.h"
|
||||
#include "perlinnoise.h"
|
||||
|
||||
int const LOWRES_SIZE = 32;
|
||||
|
||||
class CloudNoise : public Noise
|
||||
{
|
||||
|
@ -12,7 +16,20 @@ public:
|
|||
* @param size
|
||||
* @param seed 0 for random seed
|
||||
*/
|
||||
CloudNoise(int size, unsigned int seed = 0);
|
||||
explicit CloudNoise(int size, unsigned int seed = 0);
|
||||
|
||||
void renderNoiseThread(int xOffset, int xSize);
|
||||
|
||||
private:
|
||||
// Some worley noises
|
||||
WorleyNoise worleyNoise1;
|
||||
WorleyNoise worleyNoise3;
|
||||
|
||||
// Some perlin noises
|
||||
PerlinNoise perlinNoise1;
|
||||
PerlinNoise perlinNoise2;
|
||||
|
||||
static void runCloudNoiseInThread(int xOffset, int xSize, CloudNoise *noise);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <random>
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include "perlinnoise.h"
|
||||
|
||||
Vector3d PerlinNoise::randomGradient()
|
||||
|
@ -72,6 +74,8 @@ PerlinNoise::PerlinNoise(int size, int gridSize, unsigned int seed) : Noise(size
|
|||
|
||||
void PerlinNoise::generateNoise()
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Generate gradients
|
||||
gradients.clear();
|
||||
gradients.resize(pow(gridSize, 3));
|
||||
|
@ -81,15 +85,21 @@ void PerlinNoise::generateNoise()
|
|||
}
|
||||
|
||||
// Generate each pixel
|
||||
for (int x = 0; x < size; x++)
|
||||
int const nThreads = (int) std::thread::hardware_concurrency() - 1;
|
||||
int threadSize = std::floor((float) size / (float) nThreads);
|
||||
int remaining = size - nThreads * threadSize;
|
||||
std::vector<std::thread> threads;
|
||||
for (int n = 0; n < nThreads; n++)
|
||||
{
|
||||
for (int y = 0; y < size; y++)
|
||||
{
|
||||
for (int z = 0; z < size; z++)
|
||||
{
|
||||
setNoise(x, y, z, getGradientValue(x, y, z));
|
||||
}
|
||||
threads.emplace_back(runPerlinNoiseInThread, n * threadSize, threadSize, this);
|
||||
}
|
||||
|
||||
renderNoiseThread(nThreads * threadSize, remaining);
|
||||
|
||||
// Rejoin the threads
|
||||
for (int t = 0; t < nThreads; ++t)
|
||||
{
|
||||
threads[t].join();
|
||||
}
|
||||
|
||||
// Normalize cloudNoise map to [0, 1]
|
||||
|
@ -100,6 +110,32 @@ void PerlinNoise::generateNoise()
|
|||
{
|
||||
value = (value - min) / (max - min);
|
||||
});
|
||||
|
||||
// Duration of computation
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(stop - start);
|
||||
|
||||
std::cout << "Finished computing Perlin noise for size " << size << " and grid size " << gridSize << " in "
|
||||
<< duration.count() << " seconds" << std::endl;
|
||||
}
|
||||
|
||||
void PerlinNoise::runPerlinNoiseInThread(int xOffset, int xSize, PerlinNoise *noise)
|
||||
{
|
||||
noise->renderNoiseThread(xOffset, xSize);
|
||||
}
|
||||
|
||||
void PerlinNoise::renderNoiseThread(int xOffset, int xSize)
|
||||
{
|
||||
for (int x = xOffset; x < xOffset + xSize; x++)
|
||||
{
|
||||
for (int y = 0; y < size; y++)
|
||||
{
|
||||
for (int z = 0; z < size; z++)
|
||||
{
|
||||
setNoise(x, y, z, getGradientValue(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float PerlinNoise::getCornerValue(Vector3d position, Vector3d corner)
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
*/
|
||||
PerlinNoise(int size, int gridSize, unsigned int seed = 0);
|
||||
|
||||
void renderNoiseThread(int xOffset, int xSize);
|
||||
private:
|
||||
void generateNoise();
|
||||
std::normal_distribution<float> distribution;
|
||||
|
@ -29,6 +30,9 @@ private:
|
|||
float getGradientValue(int x, int y, int z);
|
||||
|
||||
float getCornerValue(Vector3d position, Vector3d corner);
|
||||
|
||||
static void runPerlinNoiseInThread(int xOffset, int xSize, PerlinNoise *noise);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include "worleynoise.h"
|
||||
#include "common/vector3d.h"
|
||||
|
||||
void WorleyNoise::runWorleyNoiseInThread(int xOffset, int xSize, WorleyNoise *noise)
|
||||
{
|
||||
noise->renderNoiseThread(xOffset, xSize);
|
||||
}
|
||||
|
||||
void WorleyNoise::generateNoise()
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
@ -36,7 +42,43 @@ void WorleyNoise::generateNoise()
|
|||
noiseMap.clear();
|
||||
noiseMap.resize(size * size * size);
|
||||
|
||||
for (int x = 0; x < size; x++)
|
||||
int const nThreads = (int) std::thread::hardware_concurrency() - 1;
|
||||
int threadSize = std::floor((float) size / (float) nThreads);
|
||||
int remaining = size - nThreads * threadSize;
|
||||
std::vector<std::thread> threads;
|
||||
for (int n = 0; n < nThreads; n++)
|
||||
{
|
||||
threads.emplace_back(runWorleyNoiseInThread, n * threadSize, threadSize, this);
|
||||
}
|
||||
|
||||
renderNoiseThread(nThreads * threadSize, remaining);
|
||||
|
||||
// Rejoin the threads
|
||||
for (int t = 0; t < nThreads; ++t)
|
||||
{
|
||||
threads[t].join();
|
||||
}
|
||||
|
||||
// Normalize cloudNoise map to [0, 1]
|
||||
float min = *std::min_element(noiseMap.begin(), noiseMap.end());
|
||||
float max = *std::max_element(noiseMap.begin(), noiseMap.end());
|
||||
|
||||
std::for_each(noiseMap.begin(), noiseMap.end(), [min, max](float &value)
|
||||
{
|
||||
value = (value - min) / (max - min);
|
||||
});
|
||||
|
||||
// Duration of computation
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(stop - start);
|
||||
|
||||
std::cout << "Finished computing Worley noise for size " << size << " and " << numberOfPoints << " points in "
|
||||
<< duration.count() << " seconds" << std::endl;
|
||||
}
|
||||
|
||||
void WorleyNoise::renderNoiseThread(int xOffset, int xSize)
|
||||
{
|
||||
for (int x = xOffset; x < xOffset + xSize; x++)
|
||||
{
|
||||
for (int y = 0; y < size; y++)
|
||||
{
|
||||
|
@ -48,22 +90,6 @@ void WorleyNoise::generateNoise()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize getNoise map to [0, 1]
|
||||
float min = *std::min_element(noiseMap.begin(), noiseMap.end());
|
||||
float max = *std::max_element(noiseMap.begin(), noiseMap.end());
|
||||
|
||||
for (int i = 0; i < noiseMap.size(); i++)
|
||||
{
|
||||
noiseMap[i] = (noiseMap[i] - min) / (max - min);
|
||||
}
|
||||
|
||||
// Duration of computation
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(stop - start);
|
||||
|
||||
std::cout << "Finished computing Worley noise for size " << size << " and " << numberOfPoints << " points in "
|
||||
<< duration.count() << " seconds" << std::endl;
|
||||
}
|
||||
|
||||
WorleyNoise::WorleyNoise(int size, int numberOfPoints, unsigned int seed) : numberOfPoints(numberOfPoints), Noise(size)
|
||||
|
|
|
@ -18,6 +18,8 @@ public:
|
|||
*/
|
||||
WorleyNoise(int size, int numberOfPoints, unsigned int seed = 0);
|
||||
|
||||
void renderNoiseThread(int xOffset, int xSize);
|
||||
|
||||
protected:
|
||||
int numberOfPoints;
|
||||
std::vector<Vector3d> points; // 3D-Array, each cell represents a subcell. There are numberOfPoints^3 subcells.
|
||||
|
@ -32,6 +34,8 @@ protected:
|
|||
void generateNoise();
|
||||
|
||||
std::vector<Vector3d> getSubcellPoints(Vector3d point);
|
||||
|
||||
static void runWorleyNoiseInThread(int xOffset, int xSize, WorleyNoise *noise);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ Color Texture::color(Vector2d const &surfacePosition, bool interpolate) const {
|
|||
return color(surfacePosition.u, surfacePosition.v, interpolate);
|
||||
}
|
||||
|
||||
CImg<float> Texture::getImage() {
|
||||
CImg<float>& Texture::getImage() {
|
||||
return image_;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
Color color(float u, float v, bool interpolate = true) const;
|
||||
Color color(Vector2d const &surfacePosition, bool interpolate = true) const;
|
||||
|
||||
CImg<float> getImage();
|
||||
CImg<float>& getImage();
|
||||
|
||||
private:
|
||||
CImg<float> image_;
|
||||
|
|
2667
data/FancyPlane/Plane.obj
Normal file
2667
data/FancyPlane/Plane.obj
Normal file
File diff suppressed because it is too large
Load diff
|
@ -50,9 +50,9 @@ int main()
|
|||
// scene.add(std::make_shared<Box>(Vector3d(9.0f, 3.0f, 12.0f), Vector3d(3.0f, 3.0f, 3.0f), boxShader1));
|
||||
|
||||
// Add floor
|
||||
// auto floorShader = std::make_shared<SimpleShadowShader>(Color(0.9f, 0.9f, 0.9f));
|
||||
// scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, 0.0f, 0.0f), Vector3d(0.0f, 1.0f, 0.0f),
|
||||
// floorShader));
|
||||
auto floorShader = std::make_shared<SimpleShadowShader>(Color(0.9f, 0.9f, 0.9f));
|
||||
scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, 0.0f, 0.0f), Vector3d(0.0f, 1.0f, 0.0f),
|
||||
floorShader));
|
||||
|
||||
// Add box for volume shader
|
||||
auto cloudSettings = CloudSettings();
|
||||
|
@ -72,7 +72,7 @@ int main()
|
|||
// Render the scene
|
||||
SuperRenderer sr;
|
||||
sr.setSuperSamplingFactor(1);
|
||||
sr.renderImage(scene, camera, 512, 512).save("result.png");
|
||||
sr.renderImage(scene, camera, 2048, 2048).save("result.png");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
int main() {
|
||||
// Let's create a simple cornell box scene...
|
||||
SimpleScene scene;
|
||||
scene.setEnvironmentMap(std::make_shared<Texture>("data/lion_env.png"));
|
||||
scene.setEnvironmentMap(std::make_shared<Texture>("../data/lion_env.png"));
|
||||
|
||||
auto mirror = std::make_shared<MirrorShader>();
|
||||
auto glass = std::make_shared<RefractionShader>(1.31f, 1.0f);
|
||||
|
|
|
@ -44,8 +44,6 @@ int main() {
|
|||
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;
|
||||
|
||||
|
||||
// Set up the walls
|
||||
|
@ -88,14 +86,10 @@ int main() {
|
|||
// 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");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,36 +2,27 @@
|
|||
#include <iostream>
|
||||
#include "bloom.h"
|
||||
|
||||
Bloom::Bloom(CImg<float> image) : image(image) {}
|
||||
Bloom::Bloom(CImg<float> &image, float threshold, Texture& thresholdImg) : image(image), threshold(threshold) {}
|
||||
|
||||
|
||||
CImg<float> Bloom::bloom(float threshold, int kernelSize, float sigma, float intensity) {
|
||||
// Apply threshold to image
|
||||
//CImg<float> brightPixels = image_.get_threshold(threshold);
|
||||
//brightPixels.save("brightpixels.png");
|
||||
CImg<float> Bloom::bloom(int kernelSize, float sigma, float intensity) {
|
||||
|
||||
CImg<float> brightPixels = image.get_threshold(threshold);
|
||||
|
||||
// Apply gaussian blur to bright pixels
|
||||
CImg<float> kernel = computeGaussianKernel(kernelSize, sigma);
|
||||
CImg<float> blurred = convolution(image, kernel);
|
||||
for(int i = 0; i < 3; i++){
|
||||
kernel = computeGaussianKernel(kernelSize, sigma);
|
||||
blurred = convolution(image, kernel);
|
||||
blurred *= intensity;
|
||||
}
|
||||
|
||||
// Add blurred image back to original image
|
||||
cimg_forXYC(image, x, y, c) {
|
||||
float value = image(x,y,0,c) + blurred(x,y,0,c);
|
||||
image(x,y,0,c) = (value > 1.0f) ? 1.0f : value;
|
||||
float value = image(x, y, 0, c) + blurred(x, y, 0, c);
|
||||
image(x, y, 0, c) = (value > 1.0f) ? 1.0f : value;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
void Bloom::gaussianBlur(int kernelSize, float sigma) {
|
||||
CImg<float> kernel = computeGaussianKernel(kernelSize, sigma);
|
||||
image = convolution(image, kernel);
|
||||
}
|
||||
|
||||
// Function to compute Gaussian kernel
|
||||
CImg<float> Bloom::computeGaussianKernel(int kernelSize, float sigma) {
|
||||
|
@ -72,7 +63,7 @@ CImg<float> Bloom::convolution(CImg<float> &img, CImg<float> &kernel) {
|
|||
cimg_forX(kernel, n) {
|
||||
int x = i + n - kernelRadius;
|
||||
int y = j + m - kernelRadius;
|
||||
if(x >= 0 && x < imgCols && y >= 0 && y < imgRows){
|
||||
if (x >= 0 && x < imgCols && y >= 0 && y < imgRows) {
|
||||
sum += img(x, y, 0, c) * kernel(n, m);
|
||||
}
|
||||
|
||||
|
@ -82,7 +73,3 @@ CImg<float> Bloom::convolution(CImg<float> &img, CImg<float> &kernel) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Bloom::scaleBrightness(float scale) {
|
||||
image *= scale;
|
||||
}
|
||||
|
|
|
@ -8,19 +8,17 @@
|
|||
class Bloom {
|
||||
|
||||
public:
|
||||
Bloom(CImg<float> image);
|
||||
CImg<float> bloom(float threshold, int kernelSize, float sigma, float intensity);
|
||||
Bloom(CImg<float>& image, float threshold, Texture& thresholdImg);
|
||||
CImg<float> bloom(int kernelSize, float sigma, float intensity);
|
||||
|
||||
private:
|
||||
void scaleBrightness(float scale);
|
||||
void gaussianBlur(int kernelSize, float sigma);
|
||||
|
||||
CImg<float> convolution(CImg<float> &img, CImg<float> &kernel);
|
||||
CImg<float> computeGaussianKernel(int kernelSize, float sigma);
|
||||
|
||||
|
||||
|
||||
CImg<float> image;
|
||||
|
||||
float threshold;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <chrono>
|
||||
#include "depthoffieldrenderer.h"
|
||||
#include <iomanip>
|
||||
#include "post_processing/bloom.h"
|
||||
|
||||
|
||||
DOFRenderer::DOFRenderer(float _aperture, int _secondaryRayCount, float _focalLength) : aperture(_aperture),
|
||||
|
@ -112,13 +111,6 @@ Texture DOFRenderer::renderImage(Scene const &scene, Camera const &camera, int w
|
|||
std::cout << "Paths: " << rays << std::endl;
|
||||
std::cout << "Paths per second: " << std::fixed << std::setprecision(0) << rays / seconds << std::endl;
|
||||
|
||||
// Post-processing
|
||||
// Bloom shader
|
||||
|
||||
image.save("original.png");
|
||||
|
||||
Bloom bloomEffect = Bloom(image.getImage());
|
||||
image.setTexture(bloomEffect.bloom(0.55f, 5, 10.0f, 0.06f));
|
||||
|
||||
return image;
|
||||
}
|
|
@ -69,7 +69,7 @@ bool CloudShader::isTransparent() const
|
|||
}
|
||||
|
||||
CloudShader::CloudShader(const CloudSettings &settings) : settings(settings),
|
||||
cloudNoise(CloudNoise(NOISE_SIZE, settings.seed))
|
||||
cloudNoise(CloudNoise(settings.noiseSize, settings.seed))
|
||||
{
|
||||
cloudNoise.invert = true;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
#include "primitive/primitive.h"
|
||||
#include "common/noise/worleynoise.h"
|
||||
|
||||
int const NOISE_SIZE = 64;
|
||||
float const TRANSMITTANCE_BREAK = 0.0001f; // If transmittance goes below this limit, the cloud is considered opaque
|
||||
|
||||
struct CloudSettings
|
||||
{
|
||||
int noiseSize = 128; // 64
|
||||
unsigned int seed = 0; // 0 for random seed
|
||||
float densitySteps = .2f; // .2f
|
||||
float scale = 30; // 30
|
||||
|
|
Loading…
Reference in a new issue