-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add emissive materials and cornell box scene
- Loading branch information
Showing
14 changed files
with
173 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "material/IMaterial.hpp" | ||
#include "texture/solid_color_texture.hpp" | ||
|
||
|
||
class DiffuseLight : public IMaterial { | ||
|
||
private: | ||
|
||
std::shared_ptr<ITexture> m_albedo; | ||
|
||
|
||
public: | ||
|
||
DiffuseLight(const RGBColor& albedo): m_albedo{std::make_shared<SolidColorTexture>(albedo)} {}; | ||
DiffuseLight(std::shared_ptr<ITexture> albedo): m_albedo{albedo} {}; | ||
|
||
RGBColor Emitted(double u, double v, const Point3& point) const override | ||
{ | ||
return m_albedo->GetColor(u, v, point); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
#include "cornell_box_scene.hpp" | ||
|
||
#include "geometry/hittable_list.hpp" | ||
#include "geometry/hittable_list.hpp" | ||
#include "geometry/quad.hpp" | ||
#include "material/lambertian.hpp" | ||
#include "material/diffuse_light.hpp" | ||
#include "texture/checker_texture.hpp" | ||
#include "renderer/camera.hpp" | ||
#include "renderer/pathtracing_renderer.hpp" | ||
|
||
#include <memory> | ||
|
||
|
||
using namespace std; | ||
|
||
|
||
shared_ptr<Camera> CornellBoxScene::InitCamera() | ||
{ | ||
CameraParams camera_params; | ||
camera_params.aspect_ratio = 1.0; | ||
camera_params.image_width = m_params.render_width; | ||
camera_params.vfov = 40.0; | ||
camera_params.lookfrom = Point3(278, 278, -800); | ||
camera_params.lookat = Point3(278, 278, 0); | ||
camera_params.vup = Vec3(0,1,0); | ||
camera_params.defocus_angle = 0.0; | ||
camera_params.focus_dist = 10.0; | ||
|
||
return make_shared<Camera>(std::move(camera_params)); | ||
} | ||
|
||
|
||
shared_ptr<HittableList> CornellBoxScene::InitObjects() | ||
{ | ||
auto hittable_list = make_shared<HittableList>(); | ||
|
||
auto red = make_shared<Lambertian>(RGBColor(.65, .05, .05)); | ||
auto white = make_shared<Lambertian>(RGBColor(.73, .73, .73)); | ||
auto green = make_shared<Lambertian>(RGBColor(.12, .45, .15)); | ||
auto light = make_shared<DiffuseLight>(RGBColor(15, 15, 15)); | ||
|
||
hittable_list->AddObjects({ | ||
make_shared<Quad>(Point3(555,0,0), Vec3(0,555,0), Vec3(0,0,555), green), | ||
make_shared<Quad>(Point3(0,0,0), Vec3(0,555,0), Vec3(0,0,555), red), | ||
make_shared<Quad>(Point3(343, 554, 332), Vec3(-130,0,0), Vec3(0,0,-105), light), | ||
make_shared<Quad>(Point3(0,0,0), Vec3(555,0,0), Vec3(0,0,555), white), | ||
make_shared<Quad>(Point3(555,555,555), Vec3(-555,0,0), Vec3(0,0,-555), white), | ||
make_shared<Quad>(Point3(0,0,555), Vec3(555,0,0), Vec3(0,555,0), white) | ||
}); | ||
|
||
return hittable_list; | ||
} | ||
|
||
|
||
shared_ptr<PathTracingRenderer> CornellBoxScene::InitRenderer() | ||
{ | ||
PathTracingRendererParams params; | ||
params.aa_sample_per_pixel = 1600; | ||
params.max_depth = 20; | ||
params.background_color = BLACK; | ||
|
||
return make_shared<PathTracingRenderer>(m_camera, m_objets, move(params)); | ||
} | ||
|
||
|
||
void CornellBoxScene::Build(SceneParams &¶ms) | ||
{ | ||
m_params = params; | ||
m_camera = InitCamera(); | ||
m_objets = InitObjects(); | ||
m_renderer = InitRenderer(); | ||
} | ||
|
||
|
||
shared_ptr<RGBColor[]> CornellBoxScene::Render() | ||
{ | ||
m_renderer->Render(); | ||
return m_renderer->GetBuffer(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
#pragma once | ||
|
||
#include "scenes/IScene.hpp" | ||
|
||
|
||
class Camera; | ||
class HittableList; | ||
class PathTracingRenderer; | ||
|
||
class CornellBoxScene: public IScene { | ||
|
||
private: | ||
|
||
std::shared_ptr<Camera> InitCamera(); | ||
std::shared_ptr<HittableList> InitObjects(); | ||
std::shared_ptr<PathTracingRenderer> InitRenderer(); | ||
|
||
|
||
public: | ||
|
||
void Build(SceneParams&& params) override; | ||
std::shared_ptr<RGBColor[]> Render() override; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters