mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
bugfix: clamp
This commit is contained in:
parent
efab58561a
commit
b5878e06c9
4 changed files with 13 additions and 12 deletions
12
src/Light.cc
12
src/Light.cc
|
@ -30,16 +30,18 @@ Vector3f PointLight::illumination(const HitRecord &hit,
|
|||
return Vector3f::Zero();
|
||||
|
||||
Vector3f ambient_ = geometry->coefAmbient() * geometry->ambient();
|
||||
Vector3f diffuse_ = geometry->coefDiffuse() * diffuse.array() *
|
||||
geometry->diffuse().array() *
|
||||
|
||||
Vector3f diffuse_ = geometry->coefDiffuse() * geometry->diffuse().array() *
|
||||
diffuse.array() *
|
||||
std::max(0.0f, hit.normal().dot(rayDirection));
|
||||
|
||||
Vector3f halfWay = (hit.viewDirection() + rayDirection).normalized();
|
||||
Vector3f specular_ =
|
||||
geometry->coefSpecular() * specular.array() *
|
||||
geometry->specular().array() *
|
||||
geometry->coefSpecular() * geometry->specular().array() *
|
||||
specular.array() *
|
||||
pow(std::max(0.0f, hit.normal().dot(halfWay)), geometry->getPhong());
|
||||
return diffuse_ + specular_ + ambient_;
|
||||
|
||||
return specular_ + ambient_ + diffuse_;
|
||||
}
|
||||
|
||||
Vector3f AreaLight::illumination(const HitRecord &hit,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "Output.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
void Output::write() {
|
||||
|
@ -9,9 +8,9 @@ void Output::write() {
|
|||
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
for (unsigned int x = 0; x < 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 << (char)(255.0f * red[y * width + x])
|
||||
<< (char)(255.0f * green[y * width + x])
|
||||
<< (char)(255.0f * blue[y * width + x]);
|
||||
fout.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,10 +31,11 @@ void RayTracer::calculateColor(const HitRecord &hit, Output *buffer, int i) {
|
|||
buffer->r(i, 0);
|
||||
buffer->g(i, 0);
|
||||
buffer->b(i, 0);
|
||||
|
||||
for (auto light : lights)
|
||||
if (light->isUse()) {
|
||||
Vector3f contribution = light->illumination(hit, geometries);
|
||||
Vector3f contribution =
|
||||
light->illumination(hit, geometries).cwiseMax(0.0f).cwiseMin(1.0f) /
|
||||
lights.size();
|
||||
buffer->r(i, buffer->r(i) + contribution.x());
|
||||
buffer->g(i, buffer->g(i) + contribution.y());
|
||||
buffer->b(i, buffer->b(i) + contribution.z());
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "Output.h"
|
||||
#include "Scene.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class RayTracer {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue