1 #include "SpotLight.hxx"
3 SpotLight::SpotLight(Scene
* scene
,
6 const Vec3f
& intensity
,
7 float alpha_min
, // in degree
8 float alpha_max
) // in degree
12 m_intensity(intensity
),
13 m_alpha_min(alpha_min
),
14 m_alpha_max(alpha_max
)
19 SpotLight::~SpotLight()
23 SpotLight::SpotLight()
34 SpotLight::Illuminate(Ray
& shadow_ray
, Vec3f
& intensity
)
36 // direction vector from light source to surface point
37 Vec3f D
= shadow_ray
.origin()-m_pos
;
39 // angle between light source dir and shadow ray dir
40 float phi
= fabs(acos(D
.dot(m_dir
))*180/M_PI
);
49 Vec3f dir
= m_pos
-shadow_ray
.origin();
50 float r
= dir
.norm()-Epsilon
;
51 float falloff
= 1.0f
/(r
*r
); // falloff for distance
53 // modify ray for shadow computation
55 // for shadow calculation
57 // set direction to light source
59 shadow_ray
.setDir(dir
);
63 intensity
= m_intensity
* falloff
;
67 // linear falloff from 1 at alpha_min to 0 at alpha_max
68 float partial
= 1.0f
-(phi
-m_alpha_min
)/(m_alpha_max
-m_alpha_min
);
69 intensity
= m_intensity
* falloff
* partial
;
78 SpotLight::position() const
84 SpotLight::direction() const
This page took 0.049323 seconds and 5 git commands to generate.