-
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 SolidColor texture, checkered texture and a scene
- Loading branch information
Showing
12 changed files
with
208 additions
and
15 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
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,79 @@ | ||
|
||
#include "checkered_spheres_scene.hpp" | ||
|
||
#include "geometry/hittable_list.hpp" | ||
#include "geometry/hittable_list.hpp" | ||
#include "geometry/sphere.hpp" | ||
#include "material/lambertian.hpp" | ||
#include "texture/checker_texture.hpp" | ||
#include "renderer/camera.hpp" | ||
#include "renderer/pathtracing_renderer.hpp" | ||
|
||
#include <memory> | ||
|
||
|
||
using namespace std; | ||
|
||
|
||
shared_ptr<Camera> CheckeredSpheresScene::InitCamera() | ||
{ | ||
CameraParams camera_params; | ||
camera_params.aspect_ratio = 16.0 / 9.0; | ||
camera_params.image_width = m_params.render_width; | ||
camera_params.vfov = 20.0; | ||
camera_params.lookfrom = Point3(13,2,3); | ||
camera_params.lookat = Point3(0,0,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> CheckeredSpheresScene::InitObjects() | ||
{ | ||
auto hittable_list = make_shared<HittableList>(); | ||
|
||
auto checker = make_shared<CheckerTexture>( | ||
0.32, | ||
RGBColor(0.2, 0.3, 0.1), | ||
RGBColor(0.9, 0.9, 0.9) | ||
); | ||
|
||
hittable_list->AddObject( | ||
make_shared<Sphere>(Point3(0,-10, 0), 10, make_shared<Lambertian>(checker)) | ||
); | ||
|
||
hittable_list->AddObject( | ||
make_shared<Sphere>(Point3(0, 10, 0), 10, make_shared<Lambertian>(checker)) | ||
); | ||
|
||
return hittable_list; | ||
} | ||
|
||
|
||
shared_ptr<PathTracingRenderer> CheckeredSpheresScene::InitRenderer() | ||
{ | ||
PathTracingRendererParams params; | ||
params.aa_sample_per_pixel = 100; | ||
params.max_depth = 20; | ||
|
||
return make_shared<PathTracingRenderer>(m_camera, m_objets, move(params)); | ||
} | ||
|
||
|
||
void CheckeredSpheresScene::Build(SceneParams &¶ms) | ||
{ | ||
m_params = params; | ||
m_camera = InitCamera(); | ||
m_objets = InitObjects(); | ||
m_renderer = InitRenderer(); | ||
} | ||
|
||
|
||
shared_ptr<RGBColor[]> CheckeredSpheresScene::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 CheckeredSpheresScene: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
#pragma once | ||
|
||
#include "math/vec.hpp" | ||
|
||
|
||
class ITexture { | ||
|
||
public: | ||
|
||
virtual ~ITexture() = default; | ||
virtual RGBColor GetColor(double u, double v, const Point3& point) const = 0; | ||
|
||
}; |
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,41 @@ | ||
|
||
#pragma once | ||
|
||
#include "texture/ITexture.hpp" | ||
#include "texture/solid_color_texture.hpp" | ||
|
||
#include <memory> | ||
|
||
|
||
class CheckerTexture : public ITexture { | ||
|
||
private: | ||
|
||
double m_inv_scale; | ||
std::shared_ptr<ITexture> m_even_texture; | ||
std::shared_ptr<ITexture> m_odd_texture; | ||
|
||
|
||
public: | ||
|
||
CheckerTexture(double scale, std::shared_ptr<ITexture> even, std::shared_ptr<ITexture> odd) | ||
: m_inv_scale{1.0 / scale}, m_even_texture{even}, m_odd_texture{odd} {} | ||
|
||
CheckerTexture(double scale, const RGBColor& even, const RGBColor& odd) | ||
: m_inv_scale{1.0 / scale}, | ||
m_even_texture{std::make_shared<SolidColorTexture>(even)}, | ||
m_odd_texture{std::make_shared<SolidColorTexture>(odd)} | ||
{} | ||
|
||
|
||
RGBColor GetColor(double u, double v, const Point3& point) const override { | ||
int x_value = int(std::floor(m_inv_scale * point[0])); | ||
int y_value = int(std::floor(m_inv_scale * point[1])); | ||
int z_value = int(std::floor(m_inv_scale * point[2])); | ||
|
||
bool is_even = (x_value + y_value + z_value) % 2 == 0; | ||
|
||
return is_even ? m_even_texture->GetColor(u, v, point) : m_odd_texture->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#pragma once | ||
|
||
#include "texture/ITexture.hpp" | ||
|
||
|
||
class SolidColorTexture : public ITexture { | ||
|
||
private: | ||
|
||
RGBColor m_albedo; | ||
|
||
|
||
public: | ||
|
||
SolidColorTexture(const RGBColor& color): m_albedo{color} {} | ||
SolidColorTexture(double r, double g, double b): m_albedo{RGBColor(r, g, b)} {} | ||
|
||
RGBColor GetColor(double u, double v, const Point3& point) const override { | ||
return m_albedo; | ||
} | ||
|
||
}; |