feat: Shadows
Some checks failed
CMake / build (zip, zip, [self-hosted Windows], Release/raytracing.exe, win) (push) Has been cancelled
CMake / build (zip, zip, [self-hosted Linux], raytracing, ux) (push) Has been cancelled

This commit is contained in:
Tibo De Peuter 2024-10-18 19:21:54 +02:00
parent 4e3a40c2dd
commit b0ca946840
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2

View file

@ -1,9 +1,9 @@
#include "blinn_phong_shading.h"
// Hint:
#include "first_hit.h"
#include <iostream>
const double AMBIENT_INTENSITY = 0.1;
const double FUDGE_FACTOR = 1e-6;
/* Helper functions */
Eigen::Vector3d lambert(
@ -28,11 +28,14 @@ Eigen::Vector3d blinn_phong_shading(
const std::vector< std::shared_ptr<Object> > & objects,
const std::vector<std::shared_ptr<Light> > & lights)
{
Eigen::Vector3d rgb, light_direction;
double max_t;
Eigen::Vector3d rgb, light_direction, _n_shadow;
Ray shadow_ray;
double max_t, _t_shadow;
int shadow_id;
Eigen::Vector3d v = -ray.direction.normalized();
Eigen::Vector3d hit = ray.origin + t * ray.direction;
shadow_ray.origin = hit;
std::shared_ptr<Material> material = objects[hit_id]->material;
/* Ambient lighting. */
@ -41,14 +44,16 @@ Eigen::Vector3d blinn_phong_shading(
for (const auto & light : lights) {
light->direction(hit, light_direction, max_t);
/* Diffuse component (Lambertian shading) */
rgb += lambert(n, material->kd, light_direction, light->I);
/* Specular component (Blinn-Phong shading) */
rgb += blinn_phong(v, n, material->ks, material->phong_exponent, light_direction, light->I);
/* Shadows */
// TODO
shadow_ray.direction = light_direction;
bool shadow = first_hit(shadow_ray, FUDGE_FACTOR, objects, shadow_id, _t_shadow, _n_shadow) && _t_shadow < max_t;
if (!shadow) {
/* Diffuse component (Lambertian shading) */
rgb += lambert(n, material->kd, light_direction, light->I);
/* Specular component (Blinn-Phong shading) */
rgb += blinn_phong(v, n, material->ks, material->phong_exponent, light_direction, light->I);
}
}
return rgb;