Material not being lit by AmbientLight()

Hi all :slight_smile:



I made a simple scene in blender, it just has a Cube and Lamp (apart from the default RenderLayers and World found in the Outliner that is).



I gave the Cube a custom-painted texture and then brought the .blend file into javaMonkeyPlatform into the Models folder and converted it into a .j3o (nothing else was created other than a Cube.j3odata file). I used jMP to convert it from .blend to .j3o.



A.) If I run the following code:



[java]viewPort.setBackgroundColor(ColorRGBA.DarkGray);

cam.setLocation(new Vector3f(0f, 10f, 0f));

flyCam.setMoveSpeed(10f);



Spatial cubeModel = assetManager.loadModel(“Models/Cube.j3o”);

cubeModel.setLocalTranslation(15f, 1f, 15f);

rootNode.attachChild(cubeModel);[/java]



The game runs and the Cube with the correct texture is displayed but it is darkly-lit:



http://img163.imageshack.us/img163/8508/56831409.png



B.) So I add an AmbientLight:



[java]AmbientLight light = new AmbientLight();

light.setColor(ColorRGBA.White.mult(3f));

rootNode.addLight(light);[/java]



Which gives the same results - the lighting doesn’t change:



http://img833.imageshack.us/img833/4296/17057373.png



I tried removing the Lamp in blender and if I rerun it with the AmbientLight code included the Cube is now completely black.



C.) However the ambient light works correctly if I give the cube a default jMP material:



Spatial cubeModel = assetManager.loadModel(“Models/Cube.j3o”);

cubeModel.setLocalTranslation(15f, 1f, 15f);

Material matt = assetManager.loadMaterial(“Textures/Terrain/Pond/Pond.j3m”);

cubeModel.setMaterial(matt);

rootNode.attachChild(cubeModel);



http://img18.imageshack.us/img18/6011/21833698.png



I’ve included Cube.blend, Cube.j3o, and Cube.j3odata here. Any ideas of what I’m doing wrong? Thanks alot!

Maybe somehow your texture is being used not as Diffuse map, but something else? Because diffuse defines how much light is being “reflected”.

I have tried to download you files, but it say that they are temporary unavailable. Could you upload them somewhere else?



Also try instead of [java]light.setColor(ColorRGBA.White.mult(3f));[/java] this code [java]light.setColor(ColorRGBA.White);[/java]

Since ColorRGBA.White is defined as ColorRGBA(1.0, 1.0, 1.0, 1.0) I highly doubt that multiplying it by 3f would have reason - all color components are in the range of [0…1].



And finally try [java]TangentBinormalGenerator.generate(cubeModel.getMesh(), true);[/java]. I doubt it could be normals-related problem, but worth a try :slight_smile:

If you look at the source, the Pond.j3m material definition is the following:



Material Pong Rock : Common/MatDefs/Light/Lighting.j3md {

MaterialParameters {

Shininess: 8.0

DiffuseMap: Repeat Textures/Terrain/Pond/Pond.jpg

NormalMap: Repeat Textures/Terrain/Pond/Pond_normal.png

}

}



But I don’t know how the Blender importer create the material from the .blend file. Maybe it’s something related to that.

You may need to set the ambient color on the material, the default is 0.2, 0.2, 0.2 which is quite low

I´ve downloaded the files and made 2 tests:



First test:



[java]

viewPort.setBackgroundColor(ColorRGBA.DarkGray);

cam.setLocation(new Vector3f(0f, 10f, 0f));

flyCam.setMoveSpeed(10f);



Spatial cubeModel = assetManager.loadModel(“Models/Cube.j3o”);



rootNode.attachChild(cubeModel);

cubeModel.setLocalTranslation(0f, 10f, -15f);

Geometry geom = (Geometry) rootNode.getChild(“Cube1”);

Material mat2 = geom.getMaterial();

mat2.setParam(“UseMaterialColors”, VarType.Boolean, false);



AmbientLight light = new AmbientLight();

light.setColor(ColorRGBA.White.mult(3f));

rootNode.addLight(light);

[/java]



First test result:

http://i.imgur.com/5BkRX.png



Second test:



[java]

viewPort.setBackgroundColor(ColorRGBA.DarkGray);

cam.setLocation(new Vector3f(0f, 10f, 0f));

flyCam.setMoveSpeed(10f);



Spatial cubeModel = assetManager.loadModel(“Models/Cube.j3o”);



rootNode.attachChild(cubeModel);

cubeModel.setLocalTranslation(0f, 10f, -15f);

Geometry geom = (Geometry) rootNode.getChild(“Cube1”);

Material mat2 = geom.getMaterial();

mat2.setParam(“Ambient”, VarType.Vector4, new ColorRGBA(0.2f, 0.2f, 0.2f, 1.0f));



AmbientLight light = new AmbientLight();

light.setColor(ColorRGBA.White.mult(3f));

rootNode.addLight(light);

[/java]



Second test result:

http://i.imgur.com/V9GfN.png



It seems like the second one was a bit darker.



To make another test, I would like to set the Ambient color inside Blender? Is there a way to do so?

I can only find there Diffuse and Specular…