Skip to content

Commit

Permalink
Fix for Final gather using background even if no IBL/caustic enabled
Browse files Browse the repository at this point in the history
In Photon Mapping and Path Tracing integrators, Final Gather was gathering the background even when IBL nor caustic were enabled in the background. This introduces undesired noise to the image from the background.

I've made changes to make sure Photon Mapping and Path Tracing *only* use the background for caustics calculations when the background has IBL *and* caustics enabled.

In the backgrounds like single color, gradient or SunSky1 where there is no parameter to enable caustic photons, I've set Final Gather to use the background just when IBL is enabled.

 Changes to be committed:
	modified:   include/core_api/background.h
	modified:   src/backgrounds/darksky.cc
	modified:   src/backgrounds/gradientback.cc
	modified:   src/backgrounds/sunsky.cc
	modified:   src/backgrounds/textureback.cc
	modified:   src/integrators/pathtracer.cc
	modified:   src/integrators/photonintegr.cc
  • Loading branch information
DavidBluecame committed Jun 20, 2015
1 parent f7c293a commit 3f8cb7f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
2 changes: 2 additions & 0 deletions include/core_api/background.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class YAFRAYCORE_EXPORT background_t
\return the light source that reproduces background lighting, or NULL if background
shall only be sampled from BSDFs
*/
virtual bool hasIBL() { return false; }
virtual bool shootsCaustic() { return false; }
virtual ~background_t() {};
};

Expand Down
13 changes: 9 additions & 4 deletions src/backgrounds/darksky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class darkSkyBackground_t: public background_t
{
public:
darkSkyBackground_t(const point3d_t dir, float turb, float pwr, float skyBright, bool clamp, float av, float bv, float cv, float dv, float ev,
float altitude, bool night, float exp, bool genc, ColorSpaces cs);
float altitude, bool night, float exp, bool genc, ColorSpaces cs, bool ibl, bool with_caustic);
virtual color_t operator() (const ray_t &ray, renderState_t &state, bool filtered=false) const;
virtual color_t eval(const ray_t &ray, bool filtered=false) const;
virtual ~darkSkyBackground_t();
static background_t *factory(paraMap_t &,renderEnvironment_t &);
bool hasIBL() { return withIBL; }
bool shootsCaustic() { return shootCaustic; }
color_t getAttenuatedSunColor();

protected:
Expand All @@ -57,11 +59,14 @@ class darkSkyBackground_t: public background_t
ColorConv convert;
float alt;
bool nightSky;
bool withIBL;
bool shootCaustic;
bool shootDiffuse;
};

darkSkyBackground_t::darkSkyBackground_t(const point3d_t dir, float turb, float pwr, float skyBright, bool clamp,float av, float bv, float cv, float dv, float ev,
float altitude, bool night, float exp, bool genc, ColorSpaces cs):
power(pwr * skyBright), skyBrightness(skyBright), convert(clamp, genc, cs, exp), alt(altitude), nightSky(night)
float altitude, bool night, float exp, bool genc, ColorSpaces cs, bool ibl, bool with_caustic):
power(pwr * skyBright), skyBrightness(skyBright), convert(clamp, genc, cs, exp), alt(altitude), nightSky(night), withIBL(ibl), shootCaustic(with_caustic)
{


Expand Down Expand Up @@ -310,7 +315,7 @@ background_t *darkSkyBackground_t::factory(paraMap_t &params,renderEnvironment_t
}

darkSkyBackground_t *darkSky = new darkSkyBackground_t(dir, turb, power, bright, clamp, av, bv, cv, dv, ev,
altitude, night, exp, gammaEnc, colorS);
altitude, night, exp, gammaEnc, colorS, bgl, caus);

