How can i let diffuse lighting work?

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
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

How can i let diffuse lighting work?

Post by sunzhuo »

I am using 1.7.2. I load a 3ds mesh to the scene and add a light (see below). It seems that the diffuse lighting does not work.
Image

I want get the following effect which I got in the rhinoceros software:
Image

I tried these settings but still not work.

Code: Select all

        
smgr->setAmbientLight(video::SColor(0, 60, 60, 60));
n->setMaterialType(video::EMT_SOLID);
n->getMaterial(0).SpecularColor.set(255, 255, 255, 255);
n->getMaterial(0).AmbientColor.set(255, 255, 255, 255);
n->getMaterial(0).DiffuseColor.set(255, 255, 255, 255);
n->getMaterial(0).EmissiveColor.set(40, 40, 40, 40);
 
Please help me!
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How can i let diffuse lighting work?

Post by Mel »

Try to normalize the normals.

Code: Select all

 
n->getMaterial(0).normalizeNormals = true;
 
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Re: How can i let diffuse lighting work?

Post by sunzhuo »

Mel wrote:Try to normalize the normals.

Code: Select all

 
n->getMaterial(0).normalizeNormals = true;
 
still not work
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How can i let diffuse lighting work?

Post by Mel »

Is the lighting enabled for the materials?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Re: How can i let diffuse lighting work?

Post by sunzhuo »

yes, of course. It shows shadow. Any suggestion?
manni63
Posts: 12
Joined: Tue Sep 27, 2016 6:23 am

Re: How can i let diffuse lighting work?

Post by manni63 »

Diffuse illumination means that light comes from all space directions on your mesh object. So the brightness of a mesh is completely
independent of normal directions. This is exactly the situation you show in your first image, so your diffuse illumination works pretty well.
To get a brightness that depends on normal directions of meshes as shown in your second image, you should add a directional light source (adapt the coordinates for the light source position, intensity and radius to your requirements):

Code: Select all

 
smgr->addLightSceneNode(0, core::vector3df(-1500,500,-1050), video::SColorf(1.f, 1.f, 1.f),5000.f);
 
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Re: How can i let diffuse lighting work?

Post by sunzhuo »

manni63 wrote:Diffuse illumination means that light comes from all space directions on your mesh object. So the brightness of a mesh is completely
independent of normal directions. This is exactly the situation you show in your first image, so your diffuse illumination works pretty well.
To get a brightness that depends on normal directions of meshes as shown in your second image, you should add a directional light source (adapt the coordinates for the light source position, intensity and radius to your requirements):

Code: Select all

 
smgr->addLightSceneNode(0, core::vector3df(-1500,500,-1050), video::SColorf(1.f, 1.f, 1.f),5000.f);
 
Actually, The light source that I added to the scene is quite far and can be treated as directional.

Code: Select all

smgr->addLightSceneNode(0, core::vector3df(-100000,100000,-100000), video::SColorf(1.f, 1.f, 1.f),200000.f);
But it still can't help
manni63
Posts: 12
Joined: Tue Sep 27, 2016 6:23 am

Re: How can i let diffuse lighting work?

Post by manni63 »

The first thing:
Which video driver do you use? It seems to me that the software driver as well as the burningsvideo driver seems not to support direct lighting.

The second thing is a little bit tricky and it took me some time to understand this effect:
With the coordinates of your light source (-100000, 100000, -100000) and when your object is aligned to the coordinate axis, the angle between the incoming
light and the face normals is the same for all your faces. So all faces are rendered with the same brightness.
Try to change the coordinates of your light source so that it is not on a diagonal of the coordinate system, e.g.

Code: Select all

 
smgr->addLightSceneNode(0, core::vector3df(-40000,100000,-80000), video::SColorf(1.f, 1.f, 1.f),200000.f);
 
and adapt the brightness of your ambient source or switch it completely off.
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Re: How can i let diffuse lighting work?

Post by sunzhuo »

manni63 wrote:The first thing:
Which video driver do you use? It seems to me that the software driver as well as the burningsvideo driver seems not to support direct lighting.

