Create an account

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Script] Full realtime world lighting, using static light entities

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:

// 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

Deactivation script:

// 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



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!

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.

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

(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.

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

Oh wait.

Possibly Related Threads…
Thread Author Replies Views Last Post
  VR script MirceaKitsune 2 2,642 10-16-2019, 05:48 PM
Last Post: MirceaKitsune
  using the Xolonium font TheGoodGamer 4 4,447 04-23-2016, 11:58 AM
Last Post: TheGoodGamer
Brick A script engine written in QuakeC Melanosuchus 9 12,691 10-14-2014, 02:01 AM
Last Post: Melanosuchus
  entities - damage if func_pointparticles It'sMe 4 4,979 07-11-2013, 10:04 AM
Last Post: aa
  [plan] A single-player game creation toolkit using the Xonotic framework MirceaKitsune 21 31,033 06-18-2013, 10:15 AM
Last Post: Zeo
  Physical entities test (ODE) MirceaKitsune 27 28,439 10-10-2012, 05:48 AM
Last Post: MirceaKitsune
  More Engine Suggestions - Different Lighting Handling master[mind] 13 15,990 04-04-2011, 09:36 AM
Last Post: Morphed
Information [MUST SEE!] Using Pirate Pad to democratically decide on ideas Samual 4 9,424 11-06-2010, 06:12 PM
Last Post: Rage_ATWM
  [solved] 'all' script problems xeros 4 5,429 10-16-2010, 03:37 PM
Last Post: xeros

Forum Jump:

Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-