feat: Reflections
This commit is contained in:
parent
f869cb665c
commit
4e3a40c2dd
2 changed files with 16 additions and 3 deletions
|
@ -3,6 +3,8 @@
|
||||||
#include "blinn_phong_shading.h"
|
#include "blinn_phong_shading.h"
|
||||||
#include "reflect.h"
|
#include "reflect.h"
|
||||||
|
|
||||||
|
const double FUDGE_FACTOR = 1e-6;
|
||||||
|
|
||||||
// Hint: for the mirror reflections, you can use raycolor recursively. That is what 'num_recursive_calls' is for.
|
// Hint: for the mirror reflections, you can use raycolor recursively. That is what 'num_recursive_calls' is for.
|
||||||
// The maximum number of recursive calls should be 10. In other words, to get the color of a mirror reflection,
|
// The maximum number of recursive calls should be 10. In other words, to get the color of a mirror reflection,
|
||||||
// stop after 10 bounces.
|
// stop after 10 bounces.
|
||||||
|
@ -17,7 +19,8 @@ bool raycolor(
|
||||||
{
|
{
|
||||||
int hit_id;
|
int hit_id;
|
||||||
double t;
|
double t;
|
||||||
Eigen::Vector3d n;
|
Eigen::Vector3d n, reflect_rgb;
|
||||||
|
Ray reflect_ray;
|
||||||
|
|
||||||
/* Compute viewing array. */
|
/* Compute viewing array. */
|
||||||
if (!first_hit(ray, min_t, objects, hit_id, t, n)) {
|
if (!first_hit(ray, min_t, objects, hit_id, t, n)) {
|
||||||
|
@ -27,5 +30,16 @@ bool raycolor(
|
||||||
|
|
||||||
/* Evaluate shading model and set pixel to that color. */
|
/* Evaluate shading model and set pixel to that color. */
|
||||||
rgb = blinn_phong_shading(ray, hit_id, t, n, objects, lights);
|
rgb = blinn_phong_shading(ray, hit_id, t, n, objects, lights);
|
||||||
|
|
||||||
|
if (num_recursive_calls >= 10) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reflections */
|
||||||
|
reflect_ray.origin = ray.origin + t * ray.direction;
|
||||||
|
reflect_ray.direction = reflect(ray.direction, n);
|
||||||
|
raycolor(reflect_ray, FUDGE_FACTOR, objects, lights, num_recursive_calls + 1, reflect_rgb);
|
||||||
|
rgb += (objects[hit_id]->material->km.array() * reflect_rgb.array()).matrix();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,5 @@
|
||||||
|
|
||||||
Eigen::Vector3d reflect(const Eigen::Vector3d & in, const Eigen::Vector3d & n)
|
Eigen::Vector3d reflect(const Eigen::Vector3d & in, const Eigen::Vector3d & n)
|
||||||
{
|
{
|
||||||
// Replace with your code here:
|
return in - 2 * in.dot(n) * n;
|
||||||
return Eigen::Vector3d(0,0,0);
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue