Skip to content

Commit

Permalink
add scene
Browse files Browse the repository at this point in the history
  • Loading branch information
GraphicsEnthusiast committed Jan 15, 2024
1 parent 4fd0f00 commit d30eb19
Show file tree
Hide file tree
Showing 26 changed files with 675,790 additions and 19 deletions.
6 changes: 3 additions & 3 deletions core/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ Spectrum MetalWorkflow::Sample(const Vector3f& V, Vector3f& L, float& pdf, const
return brdf;
}

Spectrum ClearCoatedConductor::Evaluate(const Vector3f& V, const Vector3f& L, float& pdf, const IntersectionInfo& info) {
Spectrum ClearcoatedConductor::Evaluate(const Vector3f& V, const Vector3f& L, float& pdf, const IntersectionInfo& info) {
float alpha_u = glm::pow2(roughnessTexture_u->GetColor(info.uv)[0]);
float alpha_v = glm::pow2(roughnessTexture_v->GetColor(info.uv)[0]);

Expand Down Expand Up @@ -744,7 +744,7 @@ Spectrum ClearCoatedConductor::Evaluate(const Vector3f& V, const Vector3f& L, fl
return brdf;
}

Spectrum ClearCoatedConductor::Sample(const Vector3f& V, Vector3f& L, float& pdf, const IntersectionInfo& info, std::shared_ptr<Sampler> sampler) {
Spectrum ClearcoatedConductor::Sample(const Vector3f& V, Vector3f& L, float& pdf, const IntersectionInfo& info, std::shared_ptr<Sampler> sampler) {
float alpha_u = glm::pow2(roughnessTexture_u->GetColor(info.uv)[0]);
float alpha_v = glm::pow2(roughnessTexture_v->GetColor(info.uv)[0]);

Expand Down Expand Up @@ -930,7 +930,7 @@ std::shared_ptr<Material> Material::Create(const MaterialParams& params) {
params.metallicTexture, params.normalTexture);
}
else if (params.type == MaterialType::ClearcoatedConductorMaterial) {
return std::make_shared<ClearCoatedConductor>(params.conductor, params.roughnessTexture_u, params.roughnessTexture_v,
return std::make_shared<ClearcoatedConductor>(params.conductor, params.roughnessTexture_u, params.roughnessTexture_v,
params.coatWeight, params.normalTexture);
}
else if(params.type == MaterialType::DiffuseTransmitterMaterial) {
Expand Down
4 changes: 2 additions & 2 deletions core/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ class MetalWorkflow : public Material {
std::shared_ptr<Texture> metallicTexture;
};

class ClearCoatedConductor : public Material {
class ClearcoatedConductor : public Material {
public:
ClearCoatedConductor(std::shared_ptr<Conductor> con, std::shared_ptr<Texture> roughness_u, std::shared_ptr<Texture> roughness_v, float coatweight,
ClearcoatedConductor(std::shared_ptr<Conductor> con, std::shared_ptr<Texture> roughness_u, std::shared_ptr<Texture> roughness_v, float coatweight,
std::shared_ptr<Texture> normal = NULL) :
Material(MaterialType::ClearcoatedConductorMaterial, normal), conductor(con), roughnessTexture_u(roughness_u), roughnessTexture_v(roughness_v), coatWeight(coatweight) {}

Expand Down
163 changes: 154 additions & 9 deletions core/TestScenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ std::shared_ptr<Renderer> TestScenes::Diningroom_MeshLight() {

// Material
float yellow[3] = { 0.75f, 0.8f, 0.7f };
float radiance[3] = { 16.0f, 8.0f, 4.0f };
float radiance[3] = { 17.0f, 12.0f, 8.0f };
float diffuse[3] = { 0.88f, 0.85f, 0.8f };
float diffuse2[3] = { 0.4f, 0.4f, 0.4f };
float albedo[3] = { 0.85f, 0.85f, 0.75f };
Expand Down Expand Up @@ -88,18 +88,18 @@ std::shared_ptr<Renderer> TestScenes::Diningroom_MeshLight() {
auto integrator = std::make_shared<VolumetricPathTracing>(scene, sampler, filter, Width, Height, 64);

// ToneMapper
auto tone = std::make_shared<Reinhard>();
auto tone = std::make_shared<ACES>();

// PostProcessing
auto post = std::make_shared<PostProcessing>(tone, 1.0f);
auto post = std::make_shared<PostProcessing>(tone, 0.0f);

// Renderer
auto renderer = std::make_shared<Renderer>(integrator, post);

return renderer;
}

std::shared_ptr<Renderer> TestScenes::Diningroom_SphereLight() {
std::shared_ptr<Renderer> TestScenes::Diningroom_EnvironmentLight() {
int Width = 1200;
int Height = 1000;

Expand Down Expand Up @@ -135,7 +135,7 @@ std::shared_ptr<Renderer> TestScenes::Diningroom_SphereLight() {
std::make_shared<Constant>(Spectrum::FromRGB(roughness)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)), 1.45f, 1.0f, true);

// Light
auto spherelight = std::make_shared<SphereArea>(new Sphere(quadlight_material, Point3f(15.0f, 5.0f, 0.0f), 5.0f));
auto envlight = std::make_shared<InfiniteArea>(std::make_shared<Hdr>("scenes/diningroom/textures/spaichingen_hill_4k.hdr"));

// Shape
Transform tran;
Expand All @@ -157,7 +157,7 @@ std::shared_ptr<Renderer> TestScenes::Diningroom_SphereLight() {
auto teapot = new TriangleMesh(teapot_material, "scenes/diningroom/models/teapot.obj", tran);

// Camera
auto camera = std::make_shared<Pinhole>(Point3f(-1.0f, 2.0f, 8.5f), Point3f(-1.0f, 2.0f, 0.0f), Vector3f(0.0f, 1.0f, 0.0f), 1.0f, 45.0f, (float)Width / (float)Height);
auto camera = std::make_shared<Pinhole>(Point3f(-1.0f, 2.0f, 9.0f), Point3f(-1.0f, 2.0f, 0.0f), Vector3f(0.0f, 1.0f, 0.0f), 1.0f, 45.0f, (float)Width / (float)Height);

// Filter
auto filter = std::make_shared<Gaussian>();
Expand All @@ -167,7 +167,7 @@ std::shared_ptr<Renderer> TestScenes::Diningroom_SphereLight() {

// Scene
auto scene = std::make_shared<Scene>(rtc_device);
scene->AddLight(spherelight);
scene->AddLight(envlight);
scene->AddShape(light);
scene->AddShape(floor);
scene->AddShape(wall);
Expand All @@ -194,10 +194,155 @@ std::shared_ptr<Renderer> TestScenes::Diningroom_SphereLight() {
auto tone = std::make_shared<Reinhard>();

// PostProcessing
auto post = std::make_shared<PostProcessing>(tone, 1.0f);
auto post = std::make_shared<PostProcessing>(tone, 0.5f);

// Renderer
auto renderer = std::make_shared<Renderer>(integrator, post);

return renderer;
}
}

std::shared_ptr<Renderer> TestScenes::Subsurface() {
int Width = 800;
int Height = 800;

// Medium
float sigma_a[3] = { 0.032f, 0.17f, 0.48f };
float sigma_s[3] = { 0.74f, 0.88f, 1.01f };
float scale = 20.0f;
auto medium = std::make_shared<Homogeneous>(std::make_shared<Isotropic>(), Spectrum::FromRGB(sigma_s), Spectrum::FromRGB(sigma_a), scale);

// Material
float diffuse_white[3] = { 0.725f, 0.71f, 0.68f };
float diffuse_red[3] = { 0.63f, 0.065f, 0.05f };
float diffuse_green[3] = { 0.14f, 0.45f, 0.091f };
float albedo[3] = { 1.0f, 1.0f, 1.0f };
float roughness[3] = { 0.1f };
float radiance[3] = { 4.0f, 2.0f, 1.0f };

auto light_material = std::make_shared<DiffuseLight>(Spectrum::FromRGB(radiance));
auto plane_material = std::make_shared<Diffuse>(std::make_shared<Constant>(Spectrum::FromRGB(albedo)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)));
auto buddha_material = std::make_shared<ThinDielectric>(std::make_shared<Constant>(Spectrum::FromRGB(albedo)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)),
std::make_shared<Constant>(Spectrum::FromRGB(roughness)), 1.5f, 1.0f);
auto white = std::make_shared<Diffuse>(std::make_shared<Constant>(Spectrum::FromRGB(diffuse_white)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)));
auto red = std::make_shared<Diffuse>(std::make_shared<Constant>(Spectrum::FromRGB(diffuse_red)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)));
auto green = std::make_shared<Diffuse>(std::make_shared<Constant>(Spectrum::FromRGB(diffuse_green)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)));

// Light
auto envlight = std::make_shared<InfiniteArea>(std::make_shared<Hdr>("scenes/subsurface/textures/spruit_sunrise_4k.hdr"));

// Shape
Transform tran;
Transform tran_b = Transform::Rotate(0.0f, 180.0f, 0.0f);
auto buddha = new TriangleMesh(buddha_material, "scenes/subsurface/models/buddha.obj", tran_b, NULL, medium);
auto cbox_back = new TriangleMesh(white, "scenes/subsurface/models/cbox_back.obj", tran_b);
auto cbox_floor = new TriangleMesh(white, "scenes/subsurface/models/cbox_floor.obj", tran);
auto cbox_greenwall = new TriangleMesh(green, "scenes/subsurface/models/cbox_greenwall.obj", tran);

// Camera
auto camera = std::make_shared<Pinhole>(Point3f(0.0f, 0.0f, 55.0f), Point3f(0.0f, 0.0f, 0.0f), Vector3f(0.0f, 1.0f, 0.0f), 1.0f, 60.0f,
(float)Width / (float)Height);

// Filter
auto filter = std::make_shared<Gaussian>();

// Sampler
auto sampler = std::make_shared<Independent>();

// Scene
auto scene = std::make_shared<Scene>(rtc_device);
scene->AddLight(envlight);
scene->AddShape(buddha);
scene->AddShape(cbox_back);
scene->AddShape(cbox_floor);
scene->AddShape(cbox_greenwall);
scene->SetCamera(camera);
scene->Commit();

// Integrator
auto integrator = std::make_shared<VolumetricPathTracing>(scene, sampler, filter, Width, Height, 2048);

// ToneMapper
auto tone = std::make_shared<ACES>();

// PostProcessing
auto post = std::make_shared<PostProcessing>(tone, 0.0f);

// Renderer
auto renderer = std::make_shared<Renderer>(integrator, post);

return renderer;
}

std::shared_ptr<Renderer> TestScenes::Surface() {
int Width = 1280;
int Height = 720;

// Material
float albedo[3] = { 1.0f, 1.0f, 1.0f };
float diffuse[3] = { 0.4f, 0.4f, 0.4f };
float specular[3] = { 1.0f, 1.0f, 1.0f };
float roughness[3] = { 0.1f };
float roughness2[3] = { 0.5f };
float eta[3] = { 0.14282f, 0.37414f, 1.43944f };
float k[3] = { 3.97472f, 2.38066f, 1.59981f };

auto conductor = std::make_shared<Conductor>(std::make_shared<Constant>(Spectrum::FromRGB(albedo)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)),
std::make_shared<Constant>(Spectrum::FromRGB(roughness2)), Spectrum::FromRGB(eta), Spectrum::FromRGB(k));
auto dragon_material = std::make_shared<ClearcoatedConductor>(conductor, std::make_shared<Constant>(Spectrum::FromRGB(roughness)),
std::make_shared<Constant>(Spectrum::FromRGB(roughness)), 1.0f);
auto clock_material = std::make_shared<MetalWorkflow>(std::make_shared<Image>("scenes/surface/textures/clock_albedo.bmp"),
std::make_shared<Image>("scenes/surface/textures/clock_roughness.bmp"), std::make_shared<Image>("scenes/surface/textures/clock_roughness.bmp"),
std::make_shared<Image>("scenes/surface/textures/clock_metallic.bmp"), std::make_shared<Image>("scenes/surface/textures/clock_normal.bmp"));
auto dielctric = std::make_shared<Dielectric>(std::make_shared<Constant>(Spectrum::FromRGB(albedo)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)),
std::make_shared<Constant>(Spectrum::FromRGB(roughness)), 1.5f, 1.0f);
auto dielctric2 = std::make_shared<Dielectric>(std::make_shared<Constant>(Spectrum::FromRGB(albedo)), std::make_shared<Constant>(Spectrum::FromRGB(roughness2)),
std::make_shared<Constant>(Spectrum::FromRGB(roughness2)), 1.5f, 1.0f);
auto teapot_material = std::make_shared<Mixture>(dielctric, dielctric2, 0.5f);
auto plane_material = std::make_shared<Plastic>(std::make_shared<Constant>(Spectrum::FromRGB(diffuse)), std::make_shared<Constant>(Spectrum::FromRGB(specular)),
std::make_shared<Constant>(Spectrum::FromRGB(roughness)), std::make_shared<Constant>(Spectrum::FromRGB(roughness)), 1.5f, 1.0f, true);

// Light
auto envlight = std::make_shared<InfiniteArea>(std::make_shared<Hdr>("scenes/surface/textures/spruit_sunrise_4k.hdr"));

// Shape
Transform tran;
auto clock = new TriangleMesh(clock_material, "scenes/surface/models/clock.obj", tran);
auto dragon = new TriangleMesh(dragon_material, "scenes/surface/models/dragon.obj", tran);
auto teapot = new TriangleMesh(teapot_material, "scenes/surface/models/teapot.obj", tran);
auto plane = new TriangleMesh(plane_material, "scenes/surface/models/plane.obj", tran);

// Camera
auto camera = std::make_shared<Pinhole>(Point3f(15.0f, 7.5f, 0.0f), Point3f(0.0f, 0.0f, 0.0f), Vector3f(0.0f, 1.0f, 0.0f), 1.0f, 60.0f,
(float)Width / (float)Height);

// Filter
auto filter = std::make_shared<Gaussian>();

// Sampler
auto sampler = std::make_shared<SimpleSobol>(0);

// Scene
auto scene = std::make_shared<Scene>(rtc_device);
scene->AddLight(envlight);
scene->AddShape(clock);
scene->AddShape(dragon);
scene->AddShape(teapot);
scene->AddShape(plane);
scene->SetCamera(camera);
scene->Commit();

// Integrator
auto integrator = std::make_shared<VolumetricPathTracing>(scene, sampler, filter, Width, Height, 64);

// ToneMapper
auto tone = std::make_shared<Uncharted2>();

// PostProcessing
auto post = std::make_shared<PostProcessing>(tone, 0.0f);

// Renderer
auto renderer = std::make_shared<Renderer>(integrator, post);

return renderer;
}
6 changes: 5 additions & 1 deletion core/TestScenes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
namespace TestScenes{
std::shared_ptr<Renderer> Diningroom_MeshLight();

std::shared_ptr<Renderer> Diningroom_SphereLight();
std::shared_ptr<Renderer> Diningroom_EnvironmentLight();

std::shared_ptr<Renderer> Subsurface();

std::shared_ptr<Renderer> Surface();
}
2 changes: 1 addition & 1 deletion core/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Spectrum Constant::GetColor(const Point2f& uv) {
}

Image::Image(const std::string& filepath) : Texture(TextureType::ImageTexture) {
stbi_set_flip_vertically_on_load(true);
stbi_set_flip_vertically_on_load(false);
data = stbi_load(filepath.c_str(), &nx, &ny, &nn, 0);
if (data == NULL) {
std::cerr << "Texture is null.\n";
Expand Down
2 changes: 1 addition & 1 deletion core/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <int nSpectrumSamples>
class CoefficientSpectrum;
class RGBSpectrum;
class SampledSpectrum;
typedef SampledSpectrum Spectrum;
typedef RGBSpectrum Spectrum;

class ToneMapper;
class Reinhard;
Expand Down
6 changes: 4 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "TestScenes.h"

int main() {
SampledSpectrum::Init();
// SampledSpectrum::Init();

// auto renderer = TestScenes::Diningroom_MeshLight();
auto renderer = TestScenes::Diningroom_SphereLight();
// auto renderer = TestScenes::Diningroom_EnvironmentLight();
// auto renderer = TestScenes::Subsurface();
auto renderer = TestScenes::Surface();
renderer->Run();

return 0;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added scenes/subsurface/Subsurface(spp=242,rgb).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions scenes/subsurface/models/cbox_back.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file uses centimeters as units for non-parametric coordinates.

mtllib cbox_back.mtl
g default
v 27.320000 -27.440002 27.499995
v -27.639999 27.440001 27.500005
v 27.960003 27.440001 27.500005
v -27.639999 -27.440002 27.499995
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
s off
g cbox_back:Mesh
usemtl initialShadingGroup
f 1//1 2//2 3//3
f 1//4 4//5 2//6
19 changes: 19 additions & 0 deletions scenes/subsurface/models/cbox_floor.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file uses centimeters as units for non-parametric coordinates.

mtllib cbox_floor.mtl
g default
v -27.559999 -27.499991 -27.960001
v 27.400000 -27.500009 27.960001
v 27.719999 -27.499991 -27.960001
v -27.559999 -27.500009 27.960001
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
s off
g cbox_floor:Mesh
usemtl initialShadingGroup
f 1//1 2//2 3//3
f 1//4 4//5 2//6
19 changes: 19 additions & 0 deletions scenes/subsurface/models/cbox_greenwall.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file uses centimeters as units for non-parametric coordinates.

mtllib cbox_greenwall.mtl
g default
v -27.500000 -27.439993 -27.960009
v -27.500000 27.439993 27.960009
v -27.500000 -27.440010 27.959993
v -27.500000 27.440008 -27.959991
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
s off
g cbox_greenwall:Mesh
usemtl initialShadingGroup
f 1//1 2//2 3//3
f 1//4 4//5 2//6
Binary file added scenes/subsurface/textures/spruit_sunrise_4k.hdr
Binary file not shown.
Binary file added scenes/surface/Surface(spp=431,rgb).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d30eb19

Please sign in to comment.