00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_SPHERICALFUNCTION_H
00024 #define LUX_SPHERICALFUNCTION_H
00025
00026 #include "lux.h"
00027 #include "color.h"
00028 #include "mipmap.h"
00029
00030 namespace lux {
00031
00035 class SphericalFunction {
00036 public:
00037 virtual ~SphericalFunction() {};
00038
00046 RGBColor f(const Vector& w) const {
00047 return f(SphericalPhi( w ), SphericalTheta( w ));
00048 }
00049
00058 virtual RGBColor f(float phi, float theta) const = 0;
00059 };
00060
00064 class NoopSphericalFunction : public SphericalFunction {
00065 public:
00066 RGBColor f(float phi, float theta) const { return 1.f; };
00067 };
00068
00072 class MipMapSphericalFunction : public SphericalFunction {
00073 public:
00074 MipMapSphericalFunction();
00075 MipMapSphericalFunction(boost::shared_ptr< const MIPMap<RGBColor> > aMipMap, bool flipZ);
00076
00077 void SetMipMap( boost::shared_ptr< const MIPMap<RGBColor> > aMipMap ) {
00078 mipMap = aMipMap;
00079 }
00080
00081 using SphericalFunction::f;
00082 RGBColor f(float phi, float theta) const;
00083 private:
00084 boost::shared_ptr< const MIPMap<RGBColor> > mipMap;
00085 };
00086
00091 class CompositeSphericalFunction : public SphericalFunction {
00092 public:
00093 CompositeSphericalFunction() { }
00094
00095 void Add( boost::shared_ptr< const SphericalFunction > aFunc ) {
00096 funcs.push_back( aFunc );
00097 }
00098
00099 using SphericalFunction::f;
00100 RGBColor f(float phi, float theta) const {
00101 RGBColor ret(1.f);
00102 for( u_int i = 0; i < funcs.size(); i++ )
00103 ret *= funcs[i]->f(phi, theta);
00104 return ret;
00105 }
00106 private:
00107 vector< boost::shared_ptr<const SphericalFunction> > funcs;
00108 };
00109
00113 class SampleableSphericalFunction : public SphericalFunction {
00114 public:
00115 SampleableSphericalFunction(boost::shared_ptr<const SphericalFunction> aFunc,
00116 int xRes = 512, int yRes = 256);
00117 ~SampleableSphericalFunction();
00118
00119 using SphericalFunction::f;
00120 RGBColor f(float phi, float theta) const;
00121
00133 RGBColor Sample_f(float u1, float u2, Vector *w, float *pdf) const;
00134
00142 float Pdf(const Vector& w) const;
00143
00149 float Average_f() const;
00150 private:
00151 int nVDistribs;
00152 Distribution1D* uDistrib;
00153 Distribution1D** vDistribs;
00154 boost::shared_ptr<const SphericalFunction> func;
00155 };
00156
00165 SphericalFunction *CreateSphericalFunction(const ParamSet &ps, const TextureParams &tp);
00166
00167 }
00168
00169
00170 #endif //LUX_SPHERICALFUNCTION_H