Jump to content


Photo

Making better use of light caching

engine renderer opengl light lighting shadows feature improvement fps performance

  • Please log in to reply
12 replies to this topic

#1 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 736 posts

Posted 14 October 2016 - 09:47 AM

I recently saw a post about the functionality of the idTech 6 engine, which brought this suggestion to my attention. It's actually a simple and trivial improvement, although I can imagine people missing it and not thinking about its absence. Also keep in mind I don't know the lighting code of TDM, and everything I say is purely out of observation.

 

Like most engines that use dynamic lighting, TDM tends to have considerable performance issues when a lot of lights are rendered at once. This is often because of shadows and possibly other calculations. A common way to prevent extra computation in the renderer is caching all lights, and only updating each one when necessary. Meaning either the light itself has moved, or something is moving in front of the light. If both the light and the geometry it affects are static, there is nothing to recalculate, which offers a significant performance boost.

 

TDM has a serious problem here: Even if the engine already knows how to cache lights, every torch has a moving light source! If you look closely at a torch, you'll notice its shadows constantly bob around. While this makes sense aesthetically, it also means that light will be recalculated each frame... even if the torch is mounted on a wall and no physical object or NPC is currently moving within its radius. Since most maps use torches and have areas where characters don't walk in front of them, I see a notable performance improvement being lost here.

 

My personal suggestion: First of all, does idTech 4 support light caching for static lights + geometry to begin with? If somehow the original engine didn't have that, I definitely think it should be patched in! Once that's solved, I believe moving light sources for flame based lights should be controlled by a cvar; If people are okay with the performance loss, they can enable that to get bobbing shadows... if not, disable to allow torch lights to be cached and improve overall FPS.

 

An idea to compensate for the visual loss: Can't we use an animated light texture to simulate moving flames altogether, as well as pulsating brightness? The light bobbing looks pretty extreme anyway: In real life, candles have a smooth flame that casts a neat shadow, and shadows don't always move that chaotically even when it's a noisier flame like a campfire.


Edited by MirceaKitsune, 14 October 2016 - 09:49 AM.


#2 AluminumHaste

AluminumHaste

    Darkmod Contributor

  • Development Role
  • PipPipPipPipPip
  • 6306 posts

Posted 14 October 2016 - 10:24 AM

As far as I know, this is already done at dmap time, static lights are optimized.

Moveable light sources are the real killer.


I always assumed I'd taste like boot leather.

 

#3 conker

conker

    Member

  • Member
  • PipPip
  • 32 posts

Posted 14 October 2016 - 10:27 AM

 

I agree, moving light sources are Killers!


Edited by conker, 14 October 2016 - 10:28 AM.


#4 VanishedOne

VanishedOne

    Advanced Member

  • Member
  • PipPipPip
  • 1005 posts

Posted 14 October 2016 - 12:03 PM

light_torchflame_new01 actually has the note 'Light is steady for performance reasons' in its description. Presumably MirceaKitsune has in mind light sources like light_fireflames which have spawnargs related to oscillation (of the light centre, I think).


Some things I'm repeatedly thinking about...

- louder scream when you're dying


#5 New Horizon

New Horizon

    Mod hero

  • Active Developer
  • PipPipPipPipPip
  • 13902 posts

Posted 14 October 2016 - 12:24 PM

As far as I know, this is already done at dmap time, static lights are optimized.

Moveable light sources are the real killer.

 

Yes, it's the oscillating lights that kill performance.



#6 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 736 posts

Posted 14 October 2016 - 02:05 PM

light_torchflame_new01 actually has the note 'Light is steady for performance reasons' in its description. Presumably MirceaKitsune has in mind light sources like light_fireflames which have spawnargs related to oscillation (of the light centre, I think).

 

I didn't check the names specifically, but I am indeed referring to that oscillation. It's a nice effect, but if the light's origin moves all the time you can't make use of this important optimization.

 

As far as I know, this is already done at dmap time, static lights are optimized.

Moveable light sources are the real killer.

 

Couldn't movable light sources be cached in realtime somehow? As long as a candle is sitting still on a table, and of course nothing within the light's radius animates, this should theoretically be possible! Same for dropped torches (that have stopped rolling around) and even the player's lantern (as long as they're standing perfectly still).

 