The second thing is a little bit tricky and it took me some time to understand this effect:
With the coordinates of your light source (-100000, 100000, -100000) and when your object is aligned to the coordinate axis, the angle between the incoming
light and the face normals is the same for all your faces. So all faces are rendered with the same brightness.
Try to change the coordinates of your light source so that it is not on a diagonal of the coordinate system, e.g.

Code: Select all

 
smgr->addLightSceneNode(0, core::vector3df(-40000,100000,-80000), video::SColorf(1.f, 1.f, 1.f),200000.f);
 
and adapt the brightness of your ambient source or switch it completely off.
I am using OpenGL.
I changed the coordinates of the light source for several times. and I also off the ambient light.

Code: Select all

smgr->setAmbientLight(video::SColor(1.f, 0, 0, 0));
But still nothing changed.
manni63
Posts: 12
Joined: Tue Sep 27, 2016 6:23 am

Re: How can i let diffuse lighting work?

Post by manni63 »

What happens, when you switch off both light sources, ambient and directional?
And how do you make the shadows?
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Re: How can i let diffuse lighting work?

Post by sunzhuo »

manni63 wrote:What happens, when you switch off both light sources, ambient and directional?
And how do you make the shadows?
When I switch off all the lights everything is dark.
I make the shadows by adding a scenenode:

Code: Select all

((scene::IAnimatedMeshSceneNode*)n)->addShadowVolumeSceneNode();
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How can i let diffuse lighting work?

Post by CuteAlien »

Looks like the sum of all your lighting is already beyond full lighting. So basically in first step you have to get back to a situation where it's not full bright and then slowly turn the lights up. For example start with only 1 light - either dynamic or ambient and check how it's there.
Reasons it can have:

- Start without emissive material. It's self-lighting and you rarely need that. You definitely don't need it when you already hit full brightness like here.
- Depending on angle the specular light can make it bright. You notice by rotating the light around the object (if brightness changes by that then specular still has some influence)
- Diffuse light also confuses me really. I don't know exact formula, but from some quick tests right now it seems like when you have no texture the diffuse-light color interacts with the vertex colors of the mesh (you generally don't change those, so you tune the diffuse-color of the dynamic light). I can't figure out any influence of diffuse-material colors so far (no matter if with or without texture). So basically - change diffuse by changing it in the light.
edit: Just looked again and diffuse color is by default only using vertex-colors. But it can be changed by settting SMaterial.ColorMaterial to another value. So default is that SMaterial.Diffuse is probably ignored and the color is light.diffuse*vertexcolor.
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
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Re: How can i let diffuse lighting work?

Post by sunzhuo »

CuteAlien wrote:Looks like the sum of all your lighting is already beyond full lighting. So basically in first step you have to get back to a situation where it's not full bright and then slowly turn the lights up. For example start with only 1 light - either dynamic or ambient and check how it's there.
Reasons it can have:

- Start without emissive material. It's self-lighting and you rarely need that. You definitely don't need it when you already hit full brightness like here.
- Depending on angle the specular light can make it bright. You notice by rotating the light around the object (if brightness changes by that then specular still has some influence)
- Diffuse light also confuses me really. I don't know exact formula, but from some quick tests right now it seems like when you have no texture the diffuse-light color interacts with the vertex colors of the mesh (you generally don't change those, so you tune the diffuse-color of the dynamic light). I can't figure out any influence of diffuse-material colors so far (no matter if with or without texture). So basically - change diffuse by changing it in the light.
edit: Just looked again and diffuse color is by default only using vertex-colors. But it can be changed by settting SMaterial.ColorMaterial to another value. So default is that SMaterial.Diffuse is probably ignored and the color is light.diffuse*vertexcolor.
Finally, I figured it out.
I use irrEdit to test the same scene. I found that in my application I gave a wrong parameter for the addLightSceneNode function and make the scene too bright which seems no diffuse lighting.

Thank you all for your prompt advices!
Post Reply