Problem with "color blending" when moving directional or spot lights on surface

Hi. I have a model which is textured predominantly green, but with some white and black (i.e. high contrast) letters written on it. When I just use an AmbientLight in the scene, everything draws correctly. However, when I “shine upon” my model with a DirectionalLight or SpotLight, the white / black colors will “blend” with the dominant green color so that the white letters are now light green letters instead.

I wish to turn off this effect for my entire surface if possible, and just have the lights “shiny up” the color that is already there without any blending.

The model is an imported .OBJ exported from a 3DS using MAX 2014. I see that there are some ambient, diffuse, and specular constants defined for the various surface parts in the corresponding .MTL file. Should I manipulate any of this, or can this be done through jme?

I hope this question made sense! Thanks in advance for any help.

Could you post a screen shot and some code so we could have a better idea of what going on?

There’s very little to the code, the model is loaded straight from .OBJ:

[java]ship = (Node)assetManager.loadModel(“graphics/shipmodel3d/shiptest.obj”);[/java]

Then an AmbientLight and DirectionalLight is applied to the scene:

[java] DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(0.5f,-0.5f,0.5f));
sun.setColor(ColorRGBA.White.mult(2));
app.getRootNode().addLight(sun);

    AmbientLight amb = new AmbientLight();
    amb.setColor(ColorRGBA.White.mult(0.5f));
    app.getRootNode().addLight(amb);

[/java]

The first screenshot below shows the scene with just the AmbientLight enabled. Everything looks OK here. The second screenshot shows the scene with AmbientLight + a DirectionalLight shining on the bow of the ship. The green-ish hue the white color has picked up here is not correct.

I found out that the .MTL file has definitions for how much the surface should “pick up” ambient, diffuse, specular light by defining a set of constants 0 < K < 1 for each variable. By setting all the diffuse constants to 0, I got this effect to disappear. However the drawback is that the surface now doesn’t react to the DirectionalLight at all, so it’s not a fully acceptable solution. I would like to still use the DirectionalLight to add additional light effects to the scene, but avoid this color blending that you can see in the second screenshot.

Only AmbientLight
Ambient + Directional

@stenb said: By setting all the diffuse constants to 0, I got this effect to disappear.

What were they before you set them to 0?

@pspeed said: What were they before you set them to 0?

Varied, by material I assume. For those interested, below is the full .MTL file as exported by 3DS, with the exception that I set all the Ka parameters for ambient to 0.05 instead of 0. With Ka set to 0 the geometry did not pick up any ambient light.

[java]# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware

File Created: 02.12.2013 12:24:48

newmtl PaintGloss
Ns 80.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.0000 0.4510 0.0000
Ks 0.0000 0.1490 0.0000
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png
map_bump -bm 0.2000 BUMP_FRONT.png

newmtl PaintlSemi
Ns 60.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.3216 0.5294 0.3020
Ks 0.1059 0.1765 0.0980
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png

newmtl PaintMatte
Ns 15.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.4235 0.5647 0.4235
Ks 0.1059 0.1412 0.1059
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png

newmtl Deck
Ns 60.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.0588 0.3882 0.2549
Ks 0.0196 0.1294 0.0824
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png
map_bump -bm 0.2000 BUMP_FRONT.png

newmtl Glass
Ns 100.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.0157 0.0157 0.0157
Ks 0.0078 0.0078 0.0078
Ke 0.0000 0.0000 0.0000

newmtl Chrome
Ns 100.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.2824 0.2824 0.2824
Ks 0.6902 0.6902 0.6902
Ke 0.0000 0.0000 0.0000

newmtl Transparent
Ns 100.0000
Ni 1.5000
d 0.7700
Tr 0.2300
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.1765 0.2039 0.1922
Ks 0.3569 0.4078 0.3843
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png

newmtl DeckWood
Ns 20.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.7843 0.7843 0.7843
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png

newmtl Aluminium
Ns 30.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.5686 0.5804 0.5922
Ks 0.3863 0.3941 0.4020
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png

newmtl MetalSemi
Ns 30.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.5686 0.5804 0.5922
Ks 0.3863 0.3941 0.4020
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png

newmtl Lights
Ns 20.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 1.0000 1.0000 1.0000
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png

newmtl Flag
Ns 20.0000
Ni 1.5000
d 1.0000
Tr 0.0000
illum 2
Ka 0.0500 0.0500 0.0500
Kd 0.7843 0.7843 0.7843
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
map_Ka HULL_FRONT.png
map_Kd HULL_FRONT.png[/java]

@stenb said: [java]# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware # File Created: 02.12.2013 12:24:48

newmtl PaintGloss
Kd 0.0000 0.4510 0.0000
Ks 0.0000 0.1490 0.0000

newmtl PaintlSemi
Kd 0.3216 0.5294 0.3020
Ks 0.1059 0.1765 0.0980

newmtl PaintMatte
Kd 0.4235 0.5647 0.4235
Ks 0.1059 0.1412 0.1059

newmtl Transparent
Kd 0.1765 0.2039 0.1922
Ks 0.3569 0.4078 0.3843
[/java]

So it’s probably no coincidence that those particular materials have their green cranked higher than the other colors while their ambient is still flat gray. The model wants to be green despite it’s ambient. The behavior is to be expected with these values especially since the diffuse component of your light is essentially multiplying them by 2.

I suspect if you find the offending material and level-set it’s values to gray that your “issue” will disappear.

1 Like
@pspeed said: So it's probably no coincidence that those particular materials have their green cranked higher than the other colors while their ambient is still flat gray. The model wants to be green despite it's ambient. The behavior is to be expected with these values especially since the diffuse component of your light is essentially multiplying them by 2.

I suspect if you find the offending material and level-set it’s values to gray that your “issue” will disappear.

You are of course right. An easy fix. I need to read up on more theory behind this lighting and how ambient, diffuse, and specular is taken into account to compute the final pixel color.

For future reference, the fix involves setting the diffuse color to a light gray tone. Light gray is something like 238-233-233 on the 0-255 RGB scale, and since the Kd parameter is between 0 and 1, what I did was replace the Kd for each material with the percentage value that the color I want corresponds to on the 0-1 scale. So, this greenish diffuse parameter

[java] Kd 0.5686 0.5500 0.5922
[/java]

instead becomes this light gray

[java] Kd 0.9300 0.9300 0.9300
[/java]

and now it works perfectly. Thanks!

Is that the only one you changed? 'cause I’d have expected that one to be a purplish gray before you fixed it.

@pspeed said: Is that the only one you changed? 'cause I'd have expected that one to be a purplish gray before you fixed it.

I changed the Kd parameters for all the “white paint” materials to the 0.93 value.

@stenb said: I changed the Kd parameters for all the "white paint" materials to the 0.93 value.

Some of them were green… some of them weren’t. Those values are red, green, blue. Kd is diffuse, Ks is specular.