Coloring the nodes (in realtime)
Coloring the nodes (in realtime)
Hi
Can i use a single model file (3ds or whatever) and then color them to (for example) make a blue and red tank, so i can set which team they belong to?
Thanks
Erik
Can i use a single model file (3ds or whatever) and then color them to (for example) make a blue and red tank, so i can set which team they belong to?
Thanks
Erik
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: Coloring the nodes (in realtime)
Yes that's easy If your using Irrlicht default shaders or your own you could just assign the color values in your app like this.
And some where in your app the "yourcolor's above" can be assigned and changed by some event.
Code: Select all
video::SColorf RColor(yourcolorRED, yourcolorGREEN, yourcolorBLUE, yourcolorALPHA); // use this line If it's a Irrlicht standard shader.
services->setPixelShaderConstant(ColorDiffuse, reinterpret_cast<f32*>(&RColor), 4); // Use both lines in shader callback If it's a custom or non Irrlicht shader.
Re: Coloring the nodes (in realtime)
You can also set a different texture to each instance of the model.
Re: Coloring the nodes (in realtime)
Thanks!
But typically i make 3ds-files and add the textures in 3dS max, and then just keep the texture files in the same folder. Is there any irrlicht guide how to handle models/meshes? I mean a REALLY noob-friendly one? (concerning lightning, different fileformats, texturing etc). Ive looked at the tutorials but they dont really help.
Erik
But typically i make 3ds-files and add the textures in 3dS max, and then just keep the texture files in the same folder. Is there any irrlicht guide how to handle models/meshes? I mean a REALLY noob-friendly one? (concerning lightning, different fileformats, texturing etc). Ive looked at the tutorials but they dont really help.
Erik
Re: Coloring the nodes (in realtime)
http://irrlicht.sourceforge.net/forum/v ... =6&t=49868
Guess what I did here A shader uniform similar to The_Glitch's.
Guess what I did here A shader uniform similar to The_Glitch's.
Re: Coloring the nodes (in realtime)
If it's single-color you don't need a shader. You can set the SMaterial color values. You can use example 22 to test differnt effect combinations (and yeah - the gui of that examples is still confusing which is my fault, I'll improve it some day).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Coloring the nodes (in realtime)
single color might work, i try this:
But it doesnt turn red. Probably im way off, could you help me with the calls? I want to "multiply" the already present colors (all textures of the model).
(i have no global light (or any lights at all for that matter right now) so i turn of lighting, is this wrong? I can see all textures fully lit all the time)
Code: Select all
o->node= gfx.smgr->addAnimatedMeshSceneNode( rrr.unitMeshes[type],0,1,vect3d(0,0,0),vect3d(0,0,0),vect3d(scale,scale,scale));
o->node->setMaterialFlag(video::EMF_LIGHTING,false);
o->node->setMaterialFlag(EMF_FOG_ENABLE, true);
o->node->setPosition(o->pos);
o->node->getMaterial(0).AmbientColor = SColor(255,255,0,0);
(i have no global light (or any lights at all for that matter right now) so i turn of lighting, is this wrong? I can see all textures fully lit all the time)
Re: Coloring the nodes (in realtime)
You've turned off lighting, so the ambient colour will not be used. I think you should be looking at the diffuse colour.
Re: Coloring the nodes (in realtime)
You mean like this:
Still nothing changes. I want to be able to darken, or tint all the node (preferably without adding light sources).
I dont know if this is needed, but still doesnt work
Code: Select all
o->node->getMaterial(0).DiffuseColor.set(255,255,0,0);
I dont know if this is needed, but still doesnt work
Code: Select all
int matCount=o->node->getMaterialCount();
for(int i=0;i<matCount;i++)
o->node->getMaterial(i).DiffuseColor.set(255,255,0,0);
Re: Coloring the nodes (in realtime)
Hi mate,
I'm using this function below.
You can extract and use any part below. I think it will work.
Goodluck
I'm using this function below.
You can extract and use any part below. I think it will work.
Code: Select all
void SetNodeColor(ISceneManager *smgr, video::IVideoDriver *driver, ISceneNode *node, video::SColor newColor)
{
if (node->getType() == ESCENE_NODE_TYPE::ESNT_ANIMATED_MESH)
{
driver->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
video::ITexture* texture = driver->addTexture(core::dimension2d<u32>(1, 1), "onTheFly", video::ECF_A8R8G8B8);
driver->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true);
// get pointer to texture data
u32* p = (u32*)texture->lock();
p[0] = newColor.color;
texture->unlock();
IAnimatedMeshSceneNode *animNode = static_cast<IAnimatedMeshSceneNode*>(node);
IAnimatedMesh *mesh = animNode->getMesh();
node->setMaterialTexture(0, texture);
}
if (node->getType() == ESNT_MESH
|| node->getType() == ESNT_CUBE
|| node->getType() == ESNT_SPHERE
|| node->getType() == ESNT_WATER_SURFACE
|| node->getType() == ESNT_Q3SHADER_SCENE_NODE
|| node->getType() == ESNT_OCTREE
)
{
IMesh *mesh = static_cast<IMeshSceneNode*>(node)->getMesh();
smgr->getMeshManipulator()->setVertexColors(mesh, newColor);
}
if (node->getType() == ESNT_TERRAIN)
{
IMesh *mesh = static_cast<ITerrainSceneNode*>(node)->getMesh();
smgr->getMeshManipulator()->setVertexColors(mesh, newColor);
}
}
Re: Coloring the nodes (in realtime)
Hi!
It works but it just overwrites every texture, replacing them with a single solid color (ignoring alpha of the supplied color).
Is there a way to tint the existing node, so it gets some color, but still remains the textures?
It works but it just overwrites every texture, replacing them with a single solid color (ignoring alpha of the supplied color).
Is there a way to tint the existing node, so it gets some color, but still remains the textures?
Re: Coloring the nodes (in realtime)
Sorry mate,
The only way I know how to do that is with light setting. I'm just on the basic level of knowledge on lighting atm.
Maybe irrlicht should allows us to do that without light enable. I think that would be useful. The lib dev should look into this.
Or try Glitch method as above.
Cheers
The only way I know how to do that is with light setting. I'm just on the basic level of knowledge on lighting atm.
Maybe irrlicht should allows us to do that without light enable. I think that would be useful. The lib dev should look into this.
Or try Glitch method as above.
Cheers
Re: Coloring the nodes (in realtime)
Have you tried just changing the vertex colours. You do realise, don't you, that thanle's code creates and sets a new texture? Try leaving that texture code out. It is possible, in the fixed-function pipeline, that the vertex colour modulates the texture. But this may depend on the current OpenGL/DX state, which depends on the material type. For that reason, I suggest you change both the vertex colours and the material diffuse.