-
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.
- Loading branch information
Pedro Jorquera
committed
Mar 29, 2024
1 parent
4ab7330
commit 9916aea
Showing
6 changed files
with
124 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,35 @@ | ||
#include "constantmedium.h" | ||
|
||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
bool ConstantMedium::intersects(const Ray &ray, const Interval &interval, Hit &hit) const { | ||
Hit hit1, hit2; | ||
|
||
if (!_boundary->intersects(ray, Interval::UNIVERSE, hit1)) return false; | ||
if (!_boundary->intersects(ray, Interval(hit1.t() + 0.0001, numeric_limits<double>::infinity()), hit2)) return false; | ||
|
||
if (hit1.t() < interval.min()) hit1.setT(interval.min()); | ||
if (hit2.t() > interval.max()) hit2.setT(interval.max()); | ||
|
||
if (hit1.t() >= hit2.t()) return false; | ||
|
||
if (hit1.t() < 0.0) hit1.setT(0.0); | ||
|
||
auto ray_length = ray.dir().length(); | ||
auto distance_inside_boundary = (hit2.t() - hit1.t()) * ray_length; | ||
auto hit_distance = _negInvDensity * log(randomDouble()); | ||
|
||
if (hit_distance > distance_inside_boundary) return false; | ||
|
||
hit.setT(hit1.t() + hit_distance / ray_length); | ||
hit.setPoint(ray.at(hit.t())); | ||
|
||
hit.setNormal(Vector(1.0, 0.0, 0.0)); // arbitrary | ||
hit.setFrontFace(true); // also arbitrary | ||
hit.setMaterial(_phaseFunction); | ||
|
||
return true; | ||
} | ||
|
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 "intersectable.h" | ||
#include "material.h" | ||
|
||
#include <memory> | ||
|
||
class ConstantMedium : public Intersectable { | ||
|
||
private: | ||
|
||
std::shared_ptr<Intersectable> _boundary; | ||
double _negInvDensity; | ||
std::shared_ptr<Material> _phaseFunction; | ||
|
||
public: | ||
|
||
ConstantMedium(std::shared_ptr<Intersectable> b, double d, std::shared_ptr<Texture> a): | ||
_boundary(b), _negInvDensity(-1.0 / d), _phaseFunction(std::make_shared<Isotropic>(a)) {} | ||
|
||
ConstantMedium(std::shared_ptr<Intersectable> b, double d, Color c): | ||
_boundary(b), _negInvDensity(-1.0 / d), _phaseFunction(std::make_shared<Isotropic>(c)) {} | ||
|
||
bool intersects(const Ray &ray, const Interval &interval, Hit &hit) const override; | ||
Aabb boundingBox() const override { return _boundary->boundingBox(); } | ||
|
||
}; |
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