erebus
diff liberebus/src/brdf.h @ 21:e49f4d7ad04c
started adding BRDFs
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 28 May 2014 07:06:29 +0300 |
parents | 93894c232d65 |
children | 4a0a288ffb27 |
line diff
1.1 --- a/liberebus/src/brdf.h Tue May 27 07:49:09 2014 +0300 1.2 +++ b/liberebus/src/brdf.h Wed May 28 07:06:29 2014 +0300 1.3 @@ -1,6 +1,7 @@ 1.4 #ifndef BRDF_H_ 1.5 #define BRDF_H_ 1.6 1.7 +#include <vector> 1.8 #include "texture.h" 1.9 1.10 class Reflectance { 1.11 @@ -13,10 +14,43 @@ 1.12 virtual float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const = 0; 1.13 }; 1.14 1.15 +typedef float (*CompReflWeightFunc)(const Vector3 &norm, const Vector3 &outdir); 1.16 + 1.17 +class CompositeRefl : public Reflectance { 1.18 +private: 1.19 + struct SubRefl { 1.20 + Reflectance *brdf; 1.21 + float weight; 1.22 + CompReflWeightFunc weight_func; // if null, use static weight above 1.23 + }; 1.24 + std::vector<SubRefl> sub_brdf; 1.25 + mutable bool valid_checked; 1.26 + 1.27 + int pick_brdf(const Vector3 &norm, const Vector3 &outdir) const; 1.28 + 1.29 +public: 1.30 + CompositeRefl(); 1.31 + 1.32 + virtual void add_brdf(Reflectance *brdf, float weight); 1.33 + virtual void add_brdf(Reflectance *brdf, CompReflWeightFunc weight_func); 1.34 + 1.35 + bool check_valid() const; 1.36 + 1.37 + Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const override; 1.38 + float sample(const Vector3 &norm, const Vector3 &outdir, Vector3 *indir) const override; 1.39 + float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const override; 1.40 +}; 1.41 + 1.42 class LambertRefl : public Reflectance { 1.43 public: 1.44 Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const override; 1.45 float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const override; 1.46 }; 1.47 1.48 +class MirrorRefl : public Reflectance { 1.49 +public: 1.50 + Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const override; 1.51 + float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const override; 1.52 +}; 1.53 + 1.54 #endif // BRDF_H_