if (add_sun && radToDeg(fAcos(dir.z)) < 100.0)
{
Expand Down
14 changes: 9 additions & 5 deletions src/backgrounds/gradientback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ __BEGIN_YAFRAY
class gradientBackground_t: public background_t
{
public:
gradientBackground_t(color_t gzcol, color_t ghcol, color_t szcol, color_t shcol);
gradientBackground_t(color_t gzcol, color_t ghcol, color_t szcol, color_t shcol, bool ibl, bool with_caustic);
virtual color_t operator() (const ray_t &ray, renderState_t &state, bool filtered=false) const;
virtual color_t eval(const ray_t &ray, bool filtered=false) const;
virtual ~gradientBackground_t();
static background_t *factory(paraMap_t &,renderEnvironment_t &);
bool hasIBL() { return withIBL; }
bool shootsCaustic() { return shootCaustic; }
protected:

color_t gzenith, ghoriz, szenith, shoriz;
bool withIBL;
bool shootCaustic;
bool shootDiffuse;
};

gradientBackground_t::gradientBackground_t(color_t gzcol, color_t ghcol, color_t szcol, color_t shcol):
gzenith(gzcol), ghoriz(ghcol), szenith(szcol), shoriz(shcol)
gradientBackground_t::gradientBackground_t(color_t gzcol, color_t ghcol, color_t szcol, color_t shcol, bool ibl, bool with_caustic):
gzenith(gzcol), ghoriz(ghcol), szenith(szcol), shoriz(shcol), withIBL(ibl), shootCaustic(with_caustic)
{
// Empty
}
Expand Down Expand Up @@ -94,7 +98,7 @@ background_t* gradientBackground_t::factory(paraMap_t &params,renderEnvironment_
params.getParam("ibl_samples", bglSam);
params.getParam("power", p);

background_t *gradBG = new gradientBackground_t(gzenith*p, ghoriz*p, szenith*p, shoriz*p);
background_t *gradBG = new gradientBackground_t(gzenith*p, ghoriz*p, szenith*p, shoriz*p, bgl, true);

if(bgl)
{
Expand Down
11 changes: 8 additions & 3 deletions src/backgrounds/sunsky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ color_t ComputeAttenuatedSunlight(float theta, int turbidity);
class sunskyBackground_t: public background_t
{
public:
sunskyBackground_t(const point3d_t dir, float turb, float a_var, float b_var, float c_var, float d_var, float e_var, float pwr);
sunskyBackground_t(const point3d_t dir, float turb, float a_var, float b_var, float c_var, float d_var, float e_var, float pwr, bool ibl, bool with_caustic);
virtual color_t operator() (const ray_t &ray, renderState_t &state, bool filtered=false) const;
virtual color_t eval(const ray_t &ray, bool filtered=false) const;
virtual ~sunskyBackground_t();
static background_t *factory(paraMap_t &,renderEnvironment_t &);
bool hasIBL() { return withIBL; }
bool shootsCaustic() { return shootCaustic; }
protected:
color_t getSkyCol(const ray_t &ray) const;
vector3d_t sunDir;
Expand All @@ -54,9 +56,12 @@ class sunskyBackground_t: public background_t
double AngleBetween(double thetav, double phiv) const;
double PerezFunction(const double *lam, double theta, double gamma, double lvz) const;
float power;
bool withIBL;
bool shootCaustic;
bool shootDiffuse;
};

sunskyBackground_t::sunskyBackground_t(const point3d_t dir, float turb, float a_var, float b_var, float c_var, float d_var, float e_var, float pwr): power(pwr)
sunskyBackground_t::sunskyBackground_t(const point3d_t dir, float turb, float a_var, float b_var, float c_var, float d_var, float e_var, float pwr, bool ibl, bool with_caustic): power(pwr), withIBL(ibl), shootCaustic(with_caustic)
{
sunDir.set(dir.x, dir.y, dir.z);
sunDir.normalize();
Expand Down Expand Up @@ -227,7 +232,7 @@ background_t *sunskyBackground_t::factory(paraMap_t &params,renderEnvironment_t
params.getParam("background_light", bgl);
params.getParam("light_samples", bgl_samples);

background_t *new_sunsky = new sunskyBackground_t(dir, turb, av, bv, cv, dv, ev, power);
background_t *new_sunsky = new sunskyBackground_t(dir, turb, av, bv, cv, dv, ev, power, bgl, true);

if(bgl)
{
Expand Down
24 changes: 16 additions & 8 deletions src/backgrounds/textureback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,45 @@ class textureBackground_t: public background_t
angular
};

textureBackground_t(const texture_t *texture, PROJECTION proj, float bpower, float rot);
textureBackground_t(const texture_t *texture, PROJECTION proj, float bpower, float rot, bool ibl, bool with_caustic);
virtual color_t operator() (const ray_t &ray, renderState_t &state, bool filtered=false) const;
virtual color_t eval(const ray_t &ray, bool filtered=false) const;
virtual ~textureBackground_t();
static background_t *factory(paraMap_t &,renderEnvironment_t &);

bool hasIBL() { return withIBL; }
bool shootsCaustic() { return shootCaustic; }

protected:
const texture_t *tex;
PROJECTION project;
float power;
float rotation;
float sin_r, cos_r;
bool withIBL;
bool shootCaustic;
bool shootDiffuse;
};

class constBackground_t: public background_t
{
public:
constBackground_t(color_t col);
constBackground_t(color_t col, bool ibl, bool with_caustic);
virtual color_t operator() (const ray_t &ray, renderState_t &state, bool filtered=false) const;
virtual color_t eval(const ray_t &ray, bool filtered=false) const;
virtual ~constBackground_t();
static background_t *factory(paraMap_t &params,renderEnvironment_t &render);
bool hasIBL() { return withIBL; }
bool shootsCaustic() { return shootCaustic; }
protected:
color_t color;
bool withIBL;
bool shootCaustic;
bool shootDiffuse;
};


textureBackground_t::textureBackground_t(const texture_t *texture, PROJECTION proj, float bpower, float rot):
tex(texture), project(proj), power(bpower)
textureBackground_t::textureBackground_t(const texture_t *texture, PROJECTION proj, float bpower, float rot, bool ibl, bool with_caustic):
tex(texture), project(proj), power(bpower), withIBL(ibl), shootCaustic(with_caustic)
{
rotation = 2.0f * rot / 360.f;
sin_r = fSin(M_PI*rotation);
Expand Down Expand Up @@ -149,7 +157,7 @@ background_t* textureBackground_t::factory(paraMap_t &params,renderEnvironment_t
params.getParam("with_caustic", caust);
params.getParam("with_diffuse", diffuse);

background_t *texBG = new textureBackground_t(tex, pr, power, rot);
background_t *texBG = new textureBackground_t(tex, pr, power, rot, IBL, caust);

if(IBL)
{
Expand All @@ -174,7 +182,7 @@ background_t* textureBackground_t::factory(paraMap_t &params,renderEnvironment_t
/ minimalistic background...
/ ========================================= */

constBackground_t::constBackground_t(color_t col) : color(col)
constBackground_t::constBackground_t(color_t col, bool ibl, bool with_caustic) : color(col), withIBL(ibl), shootCaustic(with_caustic)
{
// Empty
}
Expand Down Expand Up @@ -205,7 +213,7 @@ background_t* constBackground_t::factory(paraMap_t &params,renderEnvironment_t &
params.getParam("ibl", IBL);
params.getParam("ibl_samples", IBL_sam);

background_t *constBG = new constBackground_t(col*power);
background_t *constBG = new constBackground_t(col*power, IBL, true);

if(IBL)
{
Expand Down
2 changes: 1 addition & 1 deletion src/integrators/pathtracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ colorA_t pathIntegrator_t::integrate(renderState_t &state, diffRay_t &ray/*, sam

if(!scene->intersect(pRay, *hit2)) //hit background
{
if((caustic && background))
if((caustic && background && background->hasIBL() && background->shootsCaustic()))
{
pathCol += throughput * (*background)(pRay, state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/integrators/photonintegr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ color_t photonIntegrator_t::finalGathering(renderState_t &state, const surfacePo

if(!did_hit) //hit background
{
if(caustic && background)
if(caustic && background && background->hasIBL() && background->shootsCaustic())
{
pathCol += throughput * (*background)(pRay, state);
}
Expand Down

0 comments on commit 3f8cb7f

Please sign in to comment.