Grabbing light without a normal?

Hello guys, I’m new to jMonkeyEngine but I like it a lot already.

But I ran into a problem and was wondering if there was a simple solution. I’m making a 3d environment with “2d” (flat) characters.

I’m loving how easy it has been to add in normal maps and lighting and such but it seems like there has to be a normal attached to each polygon.

Is there any way to have a polygon that will accept light in any direction?

Or a way to grab the light information from a specific point in 3d space?

Here’s a picture of my progress so far:





I didn’t set the normal for the character sprites but they seem to default to something. If I move the light behind the character it will go dark.



Thanks in advance :slight_smile:

1 Like

You can use the Unshaded material, and that will ignore the lights. Or you could attach a light to the node of your character, and have it sit in front: between the character and the screen.

Your game looks good so far :smiley:

1 Like
@Sploreg said:
You can use the Unshaded material, and that will ignore the lights. Or you could attach a light to the node of your character, and have it sit in front: between the character and the screen.

Thanks but yeah I figured out those two ideas earlier, but I don't want to make a new light for each entity and attach it. I want to be able to grab the current light from the area.

I was thinking of making two small triangles with normals in each six directions then seeing if I could find a way to grab the light value from the vertex and apply it to an Unshaded value. I'm gonna try that in a bit, I just wanted to see if there was like a world.getLightValue(x,y,z) function of some sort.

@WASD said:
Your game looks good so far :D

Thanks :)
I stole the character sprite for now, everything is just getting set up. Just working my way into learning this engine.

What appends if you dont specify a normal buffer? btw, I suggest using the unshaded material however

What appends if you dont specify a normal buffer? btw, I suggest using the unshaded material however

@EmpirePhoenix said:
What appends if you dont specify a normal buffer? btw, I suggest using the unshaded material however

It appears to give it a normal pointing toward the camera, which I believe would be a positive z vector.
Any light behind the characters won't show up.
I'll try the idea I posted above by attempting to pass the light values onto an unshaded material and post back.
@djoslin said:
I'll try the idea I posted above by attempting to pass the light values onto an unshaded material and post back.

The Unshaded material doesn't use lights.

If you are using a simple quad to render your sprite texture, then yes it does default the normal along the +Z axis.
@Sploreg said:
The Unshaded material doesn't use lights.

If you are using a simple quad to render your sprite texture, then yes it does default the normal along the +Z axis.

Yes, but I've noticed I can set the color of the material. So I can fake it if I can figure out one thing..
Is there a way to grab the light value of a certain vertex on a polygon if it's using lighting?
I tried this:
VertexBuffer vb = modellight.getMesh().getBuffer(Type.Color);

But it seems to return null, so I don't think it's the right command.

What effect are you trying to achieve? You want the quads (representing the players) to respond to where a light is? Or you just want them showing up all the time but with various intensities in a level?



You can always add an ambient light to the character node (in front of it) and make it really dim, so it at least shows up and will still be affected by a point light.

But I think it might look weird shading the 2d surface based on its angle of incidence to a nearby light. If you are in front of it or behind it, you will have full lighting. But if you are beside it, it won’t have any. If you walk a circle around a point light, it will change at each 90 degrees.

Will your characters always be on the floor?



If so then you could just set their normals facing up, give them a little brightness boost in the material color and things will sort themselves out.

Yeah I want the quads to be lit by the lights in the environment. The problem is that the lighting system needs a normal facing the light in order to effect the polygon. I’d like to be able for the quad to be lit to the correct light color of the environment at all times. Since it’s a 2d/3d hybrid, the lighting for the sprite shouldn’t really have a direction since the quad represents the entity.



I have a slight ambient light and a light follows around the player, but I want to be able to add blue lights to the environment and have the player show up blueish when he walks by it.



I figure If I create another mesh and have it follow the player mesh it can be using the lighting system and have 6 vertexs total, with a normal facing in each different direction (x+, x-, y+, y-, z+, z-). But I can’t figure out how to access the current lighting information for the polygons.

Say I had a quad that was using the lighting system, is there any way to grab the current RGB value of a certain vertex?

If I could do that I could figure out which of the six vertexes had the highest RGB value and then set the player quad material to be colored to the lighting information it just grabbed.



But yeah I know I can just set it simply to unshaded or have a light follow it, but that’s not what I want if I can help it. This system will be used for much more than just the players, I plan on having different entities in the level and it would look weird if every sprite was just fullbright the whole time.



(Thanks for your help by the way, I really appreciate it.)

@pspeed said:
Will your characters always be on the floor?

If so then you could just set their normals facing up, give them a little brightness boost in the material color and things will sort themselves out.


Yeah, most of the time. I think I'll just go with that, I'm tired of fooling around with it anyway. But if anyone does know of a way to access the lighting information of specific vertexes or points in space that would be cool. But normals facing up will work for now.

You’d have to do the calculations yourself. If your lights have attenuation then that’s the only calculation f(distance) where f is some attenuation function. I don’t know it off the top of my head.



Way easier to let the engine do the work. :slight_smile:

I suggest that you write a light shader yourself, its actually quite easy(for your case), once you understood the way shaders work.

You can set a normal map on the quad, that should do what you want

Don’t forget to use the Common/MatDefs/Misc/ShowNormals.j3md material when debugging normals, it can be super useful.

@thetoucher said:
Don't forget to use the Common/MatDefs/Misc/ShowNormals.j3md material when debugging normals, it can be super useful.

It won't show normals from the normal map though, only the normals from the quad, which in that case would just face the camera.