mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
commit
This commit is contained in:
parent
f98939c206
commit
efab58561a
6 changed files with 20 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ build/
|
|||
*.ppm
|
||||
*.zip
|
||||
.vscode/
|
||||
.cache/
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "Light.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
void Light::setTransform(const Matrix4f &transform) {
|
||||
this->transform = transform;
|
||||
|
@ -11,10 +10,14 @@ void Light::setGridSize(unsigned int gridSize) { this->gridSize = gridSize; }
|
|||
|
||||
void Light::setUseCenter(bool useCenter) { this->useCenter = useCenter; }
|
||||
|
||||
void Light::setIsUse(bool isUse) { this->use = isUse; }
|
||||
|
||||
Vector3f Light::getDiffuse() const { return diffuse; }
|
||||
|
||||
Vector3f Light::getSpecular() const { return specular; }
|
||||
|
||||
bool Light::isUse() const { return use; }
|
||||
|
||||
Vector3f PointLight::illumination(const HitRecord &hit,
|
||||
const vector<Geometry *> &geometries) const {
|
||||
Vector3f shadingPoint = hit.getPoint();
|
||||
|
|
|
@ -29,13 +29,16 @@ protected:
|
|||
Matrix4f transform = Matrix4f::Identity(); // optional member `transform`
|
||||
unsigned int gridSize = 0; // optional member `n`
|
||||
bool useCenter = false; // optional member `usecenter`
|
||||
bool use = true; // this appears in a json file
|
||||
|
||||
public:
|
||||
void setTransform(const Matrix4f &);
|
||||
void setGridSize(unsigned int);
|
||||
void setUseCenter(bool);
|
||||
void setIsUse(bool);
|
||||
Vector3f getDiffuse() const;
|
||||
Vector3f getSpecular() const;
|
||||
bool isUse() const;
|
||||
};
|
||||
|
||||
class AreaLight : public Light {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "Output.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
void Output::write() {
|
||||
|
@ -8,9 +9,9 @@ void Output::write() {
|
|||
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
for (unsigned int x = 0; x < width; ++x)
|
||||
fout << (char)(255.0f * red[y * width + x])
|
||||
<< (char)(255.0f * green[y * width + x])
|
||||
<< (char)(255.0f * blue[y * width + x]);
|
||||
fout << (char)std::min(255.0f, 255.0f * red[y * width + x])
|
||||
<< (char)std::min(255.0f, 255.0f * green[y * width + x])
|
||||
<< (char)std::min(255.0f, 255.0f * blue[y * width + x]);
|
||||
fout.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ Light *Parser::getLight(const nlohmann::json &j) {
|
|||
|
||||
l->setGridSize(j.value("n", 0));
|
||||
l->setUseCenter(j.value("usecenter", false));
|
||||
l->setIsUse(j.value("use", true));
|
||||
|
||||
return l;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ void RayTracer::calculateColor(const HitRecord &hit, Output *buffer, int i) {
|
|||
buffer->g(i, 0);
|
||||
buffer->b(i, 0);
|
||||
|
||||
for (auto light : lights) {
|
||||
for (auto light : lights)
|
||||
if (light->isUse()) {
|
||||
Vector3f contribution = light->illumination(hit, geometries);
|
||||
buffer->r(i, buffer->r(i) + contribution.x());
|
||||
buffer->g(i, buffer->g(i) + contribution.y());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue