Problem with LightMap And Light (SpotLight) - Black area not illuminated

Hello,

Escuse my English. I am using Google Translate

I created a scene under Blender, it consists of Diffuse textures and an AtlasTexture including a LightMap.

Under JmonkeyEngineSDK, I can correctly place my materials.

The problem of survival in the part of the scene is in the dark. If I use a SpotLight, the light has no influence on the parts
obscure. (Example, a flashlight that illuminates a dark area)

If I understand goods, in the FragmentShader (Lighting.frag), the diffuseColor.rgb is multiplied by LightMapColor.

 #ifdef LIGHTMAP
   vec3 lightMapColor;
   #ifdef SEPARATE_TEXCOORD
      lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
   #else
      lightMapColor = texture2D(m_LightMap, texCoord).rgb;
   #endif
   specularColor.rgb *= lightMapColor;
   diffuseColor.rgb  *= lightMapColor;
#endif

As a result, the diffuseColor is set to 0 when it is multiplied by a black area of ​​the LightMap.

The light of the SpotLight has no influence.

Is the technique I use correct?

How can I solve my problem ?

thank you in advance

THOCED

I think I have found a solution.

In the FragmentShader “Lighting.frag”, I modified this:

 gl_FragColor.rgb =  AmbientSum       * diffuseColor.rgb  +
                      DiffuseSum.rgb   * diffuseColor.rgb  * vec3(light.x) +
                      SpecularSum2.rgb * specularColor.rgb * vec3(light.y) ;

By this:

gl_FragColor.rgb =  AmbientSum       * diffuseColor.rgb  +
                       DiffuseSum.rgb   * diffuseColor.rgb  * vec3(light.x) +
                       SpecularSum2.rgb * specularColor.rgb * vec3(light.y) + (myDiffuse.rgb * vec3(light.x));

myDiffuse is a copy of diffuseColor:

 vec4 myDiffuse;

#ifdef LIGHTMAP
   vec3 lightMapColor;
   #ifdef SEPARATE_TEXCOORD
      lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
   #else
      lightMapColor = texture2D(m_LightMap, texCoord).rgb;
   #endif
   myDiffuse = diffuseColor;
   specularColor.rgb *= lightMapColor;
   diffuseColor.rgb  *= lightMapColor;
#endif

By copying the diffuseColor, I can then add the color of the diffuseMap multiplied by the light factor of the spotLight. Otherwise, the light factor multiplied a value close to 0 caused by the LightMap. The dark areas were not modified, Which did not give the results of a real flashligh.

Below are two videos, one without the modification of the FragmentShader, the second with modification.

On the first video, it can be seen that the dark areas of the LightMap generated by Blender are not illuminated with the lamp.

On the second video, which uses the modified FragmentShader, the dark areas are illuminated.

For the demonstration, the SpotLight parameters are deliberately exaggerated

Without modification of the fragmentshader:

With modification of the fragmentshader:

I do not know if that is the right solution, but it seems to work.

THOCED

2 Likes