(JME3) Light (lantern, lamp) on textured meshes?

Hi!



I am having big trouble trying to create moving light that light up textured meshes, for lanterns or lamps.



I saw that DirectionalLight works fine tho.



I am developing based on “SimpleBulletApplication extends Application”. I looked everywhere and I cant find the light that seems already attached to it, may be it is interfering?



At jme3tests I saw no example that showed a texture mesh being dynamically lighted up. The manylights test was based on a scene, I am using eclipse (as netbeans platform got slow here…). So I couldnt find a way to code dynamic light that affect textured meshes yet.



Any tips/links on this? I see many howto are about jme2, but as jme3 is MUCH easier to use, I will stick to it :D.



I saw no SpotLight also on jme3, I wonder I would have to create a mesh around pointlight to prevent it spreading backwards, what would be fun to implement anyway :D.

What kind of material are you using?

You should use the Lighting.j3md



I don’t think that there is a default light in SimpleBulletApplication



About the spot light, it’s not yet implemented.

The mesh solution you are talking about won’t work though, because the occlusion is not computed by the materials.

Think of light as “a way to render material” and not as an object. You can’t prevent light to spread backward with a mesh. You would need the shadow processor to cast shadows but the result won’t be what you are looking for.



To implement spot lights you would need to modify the Lighting.j3md so that it could handle it like described in this tutorial

oZone3D.Net Tutorials - Phong Lighting with GLSL - OpenGL Shading Language - Point Light - Spot Light - Attenuation



I guess this will eventually be implemented in JME3

I saw the tutorial, I will go for it after I can make textured meshed be lighted, thx!



Yesterday I thouth that may be I could modify that lighting.j3md at jme3platform netbeans. But that modification must allow the material to be texturized, so I will just apply that material to all meshes and setup a texture to each one/kind. I wonder if it is possible at jme3platform? despite it runs slow here… but for this stuff will work great!

There’s a test, I think its called TestNormalMapping, which shows a textured sphere with lighting. You could look at that example. Adding spot lights would be kinda complex, since the current system isn’t really optimized for handling them.

@Momoko_Fan it is “Textures/Terrain/Pond/Pond.j3m” worked very well, almost perfect!



I will try to change it at jme3platform so the texture become a parameter :smiley:



thx!

A tip to fake a lantern (now I remember it is being used on several and several games (I think…)) is to just cast ray and move the spot light a bit before to where it hits xD.



I am thinking on other tricks like create a fake cone and all objects that collide or are inside of it, are lighted up; I have yet no idea how to make the light shape to show/draw on the floor, may be some kind of boolean mesh intersection (see UnBBoolean, I will try to port to JME3 later), but that is too much realism for now…



EDIT: Btw, I found a bug in Pond.j3m? it seems to turn off lights in certain circunstances I am not sure how it happens.

Here you see the mesh lighted up:

lighed mesh



And I turn a bit to the right and it goes all in shadow… I have 2 lights, a sun and a spotlight at cast ray hit spot. The sun light seems to go off sometimes…

shadowed mesh



other meshes, like boxes, before leaving the visual area (I still can see them) they simply turn off lights when using Pond.j3m… if I look back they light up again.

Your screenshot looks strange, the pond material should display some pebbles.

The UVs of your mesh seems to be a bit off.



Isn’t there some reflection involved?

yep, what you see is a scalarfield (metaballs) mesh. Long ago I remember it still stretches the texture, and this is a big scalarfield… also, the Pond.j3m material doesnt give us access to change the texture (to Repeat or MirrorRepeat) but even before when I used a texture where I could setup Repeat, the scalarfield seems to have some bug related to textures that stretches them? I still have to look at it someday :).



yup, it seems there is reflection involved, I think Pond is created with some kind of reflection effect? I am using eclipse, have downloaded jme3sdk-alpha2 but hadnt time to test it yet, and most importantly, play with pond material to expand/“fix?” it if possible? :smiley:



btw, here a box with Pond material, showing the top is darkened, but I move a bit to the side and it lightens up…

darkened top mesh

lightened mesh

Mmmhh looks more like a normal problem…

maybe you need to recompute tangents and bi-normals on your cube (it’s kind of the magic thing :stuck_out_tongue: )



TangentBinormalGenerator.generate(cube.getMesh());

thx nehon, it worked in someway, now the face doesnt get darkened suddenly, but I have now 4ever darkened faces (seems to be both oposite sides of the cube in the Z axis) (here you see the lower faces are lightened by a spotlight I move around stick at normal end from cast ray hit spot, but that is hitting the upper face that never gets lighted no matter how much I roll the cube, as it has something to do, well there is a distant sun light so I thought that…):

forever darkened faces



also, if I use binormal generator in a mesh (scalar field generated), it gives me null pointer exception, the mesh works fine w/o binormal generator; where mesh.getMode() returns “Triangle”:



java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

at java.util.ArrayList.rangeCheck(ArrayList.java:571)

at java.util.ArrayList.get(ArrayList.java:349)

at com.jme3.util.TangentBinormalGenerator.processTriangleData(TangentBinormalGenerator.java:329)

at com.jme3.util.TangentBinormalGenerator.generate(TangentBinormalGenerator.java:105)

at com.jme3.util.TangentBinormalGenerator.generate(TangentBinormalGenerator.java:81)





Anyway, this is the perfect material to use dynamic light moving around for now, I just wonder if messing with Pond.j3m may help to improve it? I have to look at it later as netbeans is somewhat slow here…

