Spherical harmonics coefficients are no longer recomputed when the ambient light do not change

This commit is contained in:
Elderme 2015-08-07 13:50:44 +02:00
parent 351be306e1
commit 30ecf34b37
3 changed files with 53 additions and 22 deletions

View File

@ -159,6 +159,7 @@ IrrDriver::~IrrDriver()
m_shadow_matrices = NULL;
Shaders::destroy();
delete m_wind;
delete m_spherical_harmonics;
} // ~IrrDriver
// ----------------------------------------------------------------------------
@ -507,6 +508,7 @@ void IrrDriver::initDevice()
CVS->init();
m_spherical_harmonics = new SphericalHarmonics(m_scene_manager->getAmbientLight().toSColor());
if (UserConfigParams::m_shadows_resolution != 0 &&
(UserConfigParams::m_shadows_resolution < 512 ||
@ -1375,8 +1377,11 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*> &tex
//prepareSkybox();
//m_skybox_ready = true;
m_skybox = new Skybox(texture);
if(spherical_harmonics_textures.size() == 6)
{
m_spherical_harmonics->setTextures(spherical_harmonics_textures);
}
/*if(spherical_harmonics_textures.size() == 6)
{
if(m_spherical_harmonics != NULL)
{
@ -1387,7 +1392,7 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*> &tex
else
{
//m_spherical_harmonic = new SphericalHarmonic(m_scene_manager->getAmbientLight().toSColor());
}
}*/
return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1],
texture[2], texture[3],
@ -1409,8 +1414,8 @@ void IrrDriver::suppressSkyBox()
SkyboxSpecularProbe = 0;*/
delete m_skybox;
m_skybox = NULL;
delete m_spherical_harmonics;
m_spherical_harmonics = NULL;
//delete m_spherical_harmonics;
//m_spherical_harmonics = NULL;
}
// ----------------------------------------------------------------------------
@ -1790,10 +1795,11 @@ void IrrDriver::onUnloadWorld()
void IrrDriver::setAmbientLight(const video::SColorf &light)
{
m_scene_manager->setAmbientLight(light);
m_spherical_harmonics->setAmbientLight(light.toSColor());
//TODO!
if(m_spherical_harmonics == NULL)
m_spherical_harmonics = new SphericalHarmonics(light.toSColor());
//if(m_spherical_harmonics == NULL)
// m_spherical_harmonics = new SphericalHarmonics(light.toSColor());
//m_skybox_ready = false;
} // setAmbientLight

View File

@ -357,6 +357,23 @@ void SphericalHarmonics::generateSphericalHarmonics(Color *cubemap_face[6], size
// ----------------------------------------------------------------------------
SphericalHarmonics::SphericalHarmonics(const std::vector<video::ITexture *> &spherical_harmonics_textures)
{
setTextures(spherical_harmonics_textures);
}
// ----------------------------------------------------------------------------
/** When spherical harmonics textures are not defined, SH coefficents are computed
* from ambient light
*/
SphericalHarmonics::SphericalHarmonics(const video::SColor &ambient)
{
//make sure m_ambient and ambient are not equal
m_ambient = (ambient==0) ? 1 : 0;
setAmbientLight(ambient);
}
/** Compute spherical harmonics coefficients from 6 textures */
void SphericalHarmonics::setTextures(const std::vector<video::ITexture *> &spherical_harmonics_textures)
{
assert(spherical_harmonics_textures.size() == 6);
@ -400,15 +417,18 @@ SphericalHarmonics::SphericalHarmonics(const std::vector<video::ITexture *> &sph
delete[] sh_rgba[i];
delete[] float_tex_cube[i];
}
} //setSphericalHarmonicsTextures
}// SphericalHarmonics(const std::vector<video::ITexture *> &spherical_harmonics_textures)
// ----------------------------------------------------------------------------
/** When spherical harmonics textures are not defined, SH coefficents are computed
* from ambient light
*/
SphericalHarmonics::SphericalHarmonics(const video::SColor &ambient)
/** Compute spherical harmonics coefficients from ambient light */
void SphericalHarmonics::setAmbientLight(const video::SColor &ambient)
{
//do not recompute SH coefficients if we already use the same ambient light
if((m_spherical_harmonics_textures.size() != 6) && (ambient == m_ambient))
return;
m_spherical_harmonics_textures.clear();
m_ambient = ambient;
unsigned char *sh_rgba[6];
unsigned sh_w = 16;
unsigned sh_h = 16;
@ -443,10 +463,10 @@ SphericalHarmonics::SphericalHarmonics(const video::SColor &ambient)
m_green_SH_coeff[i] *= 4;
m_red_SH_coeff[i] *= 4;
}
}// SphericalHarmonics(const video::SColor &ambient)
} //setAmbientLight
// ----------------------------------------------------------------------------
/** Print spherical harmonics coefficients (debug) */
void SphericalHarmonics::printCoeff() {
Log::debug("SphericalHarmonics", "Blue_SH:");
displayCoeff(m_blue_SH_coeff);

View File

@ -36,11 +36,15 @@ private:
/** The 6 spherical harmonics textures */
std::vector<irr::video::ITexture *> m_spherical_harmonics_textures;
/** Ambient light is used for tracks without spherical harmonics textures */
irr::video::SColor m_ambient;
/** The spherical harmonics coefficients */
float m_blue_SH_coeff[9];
float m_green_SH_coeff[9];
float m_red_SH_coeff[9];
void projectSH(Color *cubemap_face[6], size_t edge_size, float *Y00[],
float *Y1minus1[], float *Y10[], float *Y11[],
float *Y2minus2[], float *Y2minus1[], float * Y20[],
@ -52,14 +56,15 @@ public:
SphericalHarmonics(const std::vector<irr::video::ITexture *> &spherical_harmonics_textures);
SphericalHarmonics(const irr::video::SColor &ambient);
void setTextures(const std::vector<irr::video::ITexture *> &spherical_harmonics_textures);
void setAmbientLight(const irr::video::SColor &ambient);
inline const float* getBlueSHCoeff () const {return m_blue_SH_coeff; }
inline const float* getGreenSHCoeff() const {return m_green_SH_coeff; }
inline const float* getRedSHCoeff () const {return m_red_SH_coeff; }
/** Print spherical harmonics coefficients (debug) */
void printCoeff();
/** Compute environment map from the spherical harmonics */
void unprojectSH (size_t width, size_t height,
float *Y00[], float *Y1minus1[], float *Y10[],
float *Y11[], float *Y2minus2[], float *Y2minus1[],