Building a Sync Tool for Blender to Defold

I think this is lighting. If you are using the simple one I posted. It is based on the model material. The fragment shader on these lines does this:

    // Diffuse light calculations
    vec3 ambient_light = vec3(0.2);
    vec3 diff_light = vec3(normalize(var_light.xyz - var_position.xyz));
    diff_light = max(dot(var_normal,diff_light), 0.0) + ambient_light;
    diff_light = clamp(diff_light, 0.0, 1.0);

The first line sets an ambient light level - 0.2. The second line calculates the normalized light direction vector. The third line then does a dot product between the normal of the mesh surface and the light direction, then adds the ambient light. And finally the last line clamps the light results between 0.0 and 1.0.

What could be happening is that you are seeing the ambient lighting overriding the small changes in lighting. Try changing ambient from 0.2 to 0.0 to see if there is any significant difference.

Another possibility is that the normal for the surface is incorrect. A way to test/check this is to change the last line in the fragment shader from:

gl_FragColor = vec4(color.rgb*diff_light*lightmap.rgb,1.0);
to
gl_FragColor = vec4(var_normal, 1.0);

Which should show different colours for each surface direction.
Hope this helps. Will try out a couple of scenes to replicate it.

1 Like