Dynamic Lights

Jun 26, 2011 at 8:22 PM

Hello guys!

First, I'd like to thank you for great work that you've done so far, it really helped me understand whole concept :) I have question regarding dynamic lights - is it possible with this engine? I dream of a possibility to carry torch instead of putting it as a static object. I understand how light works in TechCraft and thats its propagated through "air" None type blocks and then compiled into one amout for sun and for local light (flowers) when vertex list is built. This is where I see the problem - calculating a light radius for a moving target is not as bad as need to recreate whole chunk mesh to supply new light values to VertexPositionTextureLight vertices. 

I warn you that I just returned to 3D engines after 12 years of not doing any code so I'm rusty and have no idea how things like dynamic lights are done nowdays, especially in XNA. So I kindly ask for some help regarding this topic - is it possible to do without need to recompile chunk mesh? If so, how? I tried Googling the topic but I havent found many things that would push me forward with this. 

This is about torches, but it would be virtually any point light source thats moving - starting from burning objects, to some glowing worms :) So far TC light implementation is very good for "static" light that doesnt change often.



Jun 29, 2011 at 10:15 AM

As the engine stands it won't support dynamic lights. Currently the lighting is faked and only calculated when a block is added or removed. To do what you are suggesting and to enable a substantial number of dynamic lights you would need to use deferred rendering. In an early version of the techcraft engine i used exactly this approach http://www.youtube.com/watch?v=ZgRmn0rQUIs using a 3rd party lighting/rendering engine http://www.synapsegaming.com/. There are however some performance issues which come up when you switch to deferred rendering in that the scene is renderered multiple times per frame to generate the lighting. 

Implementing sunburn in techcraft is relatively straight forward and mainly consists of switching the engine to maintain sunburn sceneobjects rather than vertex buffers. 

One nice thing you could add very easily is a player torch - simply pass the torch position and intensity into the shader and modify the light values based on distance from the torch and the torch intensity.



Jun 29, 2011 at 4:27 PM

Thanks for reply! 

Thats what I was afraid of :( I had a vision of really nice feature with that dynamic lights - nothing fancy really but movable torches that could be dropped or carried by characters would add very nice immersion to the game. Sad to hear its only possible with deferred rendering :( Player torch is nice, but won't be the same as possibility to see some light cast by other player in dungeon carrying a torch, ehh. There is no way to improve current engine to only recalculate part of mesh / lighting instead of whole chunk for example? Torch has pretty limited range, it could be 3-4 blocks away, so maybe it would be possible? Or I'm missing something here.

Guess I will have to do with whats possible then.

Jun 30, 2011 at 7:14 PM

To do what you're thinking of is pretty straight forward using an engine like sunburn. The code changes are relatively simple - i've got some old code kicking around with a very early version of this engine which uses sunburn for lighting. There is still active development going on with the engine at the moment on a private fork for the time being, but more dynamic lighting is something i'd love to have.  I'll post any ideas i get, but other than using deferred rendering i can't think of anything atm.

Jun 30, 2011 at 8:23 PM

Thanks, I will be looking here from time to time in case anyone has any idea how to solve it :) And I will look into Sunburn too, did you use that free trial version or Indie or higher license?

Jul 20, 2011 at 10:19 PM

Here's an idea: pass the position of the light source and the light range (of the torch) to the shader, and shader side, make the faces brighter if it's within range of the light.