Model black on AmbientLight but it is normal on DirectionLight

Hi



I am new to jMonkeyEngine. So far I like the way how it works.

But I run into a problem (this seems like bug to me, but I would like to check it).



I import .lwo model in Blender and then export it to .obj (I do not make any modifications, only conversion).

Then I import it in JME (.obj and .mtl files) and convert it to .j3o.

This is (part of) my code:



model = assetManager.loadModel(“Models/bmw.j3o”);

rootNode.attachChild(model);



// model.setMaterial(new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”));



DirectionalLight sun = new DirectionalLight();

sun.setColor(ColorRGBA.White);

sun.setDirection(new Vector3f(-.5f, -.5f, -.5f).normalizeLocal());

rootNode.addLight(sun);



Now when I run application, BMW shows normally.

But when I change lightning to:

AmbientLight al = new AmbientLight();

al.setColor(ColorRGBA.White.mult(1.3f));

rootNode.addLight(al);



It becomes dark/black, and no mater how much I multiply color, it stays black.

But when I set material (which is commented in code above), it is shown correctly under both, Directional and Ambient lights.



I have searched forum, and I found problems related to “becomes black when scaling”.



Can someone help me with this?



Also I am using latest JME 3.0 (from October 2011).

1 Like

It sounds like the model was exported with black material ambient color. You might need to set the ambient value in the blender material for it to work

Ok, I have downloaded somewhere already made .obj and .mtl files, and lighting works as it should.

So can someone give me tip what should do before exporting object as .obj and .mtl files?



Thanks in advance



EDIT: Sorry, I refreshed page too late, I will give a try. Thanks :slight_smile:

Can you tell me how to do that?

I found ambient light under “world” tab, and when I change to white and export it, in JME it is shown as white (not textured).



EDIT: I forgot to mention, I am using Blender 2.62

In general, if ambient color is pure white you are telling the scene that light should be maximum everywhere… ie: everything will be fully light, aka: white.

But only way to get “normal” colors is to set that “world” ambient color to black.

How can I set to material “ambient color”?

I cannot find that option in blender under “materials” tab.

I didn’t realize you’d already tried a dark gray ambient color. And that may not be the issue anyway since you don’t have a problem until you add the ambient light.



And by the way:

al.setColor(ColorRGBA.White.mult(1.3f));



…is a fairly ludicrous ambient level. You are telling the scene that you want even the darkest shadow to be 1.3 x white. What happens when you set it to a more normal ambient level… like White.mult(0.1f) or something? Or what effect are you trying to achieve?

I am trying to make lightning of scene more real.

Without AmbientLight the side of model that is not lit by DirectionalLight is totally black.



I have tried 0.1 and 0.3, but it is same effect (black).

I tried to set wold ambient light to gray, but it still gets black.



But when I import some already made .obj and .mtl model, lightning works fine.

So problem is definitely with exporting in blender, I just don’t know why…



Thanks for helping me.



EDIT: I have uploaded here model which I am trying to get work with AmbientLight: http://www.filefactory.com/file/6k3hmpkren9p/n/BMW_serie_6.lwo

Take a look at the .mat File. There should be values “Ka”. Set them to something between 0.0 and 1.0. Than AmbientLight should work. Here are some explanations to the format http://en.wikipedia.org/wiki/Wavefront_.obj_file#Material_template_library.



Unfortunately Blender (in any version i encountered so far) doesn’t want to export the ambient light settings you made in blender for a material.

1 Like

Thanks Lockhead.

I have tried setting those values to 0.2 and 0.5, but the effect is same as I would set it in world ambient light.

Texture when is lit by AmbientLight becomes gray (but not textured, like whole model is from one color - gray).

But when I lit same texture with DirectionalLight it displays normally.



I am thinking now to add about 10 directional lights (in various angles) and to turn off shadows as I see no way out of this.



Thanks for help.

The scene is rendered once for every light… better to get the real issue fixed than to add 10 lights.

1 Like

Ok, thanks for information pspeed, I will try to solve it somehow…

I just ran into this myself, and a quick search also found:

http://hub.jmonkeyengine.org/groups/graphics/forum/topic/material-not-being-lit-by-ambientlight/



Essentially with materials that have been imported from blender it seems something is not set up right inside that material - so it received directional but not ambient light.



I’ve not chased it any more here yet - just found the problem myself and it sounded the same as you have been getting. If you set the material to a new JME3 material then it should fix your problem for now…



Edit to add:



I have multiple objects in the scene - and I realised that some were getting ambient light and some weren’t. I then attached a very bright red ambient light and it was immediately obvious which ones weren’t getting it and from that I spotted the pattern.

1 Like
@zarch said:
I just ran into this myself, and a quick search also found:
http://hub.jmonkeyengine.org/groups/graphics/forum/topic/material-not-being-lit-by-ambientlight/

