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?
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
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.
[java]
Material mat = new Material(Game.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.getAdditionalRenderState().setWireframe(true);
level.setMaterial(mat);
[/java]
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)
@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?
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:
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:
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.
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.
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.
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.
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”));
//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?)