Load textures for ambient lights separately from skybox textures

This commit is contained in:
Marianne Gagnon 2014-04-21 20:25:51 -04:00
parent e57339841b
commit 5373390fac
6 changed files with 95 additions and 6 deletions

View File

@ -1165,11 +1165,12 @@ scene::ISceneNode *IrrDriver::addSkyDome(video::ITexture *texture,
* \param front: Texture for the front plane of the box.
* \param back: Texture for the back plane of the box.
*/
scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*>
&texture)
scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*> &texture,
const std::vector<video::ITexture*> &sphericalHarmonics)
{
assert(texture.size() == 6);
SkyboxTextures = texture;
SphericalHarmonicsTextures = sphericalHarmonics;
SkyboxCubeMap = 0;
return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1],
texture[2], texture[3],
@ -1179,6 +1180,7 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*>
void IrrDriver::suppressSkyBox()
{
SkyboxTextures.clear();
SphericalHarmonicsTextures.clear();
if (SkyboxCubeMap)
glDeleteTextures(1, &SkyboxCubeMap);
SkyboxCubeMap = 0;

View File

@ -116,6 +116,7 @@ private:
core::matrix4 m_ViewMatrix, m_InvViewMatrix, m_ProjMatrix, m_InvProjMatrix, m_ProjViewMatrix, m_InvProjViewMatrix;
std::vector<video::ITexture *> SkyboxTextures;
std::vector<video::ITexture *> SphericalHarmonicsTextures;
float blueSHCoeff[9];
float greenSHCoeff[9];
@ -302,7 +303,8 @@ public:
scene::ISceneNode *addSkyDome(video::ITexture *texture, int hori_res,
int vert_res, float texture_percent,
float sphere_percent);
scene::ISceneNode *addSkyBox(const std::vector<video::ITexture*> &texture_names);
scene::ISceneNode *addSkyBox(const std::vector<video::ITexture*> &texture_names,
const std::vector<video::ITexture*> &sphericalHarmonics);
void suppressSkyBox();
void removeNode(scene::ISceneNode *node);
void removeMeshFromCache(scene::IMesh *mesh);

View File

@ -1351,7 +1351,60 @@ void IrrDriver::generateSkyboxCubemap()
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
}
testSH(rgba, w, h, blueSHCoeff, greenSHCoeff, redSHCoeff);
if (SphericalHarmonicsTextures.size() == 6)
{
unsigned sh_w = 0, sh_h = 0;
for (unsigned i = 0; i < 6; i++)
{
sh_w = MAX2(sh_w, SphericalHarmonicsTextures[i]->getOriginalSize().Width);
sh_h = MAX2(sh_h, SphericalHarmonicsTextures[i]->getOriginalSize().Height);
}
char *sh_rgba[6];
for (unsigned i = 0; i < 6; i++)
sh_rgba[i] = new char[sh_w * sh_h * 4];
for (unsigned i = 0; i < 6; i++)
{
unsigned idx = texture_permutation[i];
video::IImage* image = getVideoDriver()->createImageFromData(
SphericalHarmonicsTextures[idx]->getColorFormat(),
SphericalHarmonicsTextures[idx]->getSize(),
SphericalHarmonicsTextures[idx]->lock(),
false
);
SphericalHarmonicsTextures[idx]->unlock();
image->copyToScaling(sh_rgba[i], sh_w, sh_h);
image->drop();
}
testSH(sh_rgba, sh_w, sh_h, blueSHCoeff, greenSHCoeff, redSHCoeff);
for (unsigned i = 0; i < 6; i++)
delete[] sh_rgba[i];
}
else
{
int sh_w = 16;
int sh_h = 16;
char *sh_rgba[6];
for (unsigned i = 0; i < 6; i++)
{
sh_rgba[i] = new char[sh_w * sh_h * 4];
for (int j = 0; j < sh_w * sh_h * 4; j++)
{
sh_rgba[i][j] = 150;
}
}
testSH(sh_rgba, sh_w, sh_h, blueSHCoeff, greenSHCoeff, redSHCoeff);
for (unsigned i = 0; i < 6; i++)
delete[] sh_rgba[i];
}
for (unsigned i = 0; i < 6; i++)
delete[] rgba[i];

View File

@ -270,7 +270,8 @@ void FeatureUnlockedCutScene::init()
video::ITexture *t = irr_driver->getTexture(texture_names[i]);
textures.push_back(t);
}
m_sky = irr_driver->addSkyBox(textures);
std::vector<video::ITexture*> sh_textures;
m_sky = irr_driver->addSkyBox(textures, sh_textures);
#ifdef DEBUG
m_sky->setName("skybox");
#endif

View File

@ -285,6 +285,14 @@ void Track::cleanup()
}
m_sky_textures.clear();
for (unsigned int i = 0; i<m_spherical_harmonics_textures.size(); i++)
{
m_spherical_harmonics_textures[i]->drop();
if (m_spherical_harmonics_textures[i]->getReferenceCount() == 1)
irr_driver->removeTexture(m_spherical_harmonics_textures[i]);
}
m_spherical_harmonics_textures.clear();
if(m_cache_track)
material_manager->makeMaterialsPermanent();
else
@ -1643,7 +1651,10 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
}
else if(m_sky_type==SKY_BOX && m_sky_textures.size() == 6)
{
m_all_nodes.push_back(irr_driver->addSkyBox(m_sky_textures));
//if (m_spherical_harmonics_textures.size() > 0)
m_all_nodes.push_back(irr_driver->addSkyBox(m_sky_textures, m_spherical_harmonics_textures));
//else
// m_all_nodes.push_back(irr_driver->addSkyBox(m_sky_textures, m_sky_textures));
}
else if(m_sky_type==SKY_COLOR)
{
@ -2097,6 +2108,24 @@ void Track::handleSky(const XMLNode &xml_node, const std::string &filename)
{
m_sky_type = SKY_BOX;
}
std::string sh_textures;
xml_node.get("sh-texture", &sh_textures);
v = StringUtils::split(sh_textures, ' ');
for (unsigned int i = 0; i<v.size(); i++)
{
video::ITexture *t = irr_driver->getTexture(v[i]);
if (t)
{
t->grab();
m_spherical_harmonics_textures.push_back(t);
}
else
{
Log::error("track", "Sky-box spherical harmonics texture '%s' not found - ignored.",
v[i].c_str());
}
} // for i<v.size()
}
else if (xml_node.getName() == "sky-color")
{

View File

@ -281,6 +281,8 @@ private:
* in case of a dome, and 6 textures for a box. */
std::vector<video::ITexture*> m_sky_textures;
std::vector<video::ITexture*> m_spherical_harmonics_textures;
/** Used if m_sky_type is SKY_COLOR only */
irr::video::SColor m_sky_color;