Historique des modifications - Message

Message #11796

Sujet: Changer la coloration de la texture d'une skybox


TypeDateAuteurContenu
Dernière modification11-05-2017 20:57:22jonath313
Ok merci pour ton aide c'est vraiment sympas.
Néanmoins il m'affiche la même texture sur tous les layer ...

Code c++ :

 
irr::core::array<irr::video::ITexture*> rendered;

void set_color(array<irr::video::ITexture*> skybox, vector3df RedCoef, vector3df GreenCoef, vector3df BlueCoef,float colorCoeff)
{
	for(int i = 0; i<skybox.size(); ++i)
	{
		irr::core::stringc name = "skybox_";
		name += i;
		rendered.push_back(driver->addTexture(skybox[0]-> getSize(), name.c_str(), skybox[0]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[1]-> getSize(), name.c_str(), skybox[1]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[2]-> getSize(), name.c_str(), skybox[2]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[3]-> getSize(), name.c_str(), skybox[3]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[4]-> getSize(), name.c_str(), skybox[4]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[5]-> getSize(), name.c_str(), skybox[5]-> getColorFormat()));
	}


	for(unsigned i = 0; i<skybox.size(); ++i)
	{
	  irr::video::SColor color;
	  unsigned char *src = (unsigned char*) skybox[i]->lock(ETLM_READ_ONLY);
	  unsigned char *dst = (unsigned char*) rendered[i]->lock(ETLM_WRITE_ONLY);

	  u32 pitch = skybox[i]->getPitch();
	  u32 bytes = video::IImage::getBitsPerPixelFromFormat(skybox[i]->getColorFormat()) / 8;


	  for(unsigned x = 0; x<skybox[i]->getSize().Width; ++x)
	  {
		  for(unsigned y = 0; y<skybox[i]->getSize().Height; ++y)
		  {
			  unsigned char *in = src + (y * pitch) + (x * bytes);
			  unsigned char *out = dst + (y * pitch) + (x * bytes);

			  color.setData(in, skybox[i]->getColorFormat());

			  
			  float r = color.getRed() / 255.f;
			  float g = color.getGreen() / 255.f;
			  float b = color.getBlue() / 255.f;

			  float rsepia = r * RedCoef.X + g * RedCoef.Y + b * RedCoef.Z;
			  float gsepia = r * GreenCoef.X + g * GreenCoef.Y + b * GreenCoef.Z;
			  float bsepia = r * BlueCoef.X + g * BlueCoef.Y + b * BlueCoef.Z;

			  r = colorCoeff*r + (1.0-colorCoeff)*rsepia;
			  g = colorCoeff*g + (1.0-colorCoeff)*gsepia;
			  b = colorCoeff*g + (1.0-colorCoeff)*bsepia;

			  color.setRed(std::min(r * 225.f, 255.f));
			  color.setGreen(std::min(g * 225.f, 255.f));
			  color.setBlue(std::min(b * 225.f, 255.f));

			  color.getData(out, skybox[i]->getColorFormat());
		  }
	  }

	rendered[i]->unlock();
	skybox[i]->unlock();
	}
}


Utilisation :

Code c++ :


                    	set_color(	skybox,
                                    vector3df(0.393, 0.769, 0.189), 	//RedCoef,
                                    vector3df(0.349, 0.686, 0.168), 	//GreenCoef,
                                    vector3df(0.272, 0.534, 0.131), 	//BlueCoef,
                                    0.5f);		//colorCoeff

                        skyboxNode->setMaterialTexture (0, rendered[0]);
                        skyboxNode->setMaterialTexture (1, rendered[1]);
                        skyboxNode->setMaterialTexture (4, rendered[4]);
                        skyboxNode->setMaterialTexture (5, rendered[5]);
                        skyboxNode->setMaterialTexture (3, rendered[3]);
                        skyboxNode->setMaterialTexture (2, rendered[2]);


Initialisation :

