erebus

diff liberebus/src/brdf.cc @ 32:b1fc96c71bcc

- lambert BRDF importance sampling - UI + commandline arguments - font rendering for showing status/progress
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 07 Jun 2014 13:36:36 +0300
parents 53a98c148bf8
children d15ee526daa6
line diff
     1.1 --- a/liberebus/src/brdf.cc	Sat Jun 07 09:14:17 2014 +0300
     1.2 +++ b/liberebus/src/brdf.cc	Sat Jun 07 13:36:36 2014 +0300
     1.3 @@ -18,7 +18,7 @@
     1.4  	}
     1.5  
     1.6  	tangent = Vector3(1.0f, 0.0f, 0.0f);
     1.7 -	if(fabs(dot_product(normal, tangent)) - 1.0f < 1e-4f) {
     1.8 +	if(fabs(fabs(dot_product(normal, tangent)) - 1.0f) < 1e-4f) {
     1.9  		tangent = Vector3(0.0f, 0.0f, 1.0f);
    1.10  	}
    1.11  	Vector3 bitan = cross_product(normal, tangent);
    1.12 @@ -187,8 +187,14 @@
    1.13  // --- class LambertRefl ---
    1.14  Vector3 LambertRefl::sample_dir(const SurfaceGeometry &geom, const Vector3 &outdir) const
    1.15  {
    1.16 -	Vector3 dir = Vector3{randf(-1, 1), randf(-1, 1), randf(-1, 1)}.normalized();
    1.17 -	return dot_product(dir, geom.normal) < 0.0 ? -dir : dir;
    1.18 +	// TODO: write a better uniform disk sampling that doesn't rely in rejection
    1.19 +	Vector3 dir;
    1.20 +	do {
    1.21 +		dir = Vector3(randf(-1, 1), randf(-1, 1), 0);
    1.22 +	} while(dir.length_sq() > 1.0);
    1.23 +	dir.z = sqrt(1.0 - (dir.x * dir.x + dir.y * dir.y));
    1.24 +
    1.25 +	return geom.sample_to_world(dir);
    1.26  }
    1.27  
    1.28  float LambertRefl::eval(const SurfaceGeometry &geom, const Vector3 &outdir, const Vector3 &indir) const