Jump to content
EN
Play

Forum

Shadows optimization


 Share

Recommended Posts

I have a suggestion on how to optimize this graphics setting:
In-game settings > Graphics > Deep shadows
 
When I enable it my fps drops from 60 to 40 even when I'm alone in a medium sized map. This means the game keeps drawing all the shadows over and over every single frame which is really unnecessary because all of these shadows remain unchanged unless a tank drives by or a supply box drops. The idea is to save the textures with shadows and re-use them instead of re-drawing them every time, and to decrease memory usage avoid saving the same texture with the same shadow twice (to re-use - for example - the same image with shadow for all cliffs that are not at a corner)

Algorithm:
 
Let props be an indexed collection of all props in the map.
Each object in props has a boolean property hasDeepShadow and an image reference defaultShadowTexture.
 
Part 1: when the battle is loaded with deep shadows enabled / when the player enables deep shadows in the middle of a battle:

  • FOR (i = 0; i < props.length; i++)
    • Set props.hasDeepShadow to indicate whether the prop has a deep shadow on it (if there are props next to it that should cast a deep shadow effect on it)
    • IF (props.hasDeepShadow == true)​
      • FOR (j = 0; j < i; j++)   IF(props[j].hasDeepShadow == true)
        • If props and props[j] have the same texture, and adjacent props that would cast the same shadow:
          • props.defaultShadowTexture = props[j].defaultShadowTexture 
      • IF (props.defaultShadowTexture == null)
        • Draw an image of this prop's texture with the deep shadows effect applied on it, and assign props.defaultShadowTexture to reference to this image

 

Part 2: do for each prop while drawing the next frame:

  • IF (hasDeeepShadow)
    • If a player or a supply box is in range (close enough to cast a shadow on this prop) :
      • re-draw the shadow the way it is done now 
    • Otherwise:
      • Use defaultShadowTexture instead of re-drawing the same shadow from scratch
  • Otherwise: use the prop's original texture

This involves saving lots of images in memory which might be a problem in big maps. I suggest testing this to see how much memory it takes and if it's too much then enable this optimization only in maps that are small enough.

 

Similar logic can also be used in Dynamic shadows, just make sure you re-draw ONLY what needs to be re-drawn, and obviously store only a maximum of one image per prop with all shadow effects applied on the same image.

  • Like 4

Share this post


Link to post
Share on other sites

Under Review

 

Remark: maybe it also interworks with that ambient lightning, caused by flags and shots. IDK, as I have it turned off all the time.

That's not a problem, the current rendering of effects will take place any time there is an object close enough to interact with the shadows. In the algorithm I only mentioned objects that cast shadow because I'm not familiar with the game's code, tanki devs should know what to do, it's not a problem to make the current effect rendering kick in around light sources too.

Share this post


Link to post
Share on other sites

I know, but the efficiency of your caching proposal goes down, the more objects interact with the environment. There are only a couple of tanks and they move relatively slow through the environment. There are even less boxes, and they move even slower then tanks ;)

But a lot of fast traveling shots (at least the vosible ones, from Twins, Rico, Striker and Rail.. and maybe some other which I forgot).

 

Still I think that your proposal is a good one.

Share this post


Link to post
Share on other sites

All shadows in Tanki are dynamic. It makes me wonder if a system for compiling maps with pre-rendered shadows was not an option given Tanki's engine.

Share this post


Link to post
Share on other sites

All shadows in Tanki are dynamic. It makes me wonder if a system for compiling maps with pre-rendered shadows was not an option given Tanki's engine.

The creators of tanki are also the creators of the game engine that tanki runs on, so every little detail is up to them except some Flash limitations.

  • Like 1

Share this post


Link to post
Share on other sites

I feel this is a good topic to bring up again now that HTML5 is here. Pre-calculating lighting information would be a great way to improve graphics without sacrificing performance.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...