Subversion Repositories gelsvn

Rev

Rev 349 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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

Generated by GNU Enscript 1.6.6.
30

Generated by GNU Enscript 1.6.6.
31
 
31
 
32
 
32
 
33
 
33