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.