calc correct light

This commit is contained in:
Shuo Feng 2024-03-04 02:43:10 -05:00
parent b5878e06c9
commit 6d81bd4530
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1

View file

@ -1,6 +1,7 @@
#include "Light.h" #include "Light.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <iostream>
void Light::setTransform(const Matrix4f &transform) { void Light::setTransform(const Matrix4f &transform) {
this->transform = transform; this->transform = transform;
@ -52,11 +53,11 @@ Vector3f AreaLight::illumination(const HitRecord &hit,
Vector3f color = Vector3f::Zero(); Vector3f color = Vector3f::Zero();
if (useCenter) { if (useCenter) {
color += PointLight(*this, (u + v) / 2).illumination(hit, geometries); color += PointLight(*this, p1 + (u + v) / 2).illumination(hit, geometries);
} else { } else {
for (int y = 0; y < gridSize; ++y) for (int y = 0; y < gridSize; ++y)
for (int x = 0; x < gridSize; ++x) for (int x = 0; x < gridSize; ++x)
color += PointLight(*this, (u * x + v * y) / gridSize) color += PointLight(*this, p1 + (u * x + v * y) / gridSize)
.illumination(hit, geometries); .illumination(hit, geometries);
} }