BeautifulScene prepared.

This commit is contained in:
Tobias 2023-01-29 17:02:37 +01:00
parent 4baf2901bb
commit a99159dc53

View file

@ -23,45 +23,57 @@
#include <primitive/triangle.h>
#include <shader/simpleshadowshader.h>
#include <light/sunlight.h>
#include "scene/fastscene.h"
#include "shader/toneshader.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));
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,
Color(1, 1, 1));//Color(1, 0.79f, 0.62f));
scene.add(mainLight);
scene.add(std::make_shared<AmbientLight>(0.1f));
// Set up the camera
PerspectiveCamera camera;
camera.setFovAngle(90.0f);
camera.setPosition(Vector3d(0.0f, -2.0f, -5.0f));
camera.setForwardDirection(Vector3d(1.0f, 0.1f, 0.2f));
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.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 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<LambertShader>(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 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 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(7.0f, 7.0f, 7.0f));
auto alumina_oxide = std::make_shared<BrdfShader>("../data/BRDF/alumina-oxide.binary", Color(7.0f, 7.0f, 7.0f));
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);
house->loadObj("../data/NewObjects/house/objBuilding.obj", Vector3d(1.0f, 1.0f, 1.0f), Vector3d(20.0f, -6.0f, 10.0f));
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));
@ -74,7 +86,10 @@ int main()
// Add clouds
auto cloudSettings = CloudSettings();
cloudSettings.scale = 16.0f;
cloudSettings.seed = 42;
cloudSettings.lightAbsorptionTowardsLight = 0.6f;
cloudSettings.lightAbsorptionThroughCloud = 1.0f;
cloudSettings.densityOffset = -0.65f;
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));
@ -82,22 +97,15 @@ int main()
// Insert Objects
scene.add(house);
scene.add(temple);
scene.add(std::make_shared<Sphere>(Vector3d(3.0f, -2.0f, -5.0f), 0.5f, mirror));
// Light
auto mainLight = std::make_shared<SunLight>(Vector3d(-10.0f, -0.5f, -1.0f), 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(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));
// Render
SimpleRenderer rendererTest;
int width = 1920;
Texture imageSceneToTest = rendererTest.renderImage(scene, camera, width, width/16 * 9);
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
@ -114,17 +122,17 @@ int main()
*/
// save images
// imageSceneToTest.save("result.png");
// image.save("result.png");
// image.save("resultWithBloom");
imageSceneToTest.save("result1.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);
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);
CImgDisplay disp(img_8bit, "My Rendered Image", 0, false, false);
while (!disp.is_closed()) {
disp.wait();
disp.display(img_8bit);