erebus

diff liberebus/src/rt.cc @ 28:4a0a288ffb27

phong/lafortune BRDF
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 06 Jun 2014 14:39:40 +0300
parents c8a6fb04fefa
children fb20e3855740
line diff
     1.1 --- a/liberebus/src/rt.cc	Mon Jun 02 00:53:01 2014 +0300
     1.2 +++ b/liberebus/src/rt.cc	Fri Jun 06 14:39:40 2014 +0300
     1.3 @@ -2,7 +2,7 @@
     1.4  #include "rt.h"
     1.5  #include "erebus_impl.h"
     1.6  
     1.7 -#define MAX_ITER	8
     1.8 +#define MAX_ITER	6
     1.9  
    1.10  Color ray_trace(struct erebus *ctx, const Ray &ray, int iter)
    1.11  {
    1.12 @@ -40,14 +40,18 @@
    1.13  	Vector2 texcoords = hit.calc_texcoords();
    1.14  
    1.15  	Color color = mtl->get_attrib_color("diffuse", texcoords.x, texcoords.y);
    1.16 -	Color res = mtl->get_attrib_color("emissive") + color * scn->get_env().ambient;
    1.17 +	Color specular = mtl->get_attrib_color("specular", texcoords.x, texcoords.y);
    1.18 +	Color res = mtl->get_attrib_color("emissive", texcoords.x, texcoords.y) +
    1.19 +		color * scn->get_env().ambient;
    1.20 +	float shininess = mtl->get_attrib_value("shininess");
    1.21  
    1.22  	Vector3 sample_dir;
    1.23  	float prob = brdf->sample(norm, -hit.world_ray.dir, &sample_dir);
    1.24 -	if(iter < max_iter && randf() <= prob) {
    1.25 +	if(iter < max_iter && randf() <= prob && ray.energy * prob > 0.001) {
    1.26  		Ray sample_ray;
    1.27  		sample_ray.origin = ray.origin + ray.dir * hit.dist;
    1.28  		sample_ray.dir = sample_dir;
    1.29 +		sample_ray.energy = ray.energy * prob;
    1.30  
    1.31  		res += ray_trace(ctx, sample_ray, iter + 1) * color;
    1.32  	}