Ambient lighting and blender imports

public void fixMaterials( Spatial s ) {
    s.depthFirstTraversal(new SceneGraphVisitorAdapter() {
            public void visit(Geometry geom) {
                geom.getMaterial().setColor("Ambient", ColorRGBA.White);
            }
        });
}

…or something to that effect. Written directly from memory.

I stumbled over the same problem lately. Let me first explain the problem and clear some missunderstandings. Then I will picture out my solution to this.

The way jME handles ambient light
The four major light sources jMonkey provides, can be divided into two different “types”.
The first type emits only “ambient light”. AmbientLight is currently the only implementation, that belongs to this light source type.
The secound type emits only “diffuse light”. The remaining 3 light sources DirectionalLight, PointLight and SpotLight belongs to this type.
Every one of this two light source types ONLY reacts to its own material properties.
Ambient light is affected by “Ambient” (color).
Diffuse light is affected by “Diffuse” (color) and “DiffuseMap” (texture).
As far as I know, there is no texture property for ambient light. :frowning:

The way Blender handles ambient light
On the other side, we have Blender. When it comes to ambient light there are different oppinions, what the “ambient color” property in the world settings stands for. It is either the color of the ambient light of the scene, or the ambient material color of every object in the scene. I think the first one is more likely and the official documentations seems to confirm this. On http://www.blender.org/manual/game_engine/physics/world.html you can find the following description:

Ambient Color
Ambient light mimics an overall background illumination obtained from diffusing surfaces (see Ambient Light, Exposure and Ambient Occlusion). Its general color and intensity are set by these controls.

I played a bit with it in Blender, but it acts still really strange. This “ambient light” ignores the material of an object completely, as if it would have a ambient material color of pure White. Lets explain this with a little example.
Make a simple, magenta object (diffuse color) and put some cyan spotlight on it. As a result, all light up areas of the object appear in blue, because its the only color part of the cyan light, that is reflected by the magenta surface. When we now set the “ambient color” to green, the whole object turns green, even if nothing of the green light should be reflected by the magenta material. This suggests, that ether every object provides a separate, pure white ambient material color, or that ambient light is really strange handled by Blender (or even both!).

What jME3 does out of the situation
As we see, Blender not really supports separated material properties for ambient light. Therefore, jMonkey makes a simple fallback when loading a .blend file. It sets the missing “Ambient” property of every material to a default. This default was long time the color Black [0.0, 0.0, 0.0, 1.0] (reflect no ambient light), but with jME 3.1 this was changed to White [1.0, 1.0, 1.0, 1.0]. In my oppinion this is a little step into the right direction, but unfortunately not much more usefull as the color Black was. When I put colored ambient light on some objects, I want them to appear in the correct color (subracted color), that takes respect to the material colors of the objects. A magenta cube should be red, if I add a yellow ambient light source, and not yellow, as it currently does.

How I (partly) worked around this issues
I implemented my own converter, which does nothing more than:

  1. Load the model from a given .blend file, by simply using the AssetManager of jME3
  2. Iterate through the model tree (using a SceneGraphVisitor) and setting the “Ambient” color the same as the “Diffuse” color
  3. Save the model to .j3o file using jME3’s BinaryExporter.

This works really well, but it is still a workaround and does not work with textures, beacuse of a missing equivalent to “DiffuseMap” for ambient light.

Some real solutions would be …

  • When jMonkeys loads a .blend file it should not only use a fix default color for the “Ambient” material property. Alternatively it should use the “Diffuse” color of the material, if available.
  • If jMonkey would support a separate texture property for ambient light, we (or jMonkey) could even use ambient light sources together with textures.
  • Without a separate texture property for ambient light, it would be a good idea to let AmbientLight even react to the “DiffuseMap” property, so we can at least see this standard texture under ambient light.
  • As a third solution, jMonkey could extend the AmbientLight class by a new flag to enable it to use the diffuse material properties (“Diffuse” and “DiffuseMap”) even as the other three light sources do.
  • Now that we “know” the nature of the “ambient color” setting in Blender, it could be useful to convert this property into an AmbientLight object in the loaded model.

I hope, I could bring some strange ambient light into this topic and please excuse my “unusual” english. :sweat_smile:

1 Like

I always think its an good practice to always create/use jm3 materials for each object like this :

I also recommend it because you can add some effects that you dont have in blender.
If you still fell that its too much work, then you could try something like the xbuf converter ( there is this guy here in the forum building it ), so you could run and see your objects rendering on jm3 engine directly on blender.

Took a break from jMonkey for 8 years and came back to see this is still a problem.
So is there a current new/easy way to get ambient lighting? I’m not using the SDK/netbeans because that’s a bit 1990s :slight_smile: I’m using Jetbrains IDE, Jmonkey 3.6.0 and Blender 3.2.2. I export as glb files. I have an ambientLight, but I also have “Material parameter is not defined: Ambient” because the PBR materials don’t have that I guess.
The only solution I can think of that might work is use the SceneGraphVisitorAdapter and create a new material (“Lighting.j3md”) to override the PBR materials, but before I try that, any proper new way to do this? Many thanks.
p.s. I’ve missed jMonkey. Glad to see it’s still alive and well

For PBR, you will need a light probe or you will have no ambient light. There are many threads where this is discussed. You can use some standard ones or generate one specific to your scene.

2 Likes

Thanks, I’ll look into that.