Page 1 of 1

How can i let diffuse lighting work?

Posted: Sun Mar 04, 2018 4:59 pm
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!

Re: How can i let diffuse lighting work?

Posted: Mon Mar 05, 2018 12:31 am
by Mel
Try to normalize the normals.

Code: Select all

 
n->getMaterial(0).normalizeNormals = true;
 

Re: How can i let diffuse lighting work?

Posted: Mon Mar 05, 2018 1:13 am
by sunzhuo
Mel wrote:Try to normalize the normals.

Code: Select all

 
n->getMaterial(0).normalizeNormals = true;
 
still not work

Re: How can i let diffuse lighting work?

Posted: Mon Mar 05, 2018 1:17 am
by Mel
Is the lighting enabled for the materials?

Re: How can i let diffuse lighting work?

Posted: Mon Mar 05, 2018 1:29 am
by sunzhuo
yes, of course. It shows shadow. Any suggestion?

Re: How can i let diffuse lighting work?

Posted: Mon Mar 05, 2018 9:48 am
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);
 

Re: How can i let diffuse lighting work?

Posted: Mon Mar 05, 2018 12:51 pm
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

Re: How can i let diffuse lighting work?

Posted: Mon Mar 05, 2018 4:24 pm
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.

Re: How can i let diffuse lighting work?

Posted: Tue Mar 06, 2018 1:09 am
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.

Re: How can i let diffuse lighting work?

Posted: Tue Mar 06, 2018 7:53 am
by manni63
What happens, when you switch off both light sources, ambient and directional?
And how do you make the shadows?

Re: How can i let diffuse lighting work?

Posted: Tue Mar 06, 2018 9:42 am
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();

Re: How can i let diffuse lighting work?

Posted: Tue Mar 06, 2018 11:27 am
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.

Re: How can i let diffuse lighting work?

Posted: Tue Mar 06, 2018 1:49 pm
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!