Wierd Light Behavior

Hey guys,



I have 1 ambient light that lights up all of my terrain:



http://i.imgur.com/vZVKs.png



When I add a PointLight to a projectile, everything else gets darker:



http://i.imgur.com/akBJ8.png



When the PointLight gets removed (when the projectile gets destroyed), the terrain goes back to being bright again. Why does this PointLight darken everything else? :frowning:

In the first screenshot the terrain is still effected by lighting, as the blocks are darker on the left than are in front



Perhaps you can provide a test case to reproduce this issue?

I just updated to the latest SVN and Iā€™m going to test this a bit moreā€¦



EDIT: Yay! The latest SVN does not have this problem! :slight_smile: :slight_smile: :slight_smile:

New problem :frowning:



The lights look good now, and 1 bullet (with 1 PointLight) runs great (performance doesnā€™t degrade):



http://i.imgur.com/jk7TI.png



However, when I shoot a second shot, and another PointLight is added to the root node, the frame rate drops significantly:



http://i.imgur.com/T7PKP.png



What could be going on here? :frowning: The moment the engine goes back to one PointLight (or none), and just the worldā€™s ambient light, the FPS returns to around 111 FPS.



PS: The blocks have different lights on different edges because that is how the material / texture was designed (so I could use less lights to get the same effect)

The whole terrain has to be drawn again for each light

This is expected, for every light you add the entire scene is rendered another time. Perhaps you need to optimise what is drawn, for example, are you drawing all of the boxes in your hill even though they are not visible?



In any case, attaching a light to your bullets probably isnā€™t the way to go, it is very computationally expensive. Unless you make lights only affect the geometry within their radius which is another story.

1 Like

:frowning:

I am not rendering all the boxes in that hillā€¦ when it generates the hill, it only creates quads for visible faces.

Is there another way to achieve this effect without attaching a light to every bullet? ā€¦ and, how would I make it only affect geometry within the radius? Just adding it to a node with the nearby geometry?

I was hoping to use lighting around the buildings for nighttimeā€¦ but if my performance drops after 2 lights, Iā€™m not sure what Iā€™m going to do :confused:

Is your scene static? If so you could have a daytime texture and a night time texture, bake the lights in and blend between the two. Then you only have to worry about lighting dynamic objects. Obviously this wouldnā€™t work with a fully dynamic scene and more trickery would be needed.



FYI, when a spatial is rendered the lights that are used are ones attached to the spatial itself and all of the spatials above it in the scene graph. If you need to have a lot of lights, I would look for a way to only use nearby ones. Perhaps some kind of spatial partitioningā€¦ I havenā€™t used jme for long enough to know what itā€™s really capable of in this area.

1 Like

Iā€™m going to have to rethink my strategy for lightingā€¦ my terrain isnā€™t static (destructible / procedurally generated etc.)ā€¦ my ā€œchunksā€ are pretty big (33x33x33 blocks) and sit on a single node, which makes re-rendering even a single chunk each frame for each light not much of an optionā€¦ :frowning: :frowning:

Hereā€™s one idea. If you spread the blocks out into smaller partitions so there is less blocks per node. You can then attach your lights to nodes that are within range instead of to the root node. If lights move just attach and detach them to the nodes as they come within a certain range. (Lights sitting in between two nodes would be attached to both).

It is a good idea, and might be what I need to doā€¦ but I currently generate buildings within each chunk, so shrinking the chunk size will require changes elsewhere too :confused: Also shrinking the chunk size will require my game to load more chunks to keep the draw distance high, which will add to the overhead (e.g. positioning each chunk relative to the player [which always sits at 0,0,0], which I do because chunk locations may be in the millions, where float positions donā€™t have as good precision).



Is there a way to modify the brightness of each individual block via the material in real-time? I could compute lighting and modify the material each time lights changes, kinda like Minecraft? My terrain is built in large chunks as all one mesh, so this may further complicate things :confused:



continues to brainstorm, thanks for the help!

If it helps as a hintā€¦ Mythruna has only one real Light.

One real light seems like the only practical way forwardā€¦ is the one light an ambient affecting all geometry equally, or is there a way to partially apply a light to individual faces?

Mythruna has one directional light for the sun/moon. It tracks over the sky with time. Everything else is baked into the geometry at runtime.