But this might be less of a problem for starters, since most maps don't have a lot of movable lights from what I've seen (like candles). Most lights are torches mounted on walls, and not the type guards can pick up and run around with. If even those could be cached, the performance improvements might be huge! I assume what you mentioned only works for classic light entities though, not lights that are part of any entity definition (which would include all types of torches).



#7 New Horizon

New Horizon

    Mod hero

  • Active Developer
  • PipPipPipPipPip
  • 13902 posts

Posted 14 October 2016 - 02:17 PM

The oscillation technique was added by us so mappers could use them in specific situations where they wanted some added realism, but not for use all the time.

#8 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 736 posts

Posted 14 October 2016 - 02:54 PM

The oscillation technique was added by us so mappers could use them in specific situations where they wanted some added realism, but not for use all the time.

 

The problem is that as far as I'm aware, it's used by all of the torch entities. Radiant encourages mappers to go ahead and place those all the time, since they're the easiest solution... I attempted to make a map some time ago, and they were definitely the first and only option that jumped to my attention! So ultimately, maps end up using oscillating lights everywhere.

 

There might be a better solution however: Oscillation could be distance based instead. This could rely on a multiplier, ideally cvar controlled... which let's say is 1.0 when the player is 5 meters away or closer, 0.5 when they're 7.5 meters away, 0.0 when 10 meters away or farther. This gradually decreases oscillation, then makes sure that lights farther than 10 meters disable it entirely and can make use of caching! At that distance you probably don't notice it anyway, so this would maintain the effect while improving performance for large maps. Perhaps this solution is more worth considering?



#9 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1695 posts

Posted 14 October 2016 - 03:16 PM

This sounds pretty much like the LOD system for models, so maybe this could be made a part of that.


  • MirceaKitsune likes this

#10 VanishedOne

VanishedOne

    Advanced Member

  • Member
  • PipPipPip
  • 1005 posts

Posted 14 October 2016 - 04:48 PM

 

The problem is that as far as I'm aware, it's used by all of the torch entities.

light_torchflame has 'Light pulses but is static' in its description. Any torch that uses it (atdm:torch_gothic02_wall was the class I looked at) should be oscillation-free.


Some things I'm repeatedly thinking about...

- louder scream when you're dying


#11 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 736 posts

Posted 14 October 2016 - 05:05 PM

light_torchflame has 'Light pulses but is static' in its description. Any torch that uses it (atdm:torch_gothic02_wall was the class I looked at) should be oscillation-free.

 

Ah... I see. I didn't know of this difference until today... I'd imagine many mappers wouldn't either until being around for long enough. Maybe having a clearer distinction between the two can help, so mappers are aware and can be encouraged to use non-oscillating lights in most cases? I'm still curious about a few things however:

 

- Was light caching tested and working for torch entities that don't use oscillating lights, as well as electrical lamps? Or does it only work for the classic light entities, which there's pretty much no point to using in TDM nowadays?

 

- Would it be possible to cache movable light sources as well (like candles) as long as they aren't being moved? Since they can be repositioned by the player, I imagine dmap can't handle this kind of caching.

 

- What do the devs think about my LOD idea for oscillating lights? Could the effect be distance based, so even lights that use it can have a lighter performance decrease on larger maps?


Edited by MirceaKitsune, 14 October 2016 - 05:05 PM.


#12 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1695 posts

Posted 15 October 2016 - 04:29 AM

Regarding the use of oscillating lights I would suggest a small addendum to the description in DR: Currently, it is described as ""Creates moving shadows". Maybe, we could add a "Too many moving shadows might affect perfomance" or something like that. This way mappers would at least know, that the moving shadows may be bad for performance, even though they look more realistic.



#13 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 736 posts

Posted 15 October 2016 - 05:35 AM

Regarding the use of oscillating lights I would suggest a small addendum to the description in DR: Currently, it is described as ""Creates moving shadows". Maybe, we could add a "Too many moving shadows might affect perfomance" or something like that. This way mappers would at least know, that the moving shadows may be bad for performance, even though they look more realistic.

 

I'd advice a honest but technically understandable term for everyone in their descriptions. Something like: "Notice: Oscillating lights can't make use of light caching, and are more performance intensive than static lights".







Also tagged with one or more of these keywords: engine, renderer, opengl, light, lighting, shadows, feature, improvement, fps, performance

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users