Ambientlight implemented

This commit is contained in:
m.gaedke 2022-11-21 13:30:17 +01:00
parent e032f1fa03
commit 7be006ff05
4 changed files with 56 additions and 1 deletions

1
.gitignore vendored
View file

@ -11,6 +11,7 @@ build/
!/data/parallax !/data/parallax
!/data/fractal.obj !/data/fractal.obj
/result* /result*
/cmake-build-debug
# Latex stuff # Latex stuff
*.aux *.aux

View file

@ -25,7 +25,7 @@ file(GLOB shader_src "shader/*.cpp")
# The tracey library # The tracey library
add_library(tracey STATIC ${common_src} ${camera_src} ${light_src} add_library(tracey STATIC ${common_src} ${camera_src} ${light_src}
${primitive_src} ${renderer_src} ${scene_src} ${shader_src}) ${primitive_src} ${renderer_src} ${scene_src} ${shader_src} light/ambientlight.cpp light/ambientlight.h)
if(NOT WIN32) if(NOT WIN32)
target_link_libraries(tracey ${CMAKE_THREAD_LIBS_INIT} ${X11_LIBRARIES}) target_link_libraries(tracey ${CMAKE_THREAD_LIBS_INIT} ${X11_LIBRARIES})
endif() endif()

32
light/ambientlight.cpp Normal file
View file

@ -0,0 +1,32 @@
//
// Created by marcel on 21.11.22.
//
#include "light/ambientlight.h"
#include "scene/scene.h"
AmbientLight::AmbientLight(float intensity, const Color &color) : Light(intensity, color) {}
Light::Illumination AmbientLight::illuminate(Scene const &scene, Ray const &ray) const {
Vector3d const target = ray.origin + (ray.length - LGT_EPS) * ray.direction;
Illumination illum;
illum.direction = -ray.normal;
// Precompute the distance from the light source
float const distance = length(ray.normal);
// Define a secondary ray from the surface point to the light source.
Ray lightRay;
lightRay.origin = target;
lightRay.direction = -illum.direction;
lightRay.length = distance - LGT_EPS;
// If the target is not in shadow...
if (!scene.findOcclusion(lightRay))
// ... compute the attenuation and light color
illum.color = 1.0f / (distance * distance) * this->color * this->intensity;
return illum;
return illum;
}

22
light/ambientlight.h Normal file
View file

@ -0,0 +1,22 @@
//
// Created by marcel on 21.11.22.
//
#ifndef CG1_TRACER_AMBIENTLIGHT_H
#define CG1_TRACER_AMBIENTLIGHT_H
#include "light/light.h"
class AmbientLight : public Light{
public:
AmbientLight(float intensity, Color const &color = Color(1, 1, 1));
Illumination illuminate(Scene const &scene, Ray const &ray) const override;
protected:
Vector3d direction;
};
#endif //CG1_TRACER_AMBIENTLIGHT_H