Vertex lighting?

I couldnt find any info on how lighting works, but cant figure it our from in engine.

I have a model with a large floor plane, and a large wall coming out of the floor. When I make a pointlight follow my spatial, and move it close to the wall, a small white light patch appears, which is nice (not what I would expect with vertex lighting). When i move along the wall to the end though, the light patch does not stay in line with my spatial, and lags behind it.

I have also tried subdividing my faces into multiple squares but this resulted in a bizzare warped cube looking light patch on the wall.

What would I do to make my light look natural as I get close to walls?

Could you provide us with a short test app which demonstrates the issue?

Yeah, before I do though I want to check I’m not being stupid and wasting your time.

I never apply a material to the model, just export a textured model and convert to j3o, would that be an issue?

I have one model, which is rendered, and a low detail copy with parts removed placed in the same position that I use for collision, with CullHint.Always

[java]
//light creation
PointLight lamp;

lamp = new PointLight();
lamp.setColor(ColorRGBA.White);
lamp.setRadius(20);
rootNode.addLight(lamp);

//and in update
vectorA = playerControl.getPhysicsLocation(); //this is a CharacterControl
lamp.setPosition(new Vector3f(vectorA.x, vectorA.y+0.7f, vectorA.z));
[/java]

Finally, here is an image with a wireframe view and ingame view of the two models. I did think at first it was caused by the huge triangles, 2 of which make up the entire wall in the 2nd picture

The CharacterControl controls the blue box so that is the light position

This…

Is pretty typical vertex lighting artifacts. It’s because the texture stretches differently along one diagonal than the other because of the way the quads are split into triangles. This is most apparent with these kinds of dramatic lighting setups where there is lots of contrast between lit and unlit.

Not sure what’s going on in the last image, though.

How did you do the wireframe image? Usually I’d expect the wires to still be lit if doing it through the render state on the material.

1 Like

[java]
Material mat = new Material(Game.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.getAdditionalRenderState().setWireframe(true);
level.setMaterial(mat);
[/java]

No lighting whatsoever on it after that

Ok well I put together a small ish test. I understand how vertex lighting works with large triangles, but I cant make sense of this and do not know how to make it look better.
This is the test ( a jar, libs folder, and 2 dlls, sorry I could not get it all into 1 jar)

Here is a shot from that test,

I do not understand why the vertex furthest from the light is the brighest. Also if you walk alongside the right wall the specular looking light patch goes up

Controls for test:

default flybycamera controls
‘c’ disables camera
arrow keys control blue ‘player’
‘v’ enables wireframe
‘p’ and ‘L’ change light radius
‘r’ resets player position if he falls off
(I hope it works)

source: http://pastie.org/8684011

I think I’m just not using lights correctly. Really I want it to look like the player (box) is carrying a lamp, but cannot achieve this effect

Are you sure the normals are right on your mesh? Maybe they are pointing in strange directions.

The effect you want to achieve will probably always look bad with vertex lighting, though. Is there a reason you don’t use regular lighting instead?

Erm, well I just placed lights using the tutorials and assumed this was vertex lighting from the result. Where would one look for regular lighting?

@JESTERRRRRR said: Erm, well I just placed lights using the tutorials and assumed this was vertex lighting from the result. Where would one look for regular lighting?

Oh. You may already be using regular lighting. How is your material setup?

Also, what version of JME are you running?

It only says 3.0 for version, but I ran ‘check for updates’ and it found serveral which were 3.0.4 (I think) that it downloaded. Either way no updates are found when I look now, and there is no change as far as my problem goes.

I exported my model from sketchup, so I didnt do any work with materials in that (exported with ogre exporter). Then I convert to j3o in the SDK, and load it as such:

level = assetManager.loadModel(“Models/test/test.j3o”);

However there is a material file included, test.material. I do not know if JME automatically loads this when I load the j3o file, but inside the material file, materials for all textures are listed like this:

material 1391123813_2_wall3
{
technique
{
pass
{
ambient 0.0 0.0 0.0
diffuse 0.749019607843137 0.745098039215686 0.737254901960784
specular 0.0 0.0 0.0 0.0
emissive 0.0 0.0 0.0
// texture size: 23.62204724409, 23.62204724409
texture_unit
{
texture 1391123813_3_wall3.jpg
}
}
}
}

and so on for each texture

Each one is identical, bar the size and diffuse values which vary a little.

If you have the j3o open in scene composer then you can generate the material file for it and take a look. It should be a .j3m file stuck somewhere in assets/Materials/Generated or something.

1 Like

Took me a while to find, but I clicked on generate, and the file it generated-

[java]
Material MyMaterial : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
DiffuseMap : Repeat Models/mymodels/1391144976_18_metalwall2.jpg
GlowColor : 0.0 0.0 0.0 1.0
Specular : 0.0 0.0 0.0 1.0
Diffuse : 0.7372549 0.7372549 0.7372549 1.0
UseMaterialColors : true
ParallaxHeight : 0.05
Ambient : 0.0 0.0 0.0 1.0
Shininess : 16.0
}
AdditionalRenderState {
FaceCull Back
Wireframe Off
DepthWrite On
PolyOffset 0.0 0.0
AlphaTestFalloff 0.0
Blend Off
PointSprite Off
ColorWrite On
DepthTest On
}
}
[/java]
This is the material for the walls in all the screenshots. When I load it in code as opposed to the scene composer, I assume it automatically generates these?

