-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
10 changed files
with
307 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (C) Kevin Suffern 2000-2007. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
// Copyright notice for changes since the originally published version: | ||
// Copyright (C) Eduárd Mándy 2019-2021 | ||
// Though this C++ code was change in a large measure it still has the original copyright notice. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
#include "FresnelReflector.h" | ||
|
||
#include <cmath> | ||
#include <utility> | ||
|
||
#include "../Utilities/ShadeRec.h" | ||
#include "../Utilities/Vector3D.h" | ||
|
||
FresnelReflector::FresnelReflector(const FresnelReflector& fr) : BRDF(fr), eta_in(fr.eta_in), eta_out(fr.eta_out) {} | ||
|
||
FresnelReflector::FresnelReflector(FresnelReflector&& fr) noexcept : BRDF(std::move(fr)), eta_in(std::exchange(fr.eta_in, 1.0f)), eta_out(std::exchange(fr.eta_out, 1.0f)) {} | ||
|
||
FresnelReflector& FresnelReflector::operator=(const FresnelReflector& fr) { | ||
FresnelReflector::operator=(fr); | ||
eta_in = fr.eta_in; | ||
eta_out = fr.eta_out; | ||
|
||
return *this; | ||
} | ||
|
||
FresnelReflector& FresnelReflector::operator=(FresnelReflector&& fr) noexcept { | ||
FresnelReflector::operator=(fr); | ||
eta_in = std::exchange(fr.eta_in, 1.0f); | ||
eta_out = std::exchange(fr.eta_out, 1.0f); | ||
|
||
return *this; | ||
} | ||
|
||
FresnelReflector* FresnelReflector::clone() const { return new FresnelReflector(*this); } | ||
|
||
RGBColor FresnelReflector::sample_f(const ShadeRec& sr, const Vector3D& wo, Vector3D& wr) const { | ||
float ndotwo = sr.normal * wo; | ||
wr = -wo + 2.0f * sr.normal * ndotwo; | ||
return fresnel(sr) * RGBColor::white / fabs(sr.normal * wr); | ||
} | ||
|
||
float FresnelReflector::fresnel(const ShadeRec& sr) const { | ||
Normal normal(sr.normal); | ||
float ndotd = -normal * sr.ray.d; | ||
float eta; | ||
|
||
if (ndotd < 0.0f) { | ||
normal = -normal; | ||
eta = eta_out / eta_in; | ||
} else { | ||
eta = eta_in / eta_out; | ||
} | ||
|
||
float cos_theta_i = -normal * sr.ray.d; | ||
float temp = 1.0f - (1.0f - cos_theta_i * cos_theta_i) / (eta * eta); | ||
float cos_theta_t = sqrt(1.0f - (1.0f - cos_theta_i * cos_theta_i) / (eta * eta)); | ||
float r_parallel = (eta * cos_theta_i - cos_theta_t) / (eta * cos_theta_i + cos_theta_t); | ||
float r_perpendicular = (cos_theta_i - eta * cos_theta_t) / (cos_theta_i + eta * cos_theta_t); | ||
float kr = 0.5f * (r_parallel * r_parallel + r_perpendicular * r_perpendicular); | ||
|
||
return kr; | ||
} |
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,56 @@ | ||
// Copyright (C) Kevin Suffern 2000-2007. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
// Copyright notice for changes since the originally published version: | ||
// Copyright (C) Eduárd Mándy 2019-2021 | ||
// Though this C++ code was change in a large measure it still has the original copyright notice. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
#ifndef __FRESNEL_REFLECTOR__ | ||
#define __FRESNEL_REFLECTOR__ | ||
|
||
class ShadeRec; | ||
class Vector; | ||
|
||
#include "BRDF.h" | ||
|
||
class FresnelReflector : public BRDF { | ||
public: | ||
|
||
FresnelReflector() = default; | ||
|
||
~FresnelReflector() = default; | ||
|
||
FresnelReflector(const FresnelReflector& fr); | ||
|
||
FresnelReflector(FresnelReflector&& fr) noexcept; | ||
|
||
FresnelReflector& operator=(const FresnelReflector& fr); | ||
|
||
FresnelReflector& operator=(FresnelReflector&& fr) noexcept; | ||
|
||
FresnelReflector* clone() const override; | ||
|
||
void set_eta_in(const float eta); | ||
|
||
void set_eta_out(const float eta); | ||
|
||
RGBColor sample_f(const ShadeRec& sr, const Vector3D& wo, Vector3D& wr) const override; | ||
|
||
private: | ||
|
||
float eta_in = 1.0f; | ||
float eta_out = 1.0f; | ||
|
||
float fresnel(const ShadeRec& sr) const; | ||
}; | ||
|
||
inline void FresnelReflector::set_eta_in(const float eta) { eta_in = eta; } | ||
|
||
inline void FresnelReflector::set_eta_out(const float eta) { eta_out = eta; } | ||
|
||
#endif |
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 @@ | ||
// Copyright (C) Kevin Suffern 2000-2007. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
// Copyright notice for changes since the originally published version: | ||
// Copyright (C) Eduárd Mándy 2019-2021 | ||
// Though this C++ code was change in a large measure it still has the original copyright notice. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
#include "FresnelTransmitter.h" | ||
|
||
#include <utility> | ||
#include <cmath> | ||
|
||
#include "../Utilities/Vector3D.h" | ||
#include "../Utilities/ShadeRec.h" | ||
|
||
FresnelTransmitter::FresnelTransmitter(const FresnelTransmitter& pt) : BTDF(pt), kt(pt.kt), ior(pt.ior) {} | ||
|
||
FresnelTransmitter::FresnelTransmitter(FresnelTransmitter&& pt) noexcept : BTDF(std::move(pt)), kt(std::exchange(pt.kt, 0.0f)), ior(std::exchange(pt.ior, 1.0f)) {} | ||
|
||
FresnelTransmitter& FresnelTransmitter::operator=(const FresnelTransmitter& pt) { | ||
FresnelTransmitter::operator=(pt); | ||
kt = pt.kt; | ||
ior = pt.ior; | ||
|
||
return *this; | ||
} | ||
|
||
FresnelTransmitter& FresnelTransmitter::operator=(FresnelTransmitter&& pt) noexcept { | ||
FresnelTransmitter::operator=(pt); | ||
kt = std::exchange(pt.kt, 0.0f); | ||
ior = std::exchange(pt.ior, 1.0f); | ||
|
||
return *this; | ||
} | ||
|
||
FresnelTransmitter* FresnelTransmitter::clone() const { return new FresnelTransmitter(*this); } | ||
|
||
// tests for total internal reflection | ||
|
||
bool FresnelTransmitter::tir(const ShadeRec& sr) const { | ||
Vector3D wo(-sr.ray.d); | ||
float cos_thetai = sr.normal * wo; | ||
float eta = ior; | ||
|
||
if (cos_thetai < 0.0f) { | ||
eta = 1.0f / eta; | ||
} | ||
|
||
return 1.0f - (1.0f - cos_thetai * cos_thetai) / (eta * eta) < 0.0f; | ||
} | ||
|
||
RGBColor FresnelTransmitter::f(const ShadeRec& sr, const Vector3D& wo, const Vector3D& wi) const { return RGBColor::black; } | ||
|
||
// this computes the direction wt for perfect transmission | ||
// and returns the transmission coefficient | ||
// this is only called when there is no total internal reflection | ||
|
||
RGBColor FresnelTransmitter::sample_f(const ShadeRec& sr, const Vector3D& wo, Vector3D& wt) const { | ||
Normal n(sr.normal); | ||
float cos_thetai = n * wo; | ||
float eta = ior; | ||
|
||
if (cos_thetai < 0.0f) { // transmitted ray is outside | ||
cos_thetai = -cos_thetai; | ||
n = -n; // reverse direction of normal | ||
eta = 1.0f / eta; // invert ior | ||
} | ||
|
||
float temp = 1.0f - (1.0f - cos_thetai * cos_thetai) / (eta * eta); | ||
float cos_theta2 = sqrt(temp); | ||
wt = -wo / eta - (cos_theta2 - cos_thetai / eta) * n; | ||
|
||
return kt / (eta * eta) * RGBColor::white / fabs(sr.normal * wt); | ||
} | ||
|
||
RGBColor FresnelTransmitter::rho(const ShadeRec& sr, const Vector3D& wo) const { return RGBColor::black; } |
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,59 @@ | ||
// Copyright (C) Kevin Suffern 2000-2007. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
// Copyright notice for changes since the originally published version: | ||
// Copyright (C) Eduárd Mándy 2019-2021 | ||
// Though this C++ code was change in a large measure it still has the original copyright notice. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
#ifndef __FRESNEL_TRANSMITTER__ | ||
#define __FRESNEL_TRANSMITTER__ | ||
|
||
#include "BTDF.h" | ||
|
||
class FresnelTransmitter : public BTDF { | ||
public: | ||
|
||
FresnelTransmitter() = default; | ||
|
||
~FresnelTransmitter() = default; | ||
|
||
FresnelTransmitter(const FresnelTransmitter& pt); | ||
|
||
FresnelTransmitter(FresnelTransmitter&& pt) noexcept; | ||
|
||
FresnelTransmitter& operator=(const FresnelTransmitter& rhs); | ||
|
||
FresnelTransmitter& operator=(FresnelTransmitter&& rhs) noexcept; | ||
|
||
FresnelTransmitter* clone() const override; | ||
|
||
void set_eta_in(const float eta); | ||
|
||
void set_eta_out(const float eta); | ||
|
||
bool tir(const ShadeRec& sr) const; | ||
|
||
RGBColor f(const ShadeRec& sr, const Vector3D& wo, const Vector3D& wi) const override; | ||
|
||
RGBColor sample_f(const ShadeRec& sr, const Vector3D& wo, Vector3D& wt) const override; | ||
|
||
RGBColor rho(const ShadeRec& sr, const Vector3D& wo) const override; | ||
|
||
private: | ||
|
||
float eta_in = 1.0f; | ||
float eta_out = 1.0f; | ||
float kt = 0.0f; // TODO: what is kt? | ||
float ior = 0.0f; // TODO: what is ior? | ||
}; | ||
|
||
inline void FresnelTransmitter::set_eta_in(const float eta) { eta_in = eta; } | ||
|
||
inline void FresnelTransmitter::set_eta_out(const float eta) { eta_out = eta; } | ||
|
||
#endif |
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 @@ | ||
// Copyright (C) Kevin Suffern 2000-2007. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
// Copyright notice for changes since the originally published version: | ||
// Copyright (C) Eduárd Mándy 2019-2021 | ||
// Though this C++ code was change in a large measure it still has the original copyright notice. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
#include "Dielectric.h" |
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,22 @@ | ||
// Copyright (C) Kevin Suffern 2000-2007. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
// Copyright notice for changes since the originally published version: | ||
// Copyright (C) Eduárd Mándy 2019-2021 | ||
// Though this C++ code was change in a large measure it still has the original copyright notice. | ||
// This C++ code is for non-commercial purposes only. | ||
// This C++ code is licensed under the GNU General Public License Version 2. | ||
// See the file COPYING.txt for the full license. | ||
|
||
#ifndef __DIELECTRIC__ | ||
#define __DIELECTRIC__ | ||
|
||
class Dielectric { | ||
|
||
// TODO: implement, 28.3 Implementation, page 601 | ||
|
||
}; | ||
|
||
#endif |