Пример #1
0
rgb lighting(scene s, ray r, hit_test h)
{
  rgb result;
  if (h.miss)
    return s.bg;
  vec hit_position = ray_position(r, h.dist);
  if (shadow(hit_position, s.light, s.spheres)) {
    result = rgb_modulate(h.surf, s.amb);
  }
  else {  
    double dot = vec_dot(h.surf_norm, s.light.direction);
    double d = double_max(0, dot);
    rgb diffuse_light = rgb_scale(d, s.light.color);
    rgb lsum = rgb_add(s.amb, diffuse_light);
    result = rgb_modulate(h.surf, lsum);
  }
  /**** === implement specular reflection here === ****/
 
  if (rgb_nonzero(h.shine)) {
    rgb ss;
    vec N = h.surf_norm;
    vec L = s.light.direction;
    rgb S = h.shine;
    vec R = vec_sub( vec_scale(2* vec_dot(N,L),N),L);
    vec V = vec_neg(r.direction);
    if (vec_dot(N,L)>0){
      ss = rgb_scale( pow( double_max( vec_dot(R,V),0), 6), S);
      //rgb_print(k);
    }
    else
      ss = rgb_expr(0,0,0);
    return rgb_add(result,ss);
  }
  return result;
}
Пример #2
0
static void	set_color_max(t_phpa *ph)
{
	rgb_add(ph->color, ph->diffuse->r, ph->diffuse->g, ph->diffuse->b);
	rgb_add(ph->color, ph->specular->r, ph->specular->g, ph->specular->b);
	rgb_clamp(ph->color);
}