From a374c3193864494dc8b24be387cec54dc3d29765 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Mon, 23 Jan 2023 04:09:48 +0100 Subject: [PATCH] Added fun depth shader --- shader/depthshader.cpp | 12 ++++++++++++ shader/depthshader.h | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 shader/depthshader.cpp create mode 100644 shader/depthshader.h diff --git a/shader/depthshader.cpp b/shader/depthshader.cpp new file mode 100644 index 0000000..59ea643 --- /dev/null +++ b/shader/depthshader.cpp @@ -0,0 +1,12 @@ +#include "depthshader.h" + +Color DepthShader::shade(const Scene &scene, const Ray &ray) const +{ + float brightness = exp(-ray.length * 0.1f); + return brightness * nearColor + (1 - brightness) * farColor; +} + +DepthShader::DepthShader(const Color &nearColor, const Color &farColor) : nearColor(nearColor), farColor(farColor) +{ + +} diff --git a/shader/depthshader.h b/shader/depthshader.h new file mode 100644 index 0000000..fdc33a1 --- /dev/null +++ b/shader/depthshader.h @@ -0,0 +1,21 @@ +#ifndef CG1_TRACER_DEPTHSHADER_H +#define CG1_TRACER_DEPTHSHADER_H + + +#include "shader/shader.h" + +class DepthShader : public Shader { + +public: + DepthShader(Color const &nearColor = Color(1, 1, 1), Color const &farColor = Color(0, 0, 0)); + + // Shader functions + Color shade(Scene const &scene, Ray const &ray) const override; + +private: + Color nearColor; + Color farColor; +}; + + +#endif //CG1_TRACER_DEPTHSHADER_H