Create an account


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

#1
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/qiw2...js2xbu.jpg
After: http://pics.nexuizninjaz.com/images/imo7...qcd45y.jpg

Before: http://pics.nexuizninjaz.com/images/r9ok...l2xlnn.jpg
After: http://pics.nexuizninjaz.com/images/ku7r...k5zc29.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!
<spackObot> Congratulations to Samual and Taoki, your lovescore is 98.463%!
Samual (~dioteckte@...) quit #xonotic.pickup (gonna kill myself now)
Reply

#2
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.
<spackObot> Congratulations to Samual and Taoki, your lovescore is 98.463%!
Samual (~dioteckte@...) quit #xonotic.pickup (gonna kill myself now)
Reply

#3
That looks pretty bad, how come it's so dark?
[Image:http://i.imgur.com/4XODR.png]640K ought to be enough for anybody.
     ― Linux Torvalds
Reply

#4
(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.
<spackObot> Congratulations to Samual and Taoki, your lovescore is 98.463%!
Samual (~dioteckte@...) quit #xonotic.pickup (gonna kill myself now)
Reply

#5
Seems like a pretty cool addition, can only imagine how it will look with some tweaking.
ECKZBAWKZ HUGE LIST OF ACHIEVEMENTS GOES HERE....


Oh wait.
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
Brick A script engine written in QuakeC Melanosuchus 9 6,826 10-14-2014, 02:01 AM
Last Post: Melanosuchus
  entities - damage if func_pointparticles It'sMe 4 2,865 07-11-2013, 10:04 AM
Last Post: aa
  Physical entities test (ODE) MirceaKitsune 27 18,430 10-10-2012, 05:48 AM
Last Post: MirceaKitsune
  More Engine Suggestions - Different Lighting Handling master[mind] 13 10,063 04-04-2011, 09:36 AM
Last Post: Morphed
  [solved] 'all' script problems xeros 4 3,485 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-