-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold update lights
77 lines (58 loc) · 2.7 KB
/
old update lights
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
void directionalhdl::shade(vec3f &ambient, vec3f &diffuse, vec3f &specular, vec3f vertex, vec3f normal, float shininess) const
{
vec3f eye_direction = -vertex;
float eye_distance = mag(eye_direction);
eye_direction /= eye_distance;
vec3f half_vector = norm(direction + eye_direction);
float normal_dot_light_direction = max(0.0f, dot(normal, direction));
float normal_dot_half_vector = max(0.0f, dot(normal, half_vector));
float power_factor = 0.0;
if (normal_dot_light_direction > 0.0)
power_factor = pow(normal_dot_half_vector, shininess);
ambient += this->ambient;
diffuse += this->diffuse*normal_dot_light_direction;
specular += this->specular*power_factor;
}
void pointhdl::shade(vec3f &ambient, vec3f &diffuse, vec3f &specular, vec3f vertex, vec3f normal, float shininess) const
{
vec3f light_direction = position - vertex;
float light_distance = mag(light_direction);
light_direction /= light_distance;
vec3f eye_direction = -vertex;
float eye_distance = mag(eye_direction);
eye_direction /= eye_distance;
float att = 1.0/(attenuation[0] + attenuation[1]*light_distance + attenuation[2]*light_distance*light_distance);
vec3f half_vector = norm(light_direction + eye_direction);
float normal_dot_light_direction = max(0.0f, dot(normal, light_direction));
float normal_dot_half_vector = max(0.0f, dot(normal, half_vector));
float power_factor = 0.0;
if (normal_dot_light_direction > 0.0)
power_factor = pow(normal_dot_half_vector, shininess);
ambient += this->ambient*att;
diffuse += this->diffuse*normal_dot_light_direction*att;
specular += this->specular*power_factor*att;
}
void spothdl::shade(vec3f &ambient, vec3f &diffuse, vec3f &specular, vec3f vertex, vec3f normal, float shininess) const
{
vec3f light_direction = position - vertex;
float light_distance = mag(light_direction);
light_direction /= light_distance;
vec3f eye_direction = -vertex;
float eye_distance = mag(eye_direction);
eye_direction /= eye_distance;
float att = 1.0/(attenuation[0] + attenuation[1]*light_distance + attenuation[2]*light_distance*light_distance);
float spotdot = dot(-light_direction, direction);
float spotatt = 0.0;
if (spotdot >= cutoff)
spotatt = pow(spotdot, exponent);
att *= spotatt;
vec3f half_vector = norm(light_direction + norm(-vertex));
float normal_dot_light_direction = max(0.0f, dot(normal, light_direction));
float normal_dot_half_vector = max(0.0f, dot(normal, half_vector));
float power_factor = 0.0;
if (normal_dot_light_direction > 0.0)
power_factor = pow(normal_dot_half_vector, shininess);
ambient += this->ambient*att;
diffuse += this->diffuse*normal_dot_light_direction*att;
specular += this->specular*power_factor*att;
}