Vertex Color and Lighting.j3md

Hi,



is it possible to only use vertex colors in combination with Lighting.j3md (e.g. no textures)? E.g. vertex colors = the diffuse color to use.

The parameter ‘UseVertexColor’ doesn’t seem to give the desired result here.

I have a mesh with specified vertex colors and one directional light:



Material mat = new Material(game.getAssetManager(),“Common/MatDefs/Light/Lighting.j3md”);

mat.setFloat(“Shininess”, 15f);

mat.setBoolean(“UseVertexColor”, true);



Unless I specify the diffuse color I see nothing

mat.setBoolean(“UseMaterialColors”, true);

mat.setColor(“Diffuse”, diffuseColor);

but then again, that diffuse color overrides my vertex color.



setting vertex lighting colors my model to the color of the light, also not what I want.

mat.setBoolean(“VertexLighting”, true);

If you want just the vertex color just make sure the diffuse color and the light’s color are white

Thanks

I have this exact same situation. If I have the following code, it works fine. I see the mesh with colors correct, but no lighting, as expected.

[java]

// assume at this point that the “this” object is a Mesh, with all setBuffer() calls done.

G = new Geometry( “foo”, this );

Material mat = new Material( assetManager, “Common/MatDefs/Misc/VertexColor.j3md” );

G.setMaterial( mat );

[/java]

Then I try to implement the suggestions in this thread, and I change the above code to the following instead.

[java]

// assume at this point that the “this” object is a Mesh, with all setBuffer() calls done.

G = new Geometry( “foo”, this );

Material mat = new Material( assetManager, “Common/MatDefs/Light/Lighting.j3md” );

mat.setFloat( “Shininess”, 15f );

mat.setParam( “UseVertexColor”, VarType.Boolean, true );

mat.setParam( “UseMaterialColors”, VarType.Boolean, true );

mat.setParam( “VertexLighting”, VarType.Boolean, true );

mat.setColor( “Diffuse”, ColorRGBA.White );

G.setMaterial( mat );

[/java]

This makes the entire mesh black and unlit. I have tried it with the UseMaterialColors and VertexLighting lines commented out (one, another, or both), but that didn’t help either.



Wombat, is this what you did, and it worked for you?



Nathan



PS: Yes, I have a directional light in the scene, and I’ve had other stuff in this scene lit successfully.

This is my code:



Material mat = new Material(game.getAssetManager(),“Common/MatDefs/Light/Lighting.j3md”);

mat.setFloat(“Shininess”, 15f);

mat.setBoolean(“UseVertexColor”, true);



mat.setBoolean(“UseMaterialColors”, true);

mat.setColor(“Ambient”, ambient); //Using white here, but shouldn’t matter that much

mat.setColor(“Diffuse”, ColorRGBA.White);

mat.setColor(“Specular”, specular); //Using yellow for example

mat.setBoolean(“VertexLighting”, true);



and two lights I have in that one case (testing):

DirectionalLight light=new DirectionalLight();

light.setDirection(new Vector3f(-1, 0, -1).normalizeLocal());

light.setColor(ColorRGBA.White);

game.getRootNode().addLight(light);





AmbientLight ambient = new AmbientLight();

ambient.setColor(ColorRGBA.White/.mult(0.5f)/);

game.getRootNode().addLight(ambient);



This works for me…

2 Likes

This is exactly what I do, and I find that the color of the surface of the object is determined solely by the ambient light. No side of the object looks brighter/dimmer than any other; they’re all just ambiently lit the same. So the directional light is being ignored.



…which makes me realize that I’m stupid. I hadn’t defined normals for the mesh, because up until now I hadn’t needed them, which is why the directional light was being ignored. With normals, all works well.



Thanks! :slight_smile:

If diffuse color is white and ambient light is white then white * white = white. Reduce either the ambient light or the diffuse color to see darker parts

I’ve got it working now; the issue was the normals.

I am having this same problem, I know it’s not the normals, because I have a moving light and the normals are working well enough.



My code is essentially the same as @wombat has.



Did the lighting or materials code change in the past 6 months in a way that would make vertex colors no longer be possible with Lighting.j3md?

I know, this is 10 years old. But since I just had this problem, I suppose somebody else might face it, too.

Lighting.j3md has another flag UseVertexColor. So setup normals and vertex colors, then use something like this:

    val myMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md")
    myMat .setBoolean("UseMaterialColors", true)
    myMat .setBoolean("UseVertexColor", true)
    myMat .setColor("Diffuse", ColorRGBA.White)
    myMat .setColor("Specular", ColorRGBA.White)
    myMat .setFloat("Shininess", 64f) // [0,128]
    myMat .setBoolean("VertexLighting", true)