mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
impl ray casted render
This commit is contained in:
parent
ed42a0f9ca
commit
29c5fe91d9
5 changed files with 44 additions and 5 deletions
|
@ -4,6 +4,6 @@ void Geometry::setTransform(const Matrix4f &transform) {
|
|||
this->transform = transform;
|
||||
}
|
||||
|
||||
bool Sphere::intersect() const { return false; }
|
||||
bool Sphere::intersect(const Ray &r) const { return false; }
|
||||
|
||||
bool Rectangle::intersect() const { return false; }
|
||||
bool Rectangle::intersect(const Ray &r) const { return false; }
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef GEOMETRY_H_
|
||||
#define GEOMETRY_H_
|
||||
|
||||
#include "Ray.h"
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
using Eigen::Matrix;
|
||||
|
@ -13,7 +15,7 @@ public:
|
|||
enum class Type { SPHERE, RECTANGLE };
|
||||
|
||||
virtual ~Geometry() = default;
|
||||
virtual bool intersect() const = 0;
|
||||
virtual bool intersect(const Ray &) const = 0;
|
||||
|
||||
protected:
|
||||
Geometry(Type type, float ka, float kd, float ks, const Vector3f &ca,
|
||||
|
@ -37,7 +39,7 @@ public:
|
|||
: Geometry(Type::SPHERE, ka, kd, ks, ca, cd, cs, pc), radius(radius),
|
||||
center(center) {}
|
||||
|
||||
bool intersect() const override;
|
||||
bool intersect(const Ray &) const override;
|
||||
|
||||
private:
|
||||
float radius;
|
||||
|
@ -51,7 +53,7 @@ public:
|
|||
: Geometry(Type::RECTANGLE, ka, kd, ks, ca, cd, cs, pc),
|
||||
corners(corners) {}
|
||||
|
||||
bool intersect() const override;
|
||||
bool intersect(const Ray &) const override;
|
||||
|
||||
private:
|
||||
Matrix<float, 3, 4> corners;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "RayTracer.h"
|
||||
#include "../external/simpleppm.h"
|
||||
#include "Parser.h"
|
||||
#include "Ray.h"
|
||||
|
||||
void RayTracer::parse() {
|
||||
for (auto i = json["output"].begin(); i != json["output"].end(); ++i)
|
||||
|
@ -13,10 +14,34 @@ void RayTracer::parse() {
|
|||
lights.push_back(Parser::getLight(*i));
|
||||
}
|
||||
|
||||
Ray getRay(int x, int y, const Vector3f &camPos, const Vector3f &lookat,
|
||||
float fov, int width, int height) {
|
||||
// TODO: compute ray
|
||||
return Ray(Vector3f(), Vector3f());
|
||||
}
|
||||
|
||||
void RayTracer::render(Scene *scene) {
|
||||
int width = scene->getWidth();
|
||||
int height = scene->getHeight();
|
||||
float fov = scene->getFov();
|
||||
Vector3f cameraPos = scene->getCenter();
|
||||
Vector3f lookAt = scene->getLookAt();
|
||||
Vector3f up = scene->getUpVector();
|
||||
|
||||
Buffer buffer(width * height * 3);
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (int x = 0; x < width; ++x) {
|
||||
Ray ray = getRay(x, y, cameraPos, lookAt, fov, width, height);
|
||||
|
||||
for (auto geometry : geometries)
|
||||
if (geometry->intersect(ray)) {
|
||||
buffer[3 * y * width + 3 * x + 0] = 1;
|
||||
buffer[3 * y * width + 3 * x + 1] = 1;
|
||||
buffer[3 * y * width + 3 * x + 2] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Task *task = new Task(scene, buffer);
|
||||
tasks.push_back(task);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,14 @@ int Scene::getWidth() { return width; }
|
|||
|
||||
int Scene::getHeight() { return height; }
|
||||
|
||||
float Scene::getFov() { return fov; }
|
||||
|
||||
Vector3f Scene::getCenter() const { return center; }
|
||||
|
||||
Vector3f Scene::getUpVector() const { return up; }
|
||||
|
||||
Vector3f Scene::getLookAt() const { return lookAt; }
|
||||
|
||||
void Scene::setRaysPerPixel(const Eigen::VectorXi &raysPerPixel) {
|
||||
this->raysPerPixel = raysPerPixel;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ public:
|
|||
string getName() const;
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
float getFov();
|
||||
Vector3f getCenter() const;
|
||||
Vector3f getUpVector() const;
|
||||
Vector3f getLookAt() const;
|
||||
void setRaysPerPixel(const Eigen::VectorXi &);
|
||||
void setAntialiasing(bool);
|
||||
void setTwoSideRender(bool);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue