mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
small fix
This commit is contained in:
parent
c60e4da292
commit
e0ea221137
3 changed files with 16 additions and 9 deletions
|
@ -18,9 +18,8 @@ const Vector3f getVector3f(const nlohmann::json &j) {
|
||||||
const VectorXi getRpp(const nlohmann::json &j) {
|
const VectorXi getRpp(const nlohmann::json &j) {
|
||||||
VectorXi rpp(j.size());
|
VectorXi rpp(j.size());
|
||||||
|
|
||||||
for (int i = 0; i < j.size(); ++i) {
|
for (int i = 0; i < j.size(); ++i)
|
||||||
rpp[i] = j[i].get<int>();
|
rpp[i] = j[i].get<int>();
|
||||||
}
|
|
||||||
|
|
||||||
return rpp;
|
return rpp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,6 @@ Light *RayTracer::singleLightSource() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper functions
|
|
||||||
Ray getRay(int x, int y) {
|
Ray getRay(int x, int y) {
|
||||||
using namespace camera;
|
using namespace camera;
|
||||||
return Ray(pos, pxUpperLeft + x * du + y * dv - pos);
|
return Ray(pos, pxUpperLeft + x * du + y * dv - pos);
|
||||||
|
@ -194,12 +193,14 @@ void writeColor(int i, const Vector3f &color) {
|
||||||
Output::current->b(i, color.z());
|
Output::current->b(i, color.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should generate a higher quality random number
|
||||||
float getRandomNumber() {
|
float getRandomNumber() {
|
||||||
static std::uniform_real_distribution<float> distribution(0.0, 1.0);
|
static std::uniform_real_distribution<float> distribution(0.0, 1.0);
|
||||||
static std::mt19937 generator;
|
static std::mt19937 generator;
|
||||||
return distribution(generator);
|
return distribution(generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a randon point on a unit hemisphere
|
||||||
Vector3f getRandomDirection() {
|
Vector3f getRandomDirection() {
|
||||||
RETRY_RANDOM:
|
RETRY_RANDOM:
|
||||||
float x = getRandomNumber() * 2 - 1;
|
float x = getRandomNumber() * 2 - 1;
|
||||||
|
@ -225,13 +226,13 @@ Vector3f getGlobalRandDirection(Vector3f normal) {
|
||||||
return local2World * getRandomDirection();
|
return local2World * getRandomDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if a light source in on a surface (or really near)
|
||||||
bool lightOnSurface(HitRecord hit, const Light *l) {
|
bool lightOnSurface(HitRecord hit, const Light *l) {
|
||||||
Vector3f center = l->getCenter();
|
Vector3f center = l->getCenter();
|
||||||
Geometry *g = hit.geometry();
|
Geometry *g = hit.geometry();
|
||||||
Geometry::Type type = g->type();
|
Geometry::Type type = g->type();
|
||||||
if (type == Geometry::Type::RECTANGLE) {
|
if (type == Geometry::Type::RECTANGLE)
|
||||||
return (g->sample() - center).dot(g->normal(center)) < 1e-5;
|
return (g->sample() - center).dot(g->normal(center)) < 1e-5;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -293,6 +294,11 @@ int getRayNumber(VectorXi data) {
|
||||||
return data.size() == 2 ? data.y() : (data.size() == 3 ? data.z() : 1);
|
return data.size() == 2 ? data.y() : (data.size() == 3 ? data.z() : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize camera parameters
|
||||||
|
*
|
||||||
|
* Construct the surface for viewing the world
|
||||||
|
*/
|
||||||
void init() {
|
void init() {
|
||||||
width = Scene::current->width();
|
width = Scene::current->width();
|
||||||
height = Scene::current->height();
|
height = Scene::current->height();
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
class RayTracer {
|
class RayTracer {
|
||||||
public:
|
public:
|
||||||
RayTracer(const nlohmann::json &j) : json(j) {}
|
RayTracer(const nlohmann::json &j) : json(j) {}
|
||||||
|
@ -17,10 +19,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
std::vector<Scene *> scenes;
|
vector<Scene *> scenes;
|
||||||
std::vector<Light *> lights;
|
vector<Light *> lights;
|
||||||
std::vector<Geometry *> geometries;
|
vector<Geometry *> geometries;
|
||||||
std::vector<Output *> outputs;
|
vector<Output *> outputs;
|
||||||
|
|
||||||
void parse();
|
void parse();
|
||||||
void render();
|
void render();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue