-
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
Showing
37 changed files
with
684 additions
and
252 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
|
||
- Book 2 section 4 : texture mapping | ||
- Book 2 section 8 : instances | ||
- make buildchain crossplatform with CMake | ||
- test to replace RNG for grid sampling in antialiasing | ||
- centralize asset loading in a resource manager | ||
- find a good name for the project | ||
- have a format describing scenes instead of code description | ||
- add log system | ||
- add render queue |
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
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,64 @@ | ||
|
||
#include "quad.hpp" | ||
|
||
#include "math/ray.hpp" | ||
|
||
|
||
using namespace std; | ||
|
||
|
||
Quad::Quad(const Point3 &q, const Vec3 &u, const Vec3 &v, shared_ptr<IMaterial> material) | ||
: m_q{q}, m_u{u}, m_v{v}, m_material{material} | ||
{ | ||
Vec3 n = m_u.Cross(m_v); | ||
m_normal = n.Normalized(); | ||
m_d = m_normal.Dot(m_q); | ||
m_w = n / n.Dot(n); | ||
|
||
AABB diag1_aabb = AABB(m_q, m_q + m_u + m_v); | ||
AABB diag2_aabb = AABB(m_q + m_u, m_q + m_v); | ||
m_aabb = AABB(diag1_aabb, diag2_aabb); | ||
} | ||
|
||
|
||
bool Quad::Hit(const Ray &ray, const Interval &interval, HitRecord &outRecord) const | ||
{ | ||
double denominator = m_normal.Dot(ray.Direction()); | ||
if(std::fabs(denominator) < 1e-8){ | ||
return false; | ||
} | ||
|
||
double t = (m_d - m_normal.Dot(ray.Origin())) / denominator; | ||
|
||
if(! interval.Contains(t)){ | ||
return false; | ||
} | ||
|
||
Vec3 intersection = ray.At(t); | ||
|
||
Vec3 plan_centered_hitpoint = intersection - m_q; | ||
double alpha = m_w.Dot(plan_centered_hitpoint.Cross(m_v)); | ||
double beta = m_w.Dot(m_u.Cross(plan_centered_hitpoint)); | ||
|
||
if(! IsInQuad(alpha, beta, outRecord)){ | ||
return false; | ||
} | ||
|
||
outRecord.t = t; | ||
outRecord.hit_point = intersection; | ||
outRecord.material = m_material; | ||
outRecord.SetFaceNormal(ray, m_normal); | ||
|
||
return true; | ||
} | ||
|
||
|
||
bool Quad::IsInQuad(double alpha, double beta, HitRecord& hit_record) const { | ||
static const Interval unit_interval = Interval(0.0, 1.0); | ||
|
||
// set it anyway to make code branchless | ||
hit_record.u = alpha; | ||
hit_record.v = beta; | ||
|
||
return unit_interval.Contains(alpha) && unit_interval.Contains(beta); | ||
} |
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,38 @@ | ||
|
||
#pragma once | ||
|
||
|
||
#include "geometry/IHittable.hpp" | ||
|
||
#include "math/vec.hpp" | ||
|
||
|
||
class Quad : public IHittable { | ||
|
||
private: | ||
|
||
Point3 m_q; | ||
Vec3 m_u; | ||
Vec3 m_v; | ||
|
||
Vec3 m_normal; | ||
// d is the intersection equation result for the plan | ||
// for a point Q on the plane, n.Q = d | ||
double m_d; | ||
// w is a constant for a given quadrilateral | ||
// It simplifies the check to know if we are inside the quad | ||
Vec3 m_w; | ||
|
||
AABB m_aabb; | ||
std::shared_ptr<IMaterial> m_material; | ||
|
||
bool IsInQuad(double alpha, double beta, HitRecord& hit_record) const; | ||
|
||
|
||
public: | ||
|
||
Quad(const Point3& q, const Vec3& u, const Vec3& v, std::shared_ptr<IMaterial> material); | ||
|
||
bool Hit(const Ray& ray, const Interval& interval, HitRecord& outRecord) const override; | ||
AABB GetAABB() const override { return m_aabb; } | ||
}; |
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,36 @@ | ||
|
||
#include "logger.hpp" | ||
|
||
#include <sstream> | ||
#include <chrono> | ||
#include <iostream> | ||
|
||
|
||
using namespace std; | ||
using namespace std::chrono; | ||
|
||
|
||
string Logger::GetCurrentTimeFormatted() | ||
{ | ||
auto now = std::chrono::system_clock::now(); | ||
return format("[{:%T}]", zoned_time{ current_zone(), floor<milliseconds>(now)}); | ||
} | ||
|
||
|
||
void Logger::Log(const std::string &log, const LogLevel& level) | ||
{ | ||
if(level < s_level){ | ||
return; | ||
} | ||
|
||
ostringstream string_builder; | ||
string_builder << GetCurrentTimeFormatted() << " "; | ||
string_builder << s_colored_name_lookup.at(level) << " "; | ||
string_builder << log; | ||
string_builder << (s_overwrite ? '\r' : '\n'); | ||
|
||
const string& formatted_log = string_builder.str(); | ||
for(ostream* stream : s_outputs){ | ||
*stream << formatted_log << flush; | ||
} | ||
} |
Oops, something went wrong.