public function addLight(Color $col, Light $light, Vector $pos, Scene $scene, Thing $thing, Vector $reflectDir, Vector $norm) { $ldis = Vector::minus($light->pos, $pos); $livec = Vector::norm($ldis); $neatIsect = $this->testRay(new Ray($pos, $livec), $scene); $isInShadow = $neatIsect != null && $neatIsect <= Vector::mag($ldis); if ($isInShadow) { return $col; } $illum = Vector::dot($livec, $norm); $lcolor = Color::$defaultColor; if ($illum > 0) { $lcolor = Color::scale($illum, $light->color); } $specular = Vector::dot($livec, Vector::norm($reflectDir)); $scolor = Color::$defaultColor; $surface = $thing->surface(); if ($specular > 0) { $scolor = Color::scale(pow($specular, $surface->roughness()), $light->color); } return Color::plus($col, Color::plus(Color::times($surface->diffuse($pos), $lcolor), Color::times($surface->specular($pos), $scolor))); }