Spherical harmonics coefficients are no longer recomputed when the ambient light do not change
This commit is contained in:
parent
351be306e1
commit
30ecf34b37
@ -159,6 +159,7 @@ IrrDriver::~IrrDriver()
|
|||||||
m_shadow_matrices = NULL;
|
m_shadow_matrices = NULL;
|
||||||
Shaders::destroy();
|
Shaders::destroy();
|
||||||
delete m_wind;
|
delete m_wind;
|
||||||
|
delete m_spherical_harmonics;
|
||||||
} // ~IrrDriver
|
} // ~IrrDriver
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -507,6 +508,7 @@ void IrrDriver::initDevice()
|
|||||||
|
|
||||||
CVS->init();
|
CVS->init();
|
||||||
|
|
||||||
|
m_spherical_harmonics = new SphericalHarmonics(m_scene_manager->getAmbientLight().toSColor());
|
||||||
|
|
||||||
if (UserConfigParams::m_shadows_resolution != 0 &&
|
if (UserConfigParams::m_shadows_resolution != 0 &&
|
||||||
(UserConfigParams::m_shadows_resolution < 512 ||
|
(UserConfigParams::m_shadows_resolution < 512 ||
|
||||||
@ -1375,8 +1377,11 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*> &tex
|
|||||||
//prepareSkybox();
|
//prepareSkybox();
|
||||||
//m_skybox_ready = true;
|
//m_skybox_ready = true;
|
||||||
m_skybox = new Skybox(texture);
|
m_skybox = new Skybox(texture);
|
||||||
|
|
||||||
if(spherical_harmonics_textures.size() == 6)
|
if(spherical_harmonics_textures.size() == 6)
|
||||||
|
{
|
||||||
|
m_spherical_harmonics->setTextures(spherical_harmonics_textures);
|
||||||
|
}
|
||||||
|
/*if(spherical_harmonics_textures.size() == 6)
|
||||||
{
|
{
|
||||||
if(m_spherical_harmonics != NULL)
|
if(m_spherical_harmonics != NULL)
|
||||||
{
|
{
|
||||||
@ -1387,7 +1392,7 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*> &tex
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//m_spherical_harmonic = new SphericalHarmonic(m_scene_manager->getAmbientLight().toSColor());
|
//m_spherical_harmonic = new SphericalHarmonic(m_scene_manager->getAmbientLight().toSColor());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1],
|
return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1],
|
||||||
texture[2], texture[3],
|
texture[2], texture[3],
|
||||||
@ -1409,8 +1414,8 @@ void IrrDriver::suppressSkyBox()
|
|||||||
SkyboxSpecularProbe = 0;*/
|
SkyboxSpecularProbe = 0;*/
|
||||||
delete m_skybox;
|
delete m_skybox;
|
||||||
m_skybox = NULL;
|
m_skybox = NULL;
|
||||||
delete m_spherical_harmonics;
|
//delete m_spherical_harmonics;
|
||||||
m_spherical_harmonics = NULL;
|
//m_spherical_harmonics = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -1790,10 +1795,11 @@ void IrrDriver::onUnloadWorld()
|
|||||||
void IrrDriver::setAmbientLight(const video::SColorf &light)
|
void IrrDriver::setAmbientLight(const video::SColorf &light)
|
||||||
{
|
{
|
||||||
m_scene_manager->setAmbientLight(light);
|
m_scene_manager->setAmbientLight(light);
|
||||||
|
m_spherical_harmonics->setAmbientLight(light.toSColor());
|
||||||
//TODO!
|
//TODO!
|
||||||
|
|
||||||
if(m_spherical_harmonics == NULL)
|
//if(m_spherical_harmonics == NULL)
|
||||||
m_spherical_harmonics = new SphericalHarmonics(light.toSColor());
|
// m_spherical_harmonics = new SphericalHarmonics(light.toSColor());
|
||||||
|
|
||||||
//m_skybox_ready = false;
|
//m_skybox_ready = false;
|
||||||
} // setAmbientLight
|
} // setAmbientLight
|
||||||
|
@ -357,6 +357,23 @@ void SphericalHarmonics::generateSphericalHarmonics(Color *cubemap_face[6], size
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
SphericalHarmonics::SphericalHarmonics(const std::vector<video::ITexture *> &spherical_harmonics_textures)
|
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);
|
assert(spherical_harmonics_textures.size() == 6);
|
||||||
|
|
||||||
@ -400,15 +417,18 @@ SphericalHarmonics::SphericalHarmonics(const std::vector<video::ITexture *> &sph
|
|||||||
delete[] sh_rgba[i];
|
delete[] sh_rgba[i];
|
||||||
delete[] float_tex_cube[i];
|
delete[] float_tex_cube[i];
|
||||||
}
|
}
|
||||||
|
} //setSphericalHarmonicsTextures
|
||||||
|
|
||||||
}// SphericalHarmonics(const std::vector<video::ITexture *> &spherical_harmonics_textures)
|
/** Compute spherical harmonics coefficients from ambient light */
|
||||||
|
void SphericalHarmonics::setAmbientLight(const video::SColor &ambient)
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
/** When spherical harmonics textures are not defined, SH coefficents are computed
|
|
||||||
* from ambient light
|
|
||||||
*/
|
|
||||||
SphericalHarmonics::SphericalHarmonics(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 char *sh_rgba[6];
|
||||||
unsigned sh_w = 16;
|
unsigned sh_w = 16;
|
||||||
unsigned sh_h = 16;
|
unsigned sh_h = 16;
|
||||||
@ -443,10 +463,10 @@ SphericalHarmonics::SphericalHarmonics(const video::SColor &ambient)
|
|||||||
m_green_SH_coeff[i] *= 4;
|
m_green_SH_coeff[i] *= 4;
|
||||||
m_red_SH_coeff[i] *= 4;
|
m_red_SH_coeff[i] *= 4;
|
||||||
}
|
}
|
||||||
|
} //setAmbientLight
|
||||||
}// SphericalHarmonics(const video::SColor &ambient)
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Print spherical harmonics coefficients (debug) */
|
||||||
void SphericalHarmonics::printCoeff() {
|
void SphericalHarmonics::printCoeff() {
|
||||||
Log::debug("SphericalHarmonics", "Blue_SH:");
|
Log::debug("SphericalHarmonics", "Blue_SH:");
|
||||||
displayCoeff(m_blue_SH_coeff);
|
displayCoeff(m_blue_SH_coeff);
|
||||||
|
@ -36,11 +36,15 @@ private:
|
|||||||
/** The 6 spherical harmonics textures */
|
/** The 6 spherical harmonics textures */
|
||||||
std::vector<irr::video::ITexture *> m_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 */
|
/** The spherical harmonics coefficients */
|
||||||
float m_blue_SH_coeff[9];
|
float m_blue_SH_coeff[9];
|
||||||
float m_green_SH_coeff[9];
|
float m_green_SH_coeff[9];
|
||||||
float m_red_SH_coeff[9];
|
float m_red_SH_coeff[9];
|
||||||
|
|
||||||
|
|
||||||
void projectSH(Color *cubemap_face[6], size_t edge_size, float *Y00[],
|
void projectSH(Color *cubemap_face[6], size_t edge_size, float *Y00[],
|
||||||
float *Y1minus1[], float *Y10[], float *Y11[],
|
float *Y1minus1[], float *Y10[], float *Y11[],
|
||||||
float *Y2minus2[], float *Y2minus1[], float * Y20[],
|
float *Y2minus2[], float *Y2minus1[], float * Y20[],
|
||||||
@ -52,14 +56,15 @@ public:
|
|||||||
SphericalHarmonics(const std::vector<irr::video::ITexture *> &spherical_harmonics_textures);
|
SphericalHarmonics(const std::vector<irr::video::ITexture *> &spherical_harmonics_textures);
|
||||||
SphericalHarmonics(const irr::video::SColor &ambient);
|
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* getBlueSHCoeff () const {return m_blue_SH_coeff; }
|
||||||
inline const float* getGreenSHCoeff() const {return m_green_SH_coeff; }
|
inline const float* getGreenSHCoeff() const {return m_green_SH_coeff; }
|
||||||
inline const float* getRedSHCoeff () const {return m_red_SH_coeff; }
|
inline const float* getRedSHCoeff () const {return m_red_SH_coeff; }
|
||||||
|
|
||||||
/** Print spherical harmonics coefficients (debug) */
|
|
||||||
void printCoeff();
|
void printCoeff();
|
||||||
|
|
||||||
/** Compute environment map from the spherical harmonics */
|
|
||||||
void unprojectSH (size_t width, size_t height,
|
void unprojectSH (size_t width, size_t height,
|
||||||
float *Y00[], float *Y1minus1[], float *Y10[],
|
float *Y00[], float *Y1minus1[], float *Y10[],
|
||||||
float *Y11[], float *Y2minus2[], float *Y2minus1[],
|
float *Y11[], float *Y2minus2[], float *Y2minus1[],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user