erebus

view liberebus/src/brdf.h @ 26:c8a6fb04fefa

multithreadededit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Jun 2014 19:19:40 +0300
parents 93894c232d65
children 4a0a288ffb27
line source
1 #ifndef BRDF_H_
2 #define BRDF_H_
4 #include <vector>
5 #include "texture.h"
7 class Reflectance {
8 public:
9 Reflectance();
10 virtual ~Reflectance() = default;
12 virtual Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const = 0;
13 virtual float sample(const Vector3 &norm, const Vector3 &outdir, Vector3 *indir) const;
14 virtual float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const = 0;
15 };
17 typedef float (*CompReflWeightFunc)(const Vector3 &norm, const Vector3 &outdir);
19 class CompositeRefl : public Reflectance {
20 private:
21 struct SubRefl {
22 Reflectance *brdf;
23 float weight;
24 CompReflWeightFunc weight_func; // if null, use static weight above
25 };
26 std::vector<SubRefl> sub_brdf;
27 mutable bool valid_checked;
29 int pick_brdf(const Vector3 &norm, const Vector3 &outdir) const;
31 public:
32 CompositeRefl();
34 virtual void add_brdf(Reflectance *brdf, float weight);
35 virtual void add_brdf(Reflectance *brdf, CompReflWeightFunc weight_func);
37 bool check_valid() const;
39 Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const override;
40 float sample(const Vector3 &norm, const Vector3 &outdir, Vector3 *indir) const override;
41 float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const override;
42 };
44 class LambertRefl : public Reflectance {
45 public:
46 Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const override;
47 float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const override;
48 };
50 class MirrorRefl : public Reflectance {
51 public:
52 Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const override;
53 float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const override;
54 };
56 #endif // BRDF_H_