Graphics Update, V1.2

Discussion in 'Planetary Annihilation General Discussion' started by varrak, March 14, 2014.

  1. varrak

    varrak Official PA

    Messages:
    169
    Likes Received:
    1,237
    First off - let me make the disclaimer that this post refers to changes that will go live some time in the not-too-distant future. They're not out in the wild just yet. This is more of a "I had a busy week, but it was awesome, and now I want to share" post.

    A little while ago I noticed that a lot of our CPU-side performance was going to drawing lights. Huh. "Drawing lights". This might seem like an odd statement to the non-graphics programmers out there, so let me explain.

    The PA engine is a Deferred Rendering Engine. Wikipedia has a good reasonable article covering the basics here. Although it's very basic... but anyway. With deferred rendering, you render geometry once, and then you add lighting after the fact. The big advantage of deferred rendering is that you can add lots and lots of lights, and it's (relatively) cheap. To draw a light, in PA, we just render a box, or a capsule, or a sphere, using a special technique, and the shader used to render that geometry composes lighting into the scene.

    Anyway... back to the story. I noticed drawing lights was starting to cost us a lot of CPU performance. Since we're a deferred engine, our technical artist started adding more interesting stuff to the scene, in the form of lights. All buildings have lights on them now. The commanders have had headlights for a while (no shock there). Explosions have lights. The fog of war is rendered as lights. Fab spray effects spit out several lights, per spray. We have lots of lights. (I actually measured one game I played to have around 7500 lights, which is... a lot.)

    Anyway, when the engine was originally written we didn't have that many, so we drew them the easy way (one by one). This works great for a few dozen, or even for a few hundred. But for thousands? It adds up.

    So I got a bee in my bonnet last week about instancing the lights. When a really busy game is taking 20 millseconds to execute 7000 draw calls just for lights, you need to do something... so I made some changes so that we could batch the lights. So, those 7000 draw calls? Now it's more like 7. (Actually, it's exactly 7). Not bad. It also takes a lot less time. Bonus!

    That was a good start, but I noticed the framerate would still take a dive if I got close up to a massed army of several hundred units. After careful measurement, I realized in this case we were GPU bound (meaning the GPU was taking longer to perform work than the CPU). Oh dear... well, it turns out, all those units in a big mass, rendering fog-of-war lights? That was a lot of pixels getting written out, which even the beefiest GPU will start to struggle with. So that got me thinking... the fog of war is basically created as a full-screen stencil type thing that we composite over the scene. Do we really need to do that at full size? Also, notice how it's slightly blurry around the edges? Maybe we can use that...?

    Turns out, we can actually render the fog-of-war buffer at 1/16th resolution. That's 1/16th of the pixels. If you are running at 1920x1080 (for a total of 2 million pixels), we would only actually perform the operation on 130,000 of them.

    It makes things faster. It also has little to no impact visually. It's a win. And you'll be seeing that in a build coming your way soon (next week, with any luck).

    Anyway, I'm really excited about these latest changes. It should make a noticeable difference to almost everyone out there. :)
    Last edited: March 14, 2014
  2. SXX

    SXX Post Master General

    Messages:
    6,898
    Likes Received:
    1,811
    Thanks for another great post!

    I just wonder if there some "statistics for nerds" in client except one available with Ctrl+P? :oops:
  3. brianpurkiss

    brianpurkiss Post Master General

    Messages:
    7,879
    Likes Received:
    7,438
    Thanks for this! I really enjoy these graphics updates.

    I wish more of the devs would write things like this. :)
    LavaSnake, Remy561 and varrak like this.
  4. aevs

    aevs Post Master General

    Messages:
    1,051
    Likes Received:
    1,150
    Very interesting. Do you have any figures on the performance boost this allows?
    Also, will there be a feature to disable FoW visual queues? I hate seeing circles all over the map in spectator mode, for instance.
  5. varrak

    varrak Official PA

    Messages:
    169
    Likes Received:
    1,237
    I was hesitant to give figures, since it's going to vary from machine to machine, and we've not tested it widely in the office yet. I just played a game at home, and I stayed at 60fps most of the game. Experiments on a planet on my Geforce 660 at work gave 40+fps with ~600 units on-screen, up close.
  6. EdWood

    EdWood Active Member

    Messages:
    533
    Likes Received:
    147
    Keep it coming... :)
  7. varrak

    varrak Official PA

    Messages:
    169
    Likes Received:
    1,237
    Actually, I added light-count to the Ctrl+P stat screen; it shows how many API calls we make, and how many light instances.
  8. stormingkiwi

    stormingkiwi Post Master General

    Messages:
    3,266
    Likes Received:
    1,355
    So this is why there was lag when units moved around the map.

    Dayam.

    Can you render the fog-of-war buffer at even lower resolution then?
    varrak likes this.
  9. thetrophysystem

    thetrophysystem Post Master General

    Messages:
    7,050
    Likes Received:
    2,874
    I compliment you sir, you are a credit and valued asset to your team, you bring great honor to your lotus.
  10. Methlodis

    Methlodis Active Member

    Messages:
    198
    Likes Received:
    82
    For lower end machines will there be graphical options to reduce the resolution of fog of war even more? Maybe to 1/32? Just thinking of pushing the performance enhancements of low end machines.
    stormingkiwi, varrak and Martenus like this.
  11. liltbrockie

    liltbrockie Active Member

    Messages:
    314
    Likes Received:
    160
    Well done you superstar. I hope you're proud of yourself.
    varrak likes this.
  12. zweistein000

    zweistein000 Post Master General

    Messages:
    1,360
    Likes Received:
    727
    Hell yea. Any performance upgrade for this old machine is a good one. Thanks man.
  13. chronosoul

    chronosoul Well-Known Member

    Messages:
    941
    Likes Received:
    618
    Please, just start a blog. You and Bgolous have the best write ups by far.
    glinkot and vyolin like this.
  14. bgolus

    bgolus Uber Alumni

    Messages:
    1,481
    Likes Received:
    2,298
    Too many "o"s... :oops:
    vrishnak92 likes this.
  15. vyolin

    vyolin Well-Known Member

    Messages:
    631
    Likes Received:
    479
    Now you got a spare one, you lucky bastard!
    BulletMagnet, varrak and cptconundrum like this.
  16. pcnx

    pcnx New Member

    Messages:
    13
    Likes Received:
    12
    So did you draw each light in one deferred render call as in drawing x quads and applied the shader to each individual light?
  17. arm2thecore

    arm2thecore Active Member

    Messages:
    198
    Likes Received:
    132
    Good read. Thanks!
  18. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    Stuff like this is good, the more technical the better. Reminds me I should read some of the blogs more.
    varrak likes this.
  19. varrak

    varrak Official PA

    Messages:
    169
    Likes Received:
    1,237
    When you get much lower it starts falling apart (ie looking ugly). But there is certainly the potential to make this a user controllable option. Bear in mind, there's probably more we can do to make this even better, too...
  20. varrak

    varrak Official PA

    Messages:
    169
    Likes Received:
    1,237
    Pretty much, except we draw volumes not quads. Low res spheres, boxes and frusta. Now we group them by type, and dispatch while groups at one go. Much faster :)
    thelordofthenoobs likes this.

Share This Page