/******************************************************************/ /* LambertianBRDF.cpp */ /* ----------------------- */ /* */ /* Defines a very simple Lambertian BRDF material type that you */ /* can use with the BRDFMaterial class to get simple diffuse */ /* surfaces. */ /* */ /* Chris Wyman (4/9/2006) */ /******************************************************************/ #include "Materials/LambertianBRDF.h" Color LambertianBRDF::SampleBRDF( const Ray &r, const Vector &toViewer, const Vector &incidentLight ) const { // Lambertian BRDFs are the albedo divided by pi return albedo / M_PI; } Vector LambertianBRDF::RandomlySelectOutgoingVector( Random *rng, const Vector &normVec ) const { // We're sampling our outgoing ray uniformly randomly over the hemisphere return rng->RandomHemisphereVector( normVec ); } float LambertianBRDF::GetProbabilityOfSampling( const Vector &normVec, const Vector &sampleVec ) const { // The probability of sampling is 1/(2pi) return 1.0f/(2.0f*M_PI); } LambertianBRDF::LambertianBRDF( FILE *f, Scene *s ) : diffuseTexture(0) { albedo = Color::White(); char buf[ MAXLINELENGTH ], token[256], *ptr; while( fgets(buf, MAXLINELENGTH, f) != NULL ) { ptr = StripLeadingWhiteSpace( buf ); // Find the first token on the line if (ptr[0] == '#') continue; // Check if it's a comment ptr = StripLeadingTokenToBuffer( ptr, token ); // Grab the command to deal with MakeLower( token ); // Make sure it's consistantly lower case if (!strcmp(token,"end")) break; // Done reading the material? if (!strcmp(token,"color") || !strcmp(token,"albedo")) albedo = Color( ptr ); // Read in the albedo else printf("Error: Unknown command '%s' when loading LambertianBRDF\n", token); } }