(SOLVED) Vertex Colors *and* light possible? (yes, use MaterialState)

In short: Is there any way to have both vertex colors and light?



So far it seems that either I switch off the light - and then the vertices of a triangle will be shown using their own color, or I turn on the light, and then I get only the colors and shadings of the light and eventual textures I may have on the triangle. What do I have to do in order to have both at the same time? That is, the vertex colors should be modified by the light in some way or other (additive to saturation, etc.)

pretty please?



Or is this a too stupid of a question?

Did you try MaterialState.setColorMaterial()?

No. My mistake.



But … when I try it, something strange happens: it does combine the light with the vertex colors somehow. But approx. every second triangle is inverted. that is, it looks gray instead of some yellowish hue (which would be the combination of my vertex color with the light color) and if I go and look at it from the other side, the color is there, all right, but from the other side. But it does not help to turn around the normal of that triangle, nor does it help to attach the same two lights from the opposite direction. So it's not a normals related problem. See also attached screenshot.



I am setting up the mesh normals using the normals generator.



I am setting up two lights like this:

PointLight light = new PointLight();

light.setLocation(new Vector3f(-100,0,100));

light.setEnabled(true);

lightState.attach(light);



and



light = new PointLight();

light.setLocation(new Vector3f(100,-100,32));

light.setEnabled(true);

lightState.attach(light);



Materialstate I set up like this:

MaterialState state = display.getRenderer().createMaterialState();

state.setColorMaterial( MaterialState.ColorMaterial.AmbientAndDiffuse );

state.setShininess( 10 );

state.setAmbient( new ColorRGBA( 0.1f, 0.1f, 0.1f, 0.5f ) );

state.setDiffuse( new ColorRGBA( 0.4f, 0.4f, 0.4f, 0.5f ) );

state.setSpecular( new ColorRGBA( 0.6f, 0.6f, 0.6f, 0.5f ) );

myMesh.setRenderState( state );



Whenever I change something in the state, the colors change, or disappear, but this distinction between completely grayed and color triangles always stays and always affects the same triangles.



I guess I am almost there, but still missing some essential clue!

ok, sorry, let me be embarassed for a while. Naturally, there is this handy method called setMaterialFace and I simply had to



state.setMaterialFace(MaterialFace.FrontAndBack);



Thank you for the help!

"YourConscience" wrote:
ok, sorry, let me be embarassed for a while. Naturally, there is this handy method called setMaterialFace and I simply had to

state.setMaterialFace(MaterialFace.FrontAndBack);

Thank you for the help!
If you had to do that the normals of your model are severely f**ked up..

But in this case it's not my fault. All I did to obtain them was this:



NormalGenerator gen = new NormalGenerator();

gen.generateNormals(mesh, crease);



where I tried various values for crease, but ended up using 0.



Perhaps I did something wrong when creating the triangles? I use a delaunay triangulation and then for each triangle I add three vertices to the vertices buffer and set the indices accordingly. That means that I never reuse vertices. Perhaps this is what the generator expects, and since every triangle is on its own it can't recognize them to belong to a common patch or something.



Just so that you know what I was getting at, here is a screenshot. (no, it's not a game. it's a semantic space visualization tool which obtains its information from statistically significant word usage)