@JESTERRRRRR said: Took me a while to find, but I clicked on generate, and the file it generated-

[java]
Material MyMaterial : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
DiffuseMap : Repeat Models/mymodels/1391144976_18_metalwall2.jpg
GlowColor : 0.0 0.0 0.0 1.0
Specular : 0.0 0.0 0.0 1.0
Diffuse : 0.7372549 0.7372549 0.7372549 1.0
UseMaterialColors : true
ParallaxHeight : 0.05
Ambient : 0.0 0.0 0.0 1.0
Shininess : 16.0
}
AdditionalRenderState {
FaceCull Back
Wireframe Off
DepthWrite On
PolyOffset 0.0 0.0
AlphaTestFalloff 0.0
Blend Off
PointSprite Off
ColorWrite On
DepthTest On
}
}
[/java]
This is the material for the walls in all the screenshots. When I load it in code as opposed to the scene composer, I assume it automatically generates these?

Well, the “generate” just took the material that was already in the model and dumped it to a file. Now that j3o uses this material file and you could tweak stuff about the material.

It all looks ok to me.

Next thing to try would be debugging your mesh’s normals. There is some way to do this but I’ve never done it.

I cannot find a way to draw the normals, I found some stuff in a class called Debugger but it is for an older version :frowning:

I can see the normals in blender though. These are the normals of the metal looking wall shown in all my pictures

They look correct to me? They are definitely facing the correct way. The exporter I used is that which is installed by the JME SDK.

There’s a “Common/MatDefs/Misc/ShowNormals.j3md” material definitions asset built into jME3. Perhaps that’s what @pspeed was referring to. It’s used for example in the Hello Assets tutorial.

1 Like

Oh, thanks. So the material seems to do…

gl_FragColor = vec4((normal * vec3(0.5)) + vec3(0.5), 1.0);

And running it with this material applied

Im not entirely sure how to analyze that

If some of the triangles on the wall had flipped normals you would see that pretty clearly, they would be a different color from the other triangles on the wall.

1 Like

I feel like I’m just doing something wrong, or have missed out some setting or something. So to simplify this,

[java]
//2 large boxes

Box box1 = new Box(60,1,60);
level = new Geometry(“Box”, box1);

Box box2 = new Box(60,20,1);
level2 = new Geometry(“Box2”, box2);

Material mat_brick = new Material(Game.assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat_brick.setTexture(“DiffuseMap”, Game.assetManager.loadTexture(“Textures/mytextures/BrickWall.jpg”));

level1.setMaterial(mat_brick);
level2.setMaterial(mat_brick);

//create a point light
lamp = new PointLight();
lamp.setColor(ColorRGBA.White);
lamp.setRadius(100);

//added them all to rootNode
[/java]

I create 2 huge cubes, and place a light near them, again marked by the blue box (this time I used PointLight.setPosition() )
Is this what my scene should look like, I have done nothing beyond extend SimpleApplication and add the boxes and point light.


(The vertical cube is in the center of the floor cube, which recieves no light whatsoever?)

Yeah, those boxes are too big for proper point lighting.

You could try using Lemur’s MBox. It is used just like JME’s Box except that you can subdivide it. You can either download the lemur jar:
http://hub.jmonkeyengine.org/forum/topic/lemur-repo-link/

…or just cut and paste the MBox source file.
http://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/src/com/simsilica/lemur/geom/MBox.java