Xonotic Forums
[Script] Full realtime world lighting, using static light entities - Printable Version

+- Xonotic Forums (https://forums.xonotic.org)
+-- Forum: Creating & Contributing (https://forums.xonotic.org/forumdisplay.php?fid=10)
+--- Forum: Xonotic - Development (https://forums.xonotic.org/forumdisplay.php?fid=12)
+--- Thread: [Script] Full realtime world lighting, using static light entities (/showthread.php?tid=5403)



[Script] Full realtime world lighting, using static light entities - MirceaKitsune - 03-21-2015

One of my modern issues with Xonotic has been that, in an era where nearly all 3D engines use realtime lighting, Xonotic is still stuck with baked lightmaps. This is partly due to performance issues, and partly because that's how the existing maps have been designed. I previously suggested a port to idTech4 for this and other reasons... but since that's a huge effort and unlikely to get done, I thought it would be best to check what I can do with the existing engine instead.

I've been thinking for a while about creating a script which disables lightmaps and converts all static lights into realtime lights. My aim is basically to make the choice between using lightmaps and realtime map lighting entirely up to the user. However I want the method to work for all existing maps, without requiring recompilation or new light entities. Most maps include a rtlights file which only add dynamic lights in a few select locations... totally not what I'm looking for.

So I tried this out today, and actually got quite an impressive result. The good news is, I managed to create two scripts which can toggle between using lightmaps and using realtime lights, regardless whether the map has a rtlights file or not. It even supports realtime bounce lighting, and performance is only reduced to half on my machine! The bad news is that for some reason, it only works on a few maps. I asked the Darkplaces devs why, and apparently it depends on how the map is compiled, as my script relies on light entities still being present in the bsp file.

In either case, here are the scripts. Also a few screenshots: The first shows classic lightmap lighting, the second shows realtime lights with lightmaps completely disabled.

Activation script:

Code:
// Replace lightmap lighting with realtime lights

set r_shadow_realtime_world 1
set r_shadow_realtime_world_lightmaps 0
set r_shadow_realtime_world_importlightentitiesfrommap 2
set r_shadow_quakelightsizescale 1.5
set r_shadow_bouncegrid 1
r_editlights_reload

Deactivation script:

Code:
// Replace realtime lights with lightmap lighting

set r_shadow_realtime_world 1
set r_shadow_realtime_world_lightmaps 1
set r_shadow_realtime_world_importlightentitiesfrommap 1
set r_shadow_quakelightsizescale 1
set r_shadow_bouncegrid 0
r_editlights_reload

Before: http://pics.nexuizninjaz.com/images/qiw2gto14mg945js2xbu.jpg
After: http://pics.nexuizninjaz.com/images/imo75xla4ozpaqcd45y.jpg

Before: http://pics.nexuizninjaz.com/images/r9okjauftw9l2xlnn.jpg
After: http://pics.nexuizninjaz.com/images/ku7r2tijlfpd1kk5zc29.jpg

Again, this will only work on maps compiled with the _keeplights parameter, otherwise it will just make the world dark. So far this includes my maps Arboria and Old Steel Complex. Either way, try it out where it works and let me know what you think!


RE: [Script] Full realtime world lighting, using static light entities - MirceaKitsune - 03-21-2015

By the way, there is one more thing I should add: This script is only a workaround to achieving full realtime lighting with the current maps and settings! It is possible to do this in a much more optimal way... but it requires every Xonotic map to be recompiled. If the developers were to consider this as a feature, these are basically the steps that would have to be taken:

1 - Every map must be recompiled with the option to persist light entities in the bsp file, rather than q3bsp only using them to generate the light maps. This allows us to use the same light entities both to create the lightmap (q3map2) and to generate realtime lights (engine), whereas both modes should offer a similar appearance this way which is also important.

2 - Maps must stop distributing a rtlights file, and this file must be deleted. rtlights are used to place only a few dynamic lights in specific locations, and would be made obsolete by a full replacement of lightmaps with realtime lights.

3 - The cvar r_shadow_realtime_world_lightmaps must be defaulted to 0. This makes it so when you enable realtime world lighting, lightmaps are automatically turned off. Additionally we might want this to set mod_q3bsp_nolightmaps 1, so lightmaps aren't loaded into the memory for no reason.

4 - Lastly, add the option to the Effects menu. The three settings should be: "No world lighting", "Lightmap world lighting", "Realtime world lighting". The first disables lightmaps and doesn't enable realtime lighting either, which is the current effect if you uncheck "Lightmaps" in the Effects menu... some people prefer this as well.

This however needs to be a development decision. Currently Xonotic uses lightmaps at all times, and realtime lights are just an optional and additional detail. My suggestion would mean choosing either one or the other, not both at the same time. If the idea is approved however, I could easily implement it in a matter of hours and submit a pull request.


RE: [Script] Full realtime world lighting, using static light entities - Mr. Bougo - 03-22-2015

That looks pretty bad, how come it's so dark?


RE: [Script] Full realtime world lighting, using static light entities - MirceaKitsune - 03-22-2015

(03-22-2015, 02:47 PM)Mr. Bougo Wrote: That looks pretty bad, how come it's so dark?

Lightmaps also include bounce lighting, and the brightness is calculated based on different criteria. Although realtime lights support radiosity too (to my surprise), I need to tweak it better to achieve a closer result. surfaceparam lighting also doesn't currently work for realtime lights, so the lighting from sky textures is gone too.

Generally speaking though, it's darker because hardware lights are more exact and have a limited range. It will always be like this to some extent, but some people might find the price worth paying for the advantages.


RE: [Script] Full realtime world lighting, using static light entities - Lee_Stricklin - 03-23-2015

Seems like a pretty cool addition, can only imagine how it will look with some tweaking.