Essentially with materials that have been imported from blender it seems something is not set up right inside that material - so it received directional but not ambient light.

I've not chased it any more here yet - just found the problem myself and it sounded the same as you have been getting. If you set the material to a new JME3 material then it should fix your problem for now...

Edit to add:

I have multiple objects in the scene - and I realised that some were getting ambient light and some weren't. I then attached a very bright red ambient light and it was immediately obvious which ones weren't getting it and from that I spotted the pattern.

Yes, I have same problem. But I don't know how to export material from Blender so I can import it and set to model (I get .obj and .mat files which JME3 converts to .j3o).

I haven't found solution yet :(
And I still think that is bug in JME3 (with some lights it work, and with some other not).

same problem with me …i’m trying to mix the directional light, shadow and ambient light, but it didn’t work properly



Directional Light - Okay

Shadow - Okay

Ambient Lights - Fail



Code for lights in my class :


DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-2.1f, -0.7f, -1).normalizeLocal());
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));

rootNode.addLight(dl);

AmbientLight als = new AmbientLight();
als.setColor(ColorRGBA.Black.mult(3f));
rootNode.addLight(als);




the model .mtl file says :
#
## Alias OBJ Material File
# Exported from SketchUp, (c) 2000-2006 Google, Inc.

newmtl M_0135_DarkGray
Ka 0.000000 0.000000 0.000000
Kd 0.584314 0.568627 0.482353
Ks 0.330000 0.330000 0.330000
map_Kd map2/M_0135_DarkGray.png

newmtl jean_blue
Ka 0.000000 0.000000 0.000000
Kd 0.403922 0.415686 0.141176
Ks 0.330000 0.330000 0.330000
map_Kd map2/jean_blue.png

newmtl Color_B24
Ka 0.000000 0.000000 0.000000
Kd 0.486275 0.333333 0.156863
Ks 0.330000 0.330000 0.330000
map_Kd map2/Color_B24.png

newmtl Material1
Ka 0.000000 0.000000 0.000000
Kd 0.423529 0.701961 0.164706
Ks 0.330000 0.330000 0.330000
map_Kd map2/Material1.png

So whats wrong ?? Any helps ? :(

[java]

als.setColor(ColorRGBA.Black.mult(3f));

[/java]



A black ambient light does a black ambient light…even if you multiply it by 3.

3 Likes

I’m sorry but this is too funny. :smiley:



+1

2 Likes

You don’t say ??



i changed and

still fail



map2.mtl file


Exported from SketchUp, © 2000-2006 Google, Inc.


newmtl M_0135_DarkGray
Ka 1.000000 1.000000 1.000000
Kd 0.584314 0.568627 0.482353
Ks 0.330000 0.330000 0.330000
map_Kd map2/M_0135_DarkGray.png

newmtl jean_blue
Ka 1.000000 1.000000 1.000000
Kd 0.403922 0.415686 0.141176
Ks 0.330000 0.330000 0.330000
map_Kd map2/jean_blue.png

newmtl Color_B24
Ka 1.000000 1.000000 1.000000
Kd 0.486275 0.333333 0.156863
Ks 0.330000 0.330000 0.330000
map_Kd map2/Color_B24.png

newmtl Material1
Ka 1.000000 1.000000 1.000000
Kd 0.423529 0.701961 0.164706
Ks 0.330000 0.330000 0.330000
map_Kd map2/Material1.png

AmbientLight als = new AmbientLight();
als.setColor(ColorRGBA.White.mult(3f));
rootNode.addLight(als);


This part is in the shadows so it may play it’s part in the darkness.



Check those things :

  • the pssmRenderer has a setShadowIntensity(float) that can help.
  • what happens when your remove the shadows?

1 Ambient Lights, No Shadow, No PSSMFilter, No directional Lights and still goes black … :frowning:


// pssmRenderer = new PssmShadowRenderer(assetManager, 1024, 3);
// pssmRenderer.setDirection(new Vector3f(-2.1f, -0.7f, -1).normalizeLocal()); // light direction
// viewPort.addProcessor(pssmRenderer);
//
// land.setShadowMode(ShadowMode.CastAndReceive);

// DirectionalLight dl = new DirectionalLight();
// dl.setDirection(new Vector3f(-2.1f, -0.7f, -1).normalizeLocal());
// dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
// rootNode.addLight(dl);

AmbientLight als = new AmbientLight();
als.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
als.setColor(ColorRGBA.White.mult(3f));
rootNode.addLight(als);

// FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
// SSAOFilter ss = new SSAOFilter(12.94f, 33.92f, 0.63f, 0.61f);
// fpp.addFilter(ss);
// viewPort.addProcessor(fpp);