SceneNode color change when lighting it

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kotnis_m
Posts: 9
Joined: Wed Nov 14, 2012 10:51 pm
Location: Poland, Torun

SceneNode color change when lighting it

Post by kotnis_m »

Hi everyone!

I'm really confused. I give up!
Don't know what to do, to change a SceneNode color. I have created a SceneNode, then set diffuse color of it's material, and set lighting on. Then I've created a LightSceneNode, and when change DiffuseColor of my SceneNode nothing changed. Is there any way to change color of SceneNode manipulating only material color? My node is based on SMeshBuffer which has a material.
Maybe I have to change vertices Color? This works, but maybe I can set Vertices color to white (for example) and then change only Material color to take effect? Which one should I change? Is this really needed to change SceneNode vertices color?

It would be nice if someone could paste a short example.

Thanks in advance!
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: SceneNode color change when lighting it

Post by Mel »

the solid material uses the vertex colors to iluminate the models, so, you need to set the vertex colors to full white if you want the objects to be lit only with the material color.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: SceneNode color change when lighting it

Post by CuteAlien »

There is already an example in Irrlicht - checkout Example 22.MaterialViewer. It allows setting different material- and light-settings for 2 scenenodes so you can compare the changes and how they are affected by stuff like Textures.
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
kotnis_m
Posts: 9
Joined: Wed Nov 14, 2012 10:51 pm
Location: Poland, Torun

Re: SceneNode color change when lighting it

Post by kotnis_m »

I've already set vertex color to white, and still can't change color of Node. Moreover I've been using example 22 to see how material color works. And it looks like it don't work. Can you tell me how to use example 22 with vertex set to white to change color of object? It really not works fine for me.
Please write haw to set each option and what is need to be set to change to another color. Do I need special kind of light or any light can be used?
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: SceneNode color change when lighting it

Post by CuteAlien »

Uhm, light-colors used to work when materials had no textures. No longer does work that way it seems :-( Sorry, I didn't notice when this got changed, I'm pretty sure it was different back when I wrote the example. I need time to figure out since when that is the case and what's going on now.
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
kotnis_m
Posts: 9
Joined: Wed Nov 14, 2012 10:51 pm
Location: Poland, Torun

Re: SceneNode color change when lighting it

Post by kotnis_m »

Now, I can only change each vertex color to see object in that color. Does it means it's a bug?
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: SceneNode color change when lighting it

Post by Klunk »

try this on your material if your using flat colour (with white vertex colours)

Code: Select all

setFlag(EMF_COLOR_MATERIAL,false);
and if textured....

Code: Select all

setFlag(EMF_COLOR_MATERIAL,true);
kotnis_m
Posts: 9
Joined: Wed Nov 14, 2012 10:51 pm
Location: Poland, Torun

Re: SceneNode color change when lighting it

Post by kotnis_m »

@ Klunk:
I LOVE YOU! :))
I've just changed back all vertices to white and manipulate DiffuseColor of material and it affects. It just works! :)

@ CuteAlien:
I think you should change example 22. When changing texture:
material.setFlag(EMF_COLOR_MATERIAL, <texture.available>);

Thanks again everyone for your help! You are great! :)
Probably I will have another question soon. How to enable shadows? Will try to find it out myself.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: SceneNode color change when lighting it

Post by hybrid »

If you don't use setFlag() but access the member directly, you can even fine-tune the settings in more detail. This value defines, which part of the lighting material is defined by vertex colors.
kotnis_m
Posts: 9
Joined: Wed Nov 14, 2012 10:51 pm
Location: Poland, Torun

Re: SceneNode color change when lighting it

Post by kotnis_m »

Got another problem with white vertex, and color based on MaterialColor. When I set following:

SMaterial &meshMaterialWalls = meshObjectWalls->getMaterial();
meshMaterialWalls.ColorMaterial = false;
meshMaterialWalls.NormalizeNormals = true;
meshMaterialWalls.Lighting = true;
meshMaterialWalls.MaterialType = EMT_SOLID;
meshMaterialWalls.GouraudShading = true;

my mesh is not Gouraud shaded. Can you tell why is that?
kotnis_m
Posts: 9
Joined: Wed Nov 14, 2012 10:51 pm
Location: Poland, Torun

Re: SceneNode color change when lighting it

Post by kotnis_m »

I resolved it!
Indices in my mesh was combined exactly to one vertex and "vice versa". Same number vertices and indices. When I reduced vertices and finally get all vertices unique, my mesh is now rendered like I want it.
All works fine now. Thanks a lot for your help!
Post Reply