cloudy-raytracer/shader/shader.h

37 lines
1.2 KiB
C
Raw Normal View History

2022-11-05 22:08:16 +01:00
#ifndef SHADER_H
#define SHADER_H
#include "common/color.h"
#include "common/ray.h"
// Forward declarations
class Scene;
class Shader
{
2022-11-05 22:08:16 +01:00
public:
// Constructor / Desctructor
Shader() = default;
2022-11-05 22:08:16 +01:00
virtual ~Shader() = default;
2022-11-05 22:08:16 +01:00
// Get
virtual bool isTransparent() const
{ return false; }
/**
* Especially used for lighting calculations.
* @brief Returns the light let through the shader in opposite direction of the given ray.
* @param ray Origin and direction of the desired path through the object. Origin might be inside or outside the object. Length of the ray is upper bound for the destination point, and might not go through the object completely.
* @param maxLength Maximum length of the ray. If the ray through the object is longer than this, it is cut off.
* @return 0 if the shader is opaque, 1 if the shader is transparent, for each color channel.
*/
virtual Color transparency(const Scene &scene, const Ray &ray, float maxLength) const
{ return isTransparent() ? Color(1, 1, 1) : Color(0, 0, 0); }
// Shader functions
virtual Color shade(Scene const &scene, Ray const &ray) const = 0;
2022-11-05 22:08:16 +01:00
};
#endif