00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <yafray_config.h>
00022
00023 #include <core_api/environment.h>
00024 #include <core_api/background.h>
00025 #include <core_api/light.h>
00026
00027 #include <lights/bglight.h>
00028
00029 __BEGIN_YAFRAY
00030
00031 class gradientBackground_t: public background_t
00032 {
00033 public:
00034 enum PROJECTION { spherical=0, angular };
00035 gradientBackground_t(color_t gzcol, color_t ghcol, color_t szcol, color_t shcol, bool ibl, int samples);
00036 virtual color_t operator() (const ray_t &ray, renderState_t &state, bool filtered=false) const;
00037 virtual color_t eval(const ray_t &ray, bool filtered=false) const;
00038 virtual light_t* getLight() const { return envLight; }
00039 virtual ~gradientBackground_t();
00040 static background_t *factory(paraMap_t &,renderEnvironment_t &);
00041 protected:
00042
00043 color_t gzenith, ghoriz, szenith, shoriz;
00044 light_t *envLight;
00045 };
00046
00047 gradientBackground_t::gradientBackground_t(color_t gzcol, color_t ghcol, color_t szcol, color_t shcol, bool ibl, int samples):
00048 gzenith(gzcol), ghoriz(ghcol), szenith(szcol), shoriz(shcol), envLight(0)
00049 {
00050 if(ibl)
00051 {
00052 envLight = new bgLight_t(this, samples);
00053 }
00054 }
00055
00056 gradientBackground_t::~gradientBackground_t()
00057 {
00058 if(envLight) delete envLight;
00059 }
00060
00061 color_t gradientBackground_t::operator() (const ray_t &ray, renderState_t &state, bool filtered) const
00062 {
00063 return eval(ray);
00064 }
00065
00066 color_t gradientBackground_t::eval(const ray_t &ray, bool filtered) const
00067 {
00068 color_t color;
00069
00070 float blend = ray.dir.z;
00071
00072 if(blend >= 0.f)
00073 {
00074 color = blend*szenith + (1.f-blend)*shoriz;
00075 }
00076 else
00077 {
00078 blend = -blend;
00079 color = blend*gzenith + (1.f-blend)*ghoriz;
00080 }
00081
00082 if(color.minimum() < 0.000001) color = color_t(0.00001);
00083
00084 return color;
00085 }
00086
00087 background_t* gradientBackground_t::factory(paraMap_t ¶ms,renderEnvironment_t &render)
00088 {
00089 color_t gzenith, ghoriz, szenith(0.4f, 0.5f, 1.f), shoriz(1.f);
00090 float p = 1.0;
00091 bool bgl = false;
00092 int bglSam = 8;
00093 params.getParam("horizon_color", shoriz);
00094 params.getParam("zenith_color", szenith);
00095 gzenith = szenith;
00096 ghoriz = shoriz;
00097 params.getParam("horizon_ground_color", ghoriz);
00098 params.getParam("zenith_ground_color", gzenith);
00099 params.getParam("ibl", bgl);
00100 params.getParam("ibl_samples", bglSam);
00101 params.getParam("power", p);
00102
00103 return new gradientBackground_t(gzenith*p, ghoriz*p, szenith*p, shoriz*p, bgl, bglSam);
00104 }
00105
00106 extern "C"
00107 {
00108
00109 YAFRAYPLUGIN_EXPORT void registerPlugin(renderEnvironment_t &render)
00110 {
00111 render.registerFactory("gradientback",gradientBackground_t::factory);
00112 }
00113
00114 }
00115 __END_YAFRAY