34 lines
No EOL
1.2 KiB
C++
34 lines
No EOL
1.2 KiB
C++
#include "sunlight.h"
|
|
|
|
|
|
SunLight::SunLight(Vector3d const &direction, float intensity, Color const &color) : Light(intensity, color),
|
|
direction(normalized(direction))
|
|
{}
|
|
|
|
Light::Illumination SunLight::illuminate(Scene const &scene, Ray const &ray) const
|
|
{
|
|
Vector3d const target = ray.origin + (ray.length - LGT_EPS) * ray.direction;
|
|
|
|
// Illumination object
|
|
Illumination illum;
|
|
illum.direction = this->direction;
|
|
illum.distance = INFINITY;
|
|
|
|
// Define a secondary ray from the surface point to the light source.
|
|
Ray lightRay;
|
|
lightRay.origin = target;
|
|
lightRay.direction = -illum.direction;
|
|
lightRay.length = INFINITY;
|
|
|
|
// If the target is not in shadow...
|
|
if (!scene.findOcclusion(lightRay))
|
|
{
|
|
// Look at angleIntensity of light
|
|
float angleIntensity = dotProduct(-ray.normal,
|
|
this->direction); // 0 if light is behind surface, 1 if light is in front of surface
|
|
|
|
Color rayTransparency = scene.getTransparency(lightRay, INFINITY);
|
|
illum.color = this->color * this->intensity * angleIntensity * rayTransparency;
|
|
}
|
|
return illum;
|
|
} |