Code c++ :


  irr::core::array<irr::video::ITexture*> skybox;
  skybox.push_back(driver->getTexture("Daylight_Box_Top.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Bottom.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Left.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Right.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Front.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Back.bmp"));

	set_color(	skybox,
                vector3df(0.393, 0.769, 0.189), 	//RedCoef,
				vector3df(0.349, 0.686, 0.168), 	//GreenCoef,
				vector3df(0.272, 0.534, 0.131), 	//BlueCoef,
				0.8f);		//colorCoeff

        scene::ISceneNode* skyboxNode = smgr->addSkyBoxSceneNode(
                                                            rendered[0],
                                                            rendered[1],
                                                            rendered[4],
                                                            rendered[5],
                                                            rendered[3],
                                                            rendered[2]);


Il y a quelque chose qui m'échappe ?


... Bon je viens de ruiner tout mon code ...
Après y avoir fait fonctionné, je me suis rendu compte que çà lagait énnormément.
J'ai alors pensé charger les 24 textures x 6 textures correspondants chacune à une heure de la journée pour la coloration du ciel et là je me suis perdu et mon programme est planté.

Visiblement quand je fais le code suivant les textures ne sont pas appliquées correctement :

skyboxNode->setMaterialTexture(0, SkyTexRender[0]);
skyboxNode->setMaterialTexture(1, SkyTexRender[1]);
skyboxNode->setMaterialTexture(2, SkyTexRender[2]);
skyboxNode->setMaterialTexture(3, SkyTexRender[3]);
skyboxNode->setMaterialTexture(4, SkyTexRender[4]);
skyboxNode->setMaterialTexture(5, SkyTexRender[5]);