teique said:
(seems to be both oposite sides of the cube in the Z axis)

you mean the Y axis, aren't you?

I'm afraid i won't be able to help you :(. I don't get what's going on. Maybe you could post the code for initializing the cube and the lights, and i'll see what i can do.

The pond.j3m is based on the lighting material definition and has a diffuse map and a normal map. There are not a lot of things to do about it.

Anyway your spot light looks good, how is it performance wise?

No no, it is the Z axis (I dropped that physnode cube and shot several times til it turn around heh, so local geom/mesh cube Z got upwards xD )



The performance is great, may be I have few lights? a sun, a moving spotlight, shadows, water, sky, complex scalarfield mesh all seem fast, but world is still humongously… tiny :P, anyway it is a geforce gts 250 what helps as my cpu is 4 years old monocore ^^ amd64 3000+. I need to code fps info yet btw…



Here is a test case,

initially, just hold D key to move right side and show the 2nd box, without binormal, sudden shadow happens.

The 1st box has several spotlights around I show with wireframe spheres, you will see at Z axis, both cube sides are 4eva darkened, never light up after binormal;

Be aware that there is a sun also.



import com.jme3.app.SimpleApplication;

import com.jme3.app.SimpleBulletApplication;

import com.jme3.bullet.collision.shapes.BoxCollisionShape;

import com.jme3.bullet.nodes.PhysicsNode;

import com.jme3.light.DirectionalLight;

import com.jme3.light.PointLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.queue.RenderQueue.ShadowMode;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.scene.shape.Sphere;

import com.jme3.util.TangentBinormalGenerator;





public class TestCasePondLighting extends SimpleBulletApplication{

public static void main(String[] args){

TestCasePondLighting app = new TestCasePondLighting();

app.setShowSettings(false);

app.start();

}



@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(10);

cam.setLocation(new Vector3f(0,3,10));



Material mat = assetManager.loadMaterial(“Textures/Terrain/Pond/Pond.j3m”);

Material matDebugYellow = new Material(getAssetManager(), “Common/MatDefs/Misc/WireColor.j3md”);

matDebugYellow.setColor(“m_Color”, ColorRGBA.Yellow);



{

Box box = new Box(Vector3f.ZERO,1,1,1);

Geometry geom = new Geometry(“a”,box);

geom.setMaterial(mat);

PhysicsNode phys = new PhysicsNode(geom,new BoxCollisionShape(Vector3f.UNIT_XYZ));

TangentBinormalGenerator.generate(box);

rootNode.attachChild(phys);

}



{

Box box = new Box(Vector3f.ZERO,1,1,1);

Geometry geom = new Geometry(“a”,box);

geom.setMaterial(mat);

PhysicsNode phys = new PhysicsNode(geom,new BoxCollisionShape(Vector3f.UNIT_XYZ));

phys.move(Vector3f.UNIT_X.mult(10));

//TangentBinormalGenerator.generate(box);

rootNode.attachChild(phys);

}



{

PointLight pl = new PointLight();

pl.setColor(ColorRGBA.Yellow);

pl.setRadius(10.0f);

pl.setPosition(new Vector3f(-1.5f,1.5f,1.5f));

rootNode.addLight(pl);



Geometry geomLight = new Geometry(“light”,new Sphere(6,6,0.05f));

geomLight.setMaterial(matDebugYellow);

geomLight.setShadowMode(ShadowMode.Off);

geomLight.setLocalTranslation(pl.getPosition());

rootNode.attachChild(geomLight);

}



{

PointLight pl = new PointLight();

pl.setColor(ColorRGBA.Cyan);

pl.setRadius(10.0f);

pl.setPosition(new Vector3f(1.5f,-1.5f,-1.5f));

rootNode.addLight(pl);



Geometry geomLight = new Geometry(“light”,new Sphere(6,6,0.05f));

geomLight.setMaterial(matDebugYellow);

geomLight.setShadowMode(ShadowMode.Off);

geomLight.setLocalTranslation(pl.getPosition());

rootNode.attachChild(geomLight);

}



{

PointLight pl = new PointLight();

pl.setColor(ColorRGBA.Green);

pl.setRadius(10.0f);

pl.setPosition(new Vector3f(1.5f,-1.5f,1.5f));

rootNode.addLight(pl);



Geometry geomLight = new Geometry(“light”,new Sphere(6,6,0.05f));

geomLight.setMaterial(matDebugYellow);

geomLight.setShadowMode(ShadowMode.Off);

geomLight.setLocalTranslation(pl.getPosition());

rootNode.attachChild(geomLight);

}



{

PointLight pl = new PointLight();

pl.setColor(ColorRGBA.White);

pl.setRadius(10.0f);

pl.setPosition(new Vector3f(0,0,1.5f));

rootNode.addLight(pl);



Geometry geomLight = new Geometry(“light”,new Sphere(6,6,0.05f));

geomLight.setMaterial(matDebugYellow);

geomLight.setShadowMode(ShadowMode.Off);

geomLight.setLocalTranslation(pl.getPosition());

rootNode.attachChild(geomLight);

}



DirectionalLight sun = new DirectionalLight();

Vector3f v3f =new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);

sun.setDirection(v3f);

sun.setColor(ColorRGBA.White.clone().multLocal(2));

rootNode.addLight(sun);

}



}





PS.: is there a way to not loose indentations when pasting in code tag?