Subversion Repositories gelsvn

Rev

Rev 349 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
346 awk 1
#include "plastic.hpp"
2
 
3
using namespace CGLA;
4
 
5
plastic::plastic(const CGLA::Vec3f& d, const CGLA::Vec3f& g, float s)
6
: material(1.6f, 0.f), diffuse_(d), glossy_(g), shininess_(s)
7
{
8
}
9
 
10
void plastic::sample(const ray& r, hit_info& hi) const
11
{
12
	float cosi = dot(-r.direction, hi.shading_normal);
13
	cosi = clamp(cosi, -1.f, 1.f);
14
	if (cosi <= 0.f)
15
		return;
16
	float sint = 1.f / ior_ * std::sqrt(std::max(0.f, 1.f - cosi*cosi));
17
	float cost = std::sqrt(std::max(0.f, 1.f - sint * sint));
18
	cost = clamp(cost, -1.f, 1.f);
19
	float f = fresnel_dielectric(cosi, cost, ior_);
20
 
21
	hi.diffuse = diffuse_;
22
	hi.glossy = f*glossy_;
23
	hi.shininess = shininess_;
24
	hi.ior = ior_;
25
}
26
 
27
//02566 framework, Anders Wang Kristensen, awk@imm.dtu.dk, 2007