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) {
|
||||
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>();
|
||||
}
|
||||
|
||||
return rpp;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,6 @@ Light *RayTracer::singleLightSource() const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// helper functions
|
||||
Ray getRay(int x, int y) {
|
||||
using namespace camera;
|
||||
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());
|
||||
}
|
||||
|
||||
// This should generate a higher quality random number
|
||||
float getRandomNumber() {
|
||||
static std::uniform_real_distribution<float> distribution(0.0, 1.0);
|
||||
static std::mt19937 generator;
|
||||
return distribution(generator);
|
||||
}
|
||||
|
||||
// Generate a randon point on a unit hemisphere
|
||||
Vector3f getRandomDirection() {
|
||||
RETRY_RANDOM:
|
||||
float x = getRandomNumber() * 2 - 1;
|
||||
|
@ -225,13 +226,13 @@ Vector3f getGlobalRandDirection(Vector3f normal) {
|
|||
return local2World * getRandomDirection();
|
||||
}
|
||||
|
||||
// Check if a light source in on a surface (or really near)
|
||||
bool lightOnSurface(HitRecord hit, const Light *l) {
|
||||
Vector3f center = l->getCenter();
|
||||
Geometry *g = hit.geometry();
|
||||
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 false;
|
||||
}
|
||||
|
@ -293,6 +294,11 @@ int getRayNumber(VectorXi data) {
|
|||
return data.size() == 2 ? data.y() : (data.size() == 3 ? data.z() : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize camera parameters
|
||||
*
|
||||
* Construct the surface for viewing the world
|
||||
*/
|
||||
void init() {
|
||||
width = Scene::current->width();
|
||||
height = Scene::current->height();
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
|
||||
class RayTracer {
|
||||
public:
|
||||
RayTracer(const nlohmann::json &j) : json(j) {}
|
||||
|
@ -17,10 +19,10 @@ public:
|
|||
|
||||
private:
|
||||
nlohmann::json json;
|
||||
std::vector<Scene *> scenes;
|
||||
std::vector<Light *> lights;
|
||||
std::vector<Geometry *> geometries;
|
||||
std::vector<Output *> outputs;
|
||||
vector<Scene *> scenes;
|
||||
vector<Light *> lights;
|
||||
vector<Geometry *> geometries;
|
||||
vector<Output *> outputs;
|
||||
|
||||
void parse();
|
||||
void render();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue