feat: Shadows
This commit is contained in:
parent
4e3a40c2dd
commit
b0ca946840
1 changed files with 15 additions and 10 deletions
|
@ -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;
|
||||
|
|
Reference in a new issue