-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0f1914
commit f709c44
Showing
9 changed files
with
95 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "WhittedIntegrator.h" | ||
#include <FunctionLayer/Material/Material.h> | ||
|
||
Spectrum WhittedIntegrator::li(const Ray &_ray, const Scene &scene, | ||
std::shared_ptr<Sampler> sampler) const { | ||
Spectrum spectrum(.0f), beta(.0f); | ||
Ray ray(_ray); | ||
|
||
do { | ||
auto itsOpt = scene.rayIntersect(ray); | ||
|
||
// escape the scene | ||
if (!itsOpt.has_value()) { | ||
for (auto light : scene.infiniteLights) { | ||
spectrum += light->evaluateEmission(ray); | ||
} | ||
break; | ||
} | ||
|
||
Intersection its = itsOpt.value(); | ||
computeRayDifferentials(&its, ray); | ||
auto bsdf = its.shape->material->computeBSDF(its); | ||
|
||
auto bsdfSampleResult = bsdf->sample(-ray.direction, sampler->next2D()); | ||
|
||
// If the surface is specular, spwan the ray | ||
if (bsdfSampleResult.type == BSDFType::Specular) { | ||
ray = Ray(its.position, bsdfSampleResult.wi); | ||
beta *= bsdfSampleResult.weight; | ||
continue; | ||
} | ||
// If the surface is not specular, sample the light | ||
else { | ||
|
||
// First, sample infinite light | ||
for (auto light : scene.infiniteLights) { | ||
auto lightSampleResult = light->sample(its, sampler->next2D()); | ||
Ray shadowRay(its.position, lightSampleResult.direction, 1e-4f, | ||
FLT_MAX); | ||
} | ||
} | ||
} while (1); | ||
|
||
return spectrum; | ||
} |
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,15 @@ | ||
#pragma once | ||
|
||
#include "Integrator.h" | ||
|
||
class WhittedIntegrator : public Integrator { | ||
public: | ||
WhittedIntegrator() = default; | ||
|
||
WhittedIntegrator(const Json &json) : Integrator(json) {} | ||
|
||
virtual ~WhittedIntegrator() = default; | ||
|
||
virtual Spectrum li(const Ray &ray, const Scene &scene, | ||
std::shared_ptr<Sampler> sampler) const 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
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,13 @@ | ||
#include "Mirror.h" | ||
#include "./BxDF/Specular.h" | ||
|
||
MirrorMaterial::MirrorMaterial(const Json &json) : Material(json) {} | ||
|
||
std::shared_ptr<BSDF> | ||
MirrorMaterial::computeBSDF(const Intersection &intersection) const { | ||
Vector3f normal, tangent, bitangent; | ||
computeShadingGeometry(intersection, &normal, &tangent, &bitangent); | ||
return std::make_shared<SpecularReflection>(normal, tangent, bitangent); | ||
} | ||
|
||
REGISTER_CLASS(MirrorMaterial, "mirror") |
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,12 @@ | ||
#pragma once | ||
#include "Material.h" | ||
|
||
class MirrorMaterial : public Material { | ||
public: | ||
MirrorMaterial(); | ||
|
||
MirrorMaterial(const Json &json); | ||
|
||
virtual std::shared_ptr<BSDF> | ||
computeBSDF(const Intersection &intersection) const override; | ||
}; |