On ne peut pas réappliquer une texture existante sur une skybox ? (j'ai essayé sur un skydome çà fonctionne)

Je me demande si je devrais pas plutot créer 24 skybox et faire toutes les couleurs à la main sur Gimp parceque là je ne vois vraiment pas comment çà peut se résoudre
Création du message11-05-2017 14:12:49jonath313
Ok merci pour ton aide c'est vraiment sympas.
Néanmoins il m'affiche la même texture sur tous les layer ...

Code c++ :

 
irr::core::array<irr::video::ITexture*> rendered;

void set_color(array<irr::video::ITexture*> skybox, vector3df RedCoef, vector3df GreenCoef, vector3df BlueCoef,float colorCoeff)
{
	for(int i = 0; i<skybox.size(); ++i)
	{
		irr::core::stringc name = "skybox_";
		name += i;
		rendered.push_back(driver->addTexture(skybox[0]-> getSize(), name.c_str(), skybox[0]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[1]-> getSize(), name.c_str(), skybox[1]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[2]-> getSize(), name.c_str(), skybox[2]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[3]-> getSize(), name.c_str(), skybox[3]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[4]-> getSize(), name.c_str(), skybox[4]-> getColorFormat()));
		rendered.push_back(driver->addTexture(skybox[5]-> getSize(), name.c_str(), skybox[5]-> getColorFormat()));
	}


	for(unsigned i = 0; i<skybox.size(); ++i)
	{
	  irr::video::SColor color;
	  unsigned char *src = (unsigned char*) skybox[i]->lock(ETLM_READ_ONLY);
	  unsigned char *dst = (unsigned char*) rendered[i]->lock(ETLM_WRITE_ONLY);

	  u32 pitch = skybox[i]->getPitch();
	  u32 bytes = video::IImage::getBitsPerPixelFromFormat(skybox[i]->getColorFormat()) / 8;


	  for(unsigned x = 0; x<skybox[i]->getSize().Width; ++x)
	  {
		  for(unsigned y = 0; y<skybox[i]->getSize().Height; ++y)
		  {
			  unsigned char *in = src + (y * pitch) + (x * bytes);
			  unsigned char *out = dst + (y * pitch) + (x * bytes);

			  color.setData(in, skybox[i]->getColorFormat());

			  
			  float r = color.getRed() / 255.f;
			  float g = color.getGreen() / 255.f;
			  float b = color.getBlue() / 255.f;

			  float rsepia = r * RedCoef.X + g * RedCoef.Y + b * RedCoef.Z;
			  float gsepia = r * GreenCoef.X + g * GreenCoef.Y + b * GreenCoef.Z;
			  float bsepia = r * BlueCoef.X + g * BlueCoef.Y + b * BlueCoef.Z;

			  r = colorCoeff*r + (1.0-colorCoeff)*rsepia;
			  g = colorCoeff*g + (1.0-colorCoeff)*gsepia;
			  b = colorCoeff*g + (1.0-colorCoeff)*bsepia;

			  color.setRed(std::min(r * 225.f, 255.f));
			  color.setGreen(std::min(g * 225.f, 255.f));
			  color.setBlue(std::min(b * 225.f, 255.f));

			  color.getData(out, skybox[i]->getColorFormat());
		  }
	  }

	rendered[i]->unlock();
	skybox[i]->unlock();
	}
}


Utilisation :

Code c++ :


                    	set_color(	skybox,
                                    vector3df(0.393, 0.769, 0.189), 	//RedCoef,
                                    vector3df(0.349, 0.686, 0.168), 	//GreenCoef,
                                    vector3df(0.272, 0.534, 0.131), 	//BlueCoef,
                                    0.5f);		//colorCoeff

                        skyboxNode->setMaterialTexture (0, rendered[0]);
                        skyboxNode->setMaterialTexture (1, rendered[1]);
                        skyboxNode->setMaterialTexture (4, rendered[4]);
                        skyboxNode->setMaterialTexture (5, rendered[5]);
                        skyboxNode->setMaterialTexture (3, rendered[3]);
                        skyboxNode->setMaterialTexture (2, rendered[2]);


Initialisation :

Code c++ :


  irr::core::array<irr::video::ITexture*> skybox;
  skybox.push_back(driver->getTexture("Daylight_Box_Top.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Bottom.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Left.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Right.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Front.bmp"));
  skybox.push_back(driver->getTexture("Daylight_Box_Back.bmp"));

	set_color(	skybox,
                vector3df(0.393, 0.769, 0.189), 	//RedCoef,
				vector3df(0.349, 0.686, 0.168), 	//GreenCoef,
				vector3df(0.272, 0.534, 0.131), 	//BlueCoef,
				0.8f);		//colorCoeff

        scene::ISceneNode* skyboxNode = smgr->addSkyBoxSceneNode(
                                                            rendered[0],
                                                            rendered[1],
                                                            rendered[4],
                                                            rendered[5],
                                                            rendered[3],
                                                            rendered[2]);


Il y a quelque chose qui m'échappe ?


... Bon je viens de ruiner tout mon code ...
Après y avoir fait fonctionné, je me suis rendu compte que çà lagait énnormément.
J'ai alors pensé charger les 24 textures x 6 textures correspondants chacune à une heure de la journée pour la coloration du ciel et là je me suis perdu et mon programme est planté.

Visiblement quand je fais le code suivant les textures ne sont pas appliquées correctement :

skyboxNode->setMaterialTexture(0, SkyTexRender[0]);
skyboxNode->setMaterialTexture(1, SkyTexRender[1]);
skyboxNode->setMaterialTexture(2, SkyTexRender[2]);
skyboxNode->setMaterialTexture(3, SkyTexRender[3]);
skyboxNode->setMaterialTexture(4, SkyTexRender[4]);
skyboxNode->setMaterialTexture(5, SkyTexRender[5]);

On ne peut pas réappliquer une texture existante sur une skybox ? (j'ai essayé sur un skydome çà fonctionne)

Je me demande si je devrais pas plutot créer 24 skybox et faire toutes les couleurs à la main sur Gimp parceque là je ne vois vraiment pas comment çà peut se résoudre

Retour

OptionsLiens officielsCaractéristiquesStatistiquesCommunauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1441 sujets
11339 messages
Dernier membre inscrit: Saidov17
65 invités en ligne
membre en ligne: -
RSS Feed