Wednesday 1 December 2010

Bye, bye Pre-Pass lighting

I have an announcement to make.

I am dumping pre-pass lighting.

A couple of weeks ago I started to remaking the renderer from a deferred shader to a pre-pass lighting one. Directly after implementing it, I wrote this post. At first, pre-pass lighting sounded great: faster light rendering and more variation in materials. Having seen that companies such as Crytek and Insomniac Games used it, I thought it would be the next logical step to take.

However, even as implemented it, the problems began. The first one was that specular lighting has to be made through hacks or something that makes it closer to deferred lighting. The next was that implementation become more messy. I suddenly needed to redraw all objects in two separate passes and this made the material and shader code harder to maintain. Normal deferred shading has this nice design where all material info is rendered in one pass to one buffer. But in pre-pass lighting, this spread out and makes more annoying to add new stuff and to update existing.

Still, I stuck to it, because I was sure that the speed and material variety would make up for it. One of the features I was looking forward to was making more interesting decals, with normals and such. Since only the light data is written to an accumulation buffer I thought this would allow me to easily put more effects to the decals. However, I quickly realized that I had been quite foolish and not considered that pretty much every interesting part of a materials is added when lighting it. The surface normals, specular, etc are all baked into the light data. So I ended up doing tricks that I could actually work with normal deferred shading.

So what ended up with was lighting of worse quality, compared deferred shading, and with no more room for special effects. Still, this rendering is much faster right? Well, I did some checks which I collected in this post. It turns out that pre-pass is actually slower unless in very specific situations. None of the improvements I was hoping for turned out to be true.

Still, I stuck to it. I am not sure why, but I guess I did not want to face the truth after having put so much time and effort into it. Going back to the old renderer was something I did not want to consider.

Then last week, as I was starting making undergrowth for the terrain, it suddenly happened. I realized that I had to render the vegetation twice, creating more overdraw and making it a lot more cumbersome to implement. At this point I decided that I should seriously consider going back to the old deferred renderer. What I was most worried about about was that it would exclude us from consoles, but I found out that games like Burnout Paradise used a deferred shader too, and assuring me that consoles would still be possible to do.

This post by Adrian Stone, with an in-depth discussion on the subject, sealed the deal for me and I got to work with going back to deferred shading. I had actually come across Adrian's post before when implemented pre-pass lighting, but never read it carefully. I guess it would not had made me stop then since I wanted to check it out myself, but it is interesting to see how one can convince oneself that something is correct, to the point of avoid contradictory sources. This is a very important lesson to learn and one should always be prepared to reconsider and "kill your darlings".

Right now I have fully implemented the deferred shader again and even updated it a bit too. For one thing, I fixed so the decals support all the feature I had in the pre-pass lighting shader. Since we are aiming for a little higher specs (shader model 3 or 4) for our next game, I took that into account and was able to add some other fun stuff. Examples are colored specular and saving the emission in the g-buffer (allowing to cheaply to a variety of effects).

I am really happy to back to the old renderer and now that I am adding new features things are going a lot smoother. The pre-pass renderer was not all in vain though. I cleaned up the rendering code a lot and it also made me rethink how some features could be added. Last but not least, it also reminded me that I should never get too attached to an idea.

13 comments:

  1. Well, as they say, there's no victory without sacrifice... Might as well make the best of it, though I really like how you're experimenting with possible new lighting and shading thingies. :-)

    ReplyDelete
  2. Too bad so much work was wasted. But nice that you had the courage to revert it all. :)

    ReplyDelete
  3. Interresting post since I want to try to change for deferred shading to light-prepass actually, but what about MSAA and SPU lighting made possible with light-prepass renderer?

    ReplyDelete
  4. "What I was most worried about about was that it would exclude us from consoles...assuring me that consoles would still be possible to do."

    Possible console release for the next game? Sweet, my laptop is really old and banged up. I had to run Amnesia real slow.
    How likely is it that a console release is going to happen?

    ReplyDelete
  5. benualdo:
    When it comes to msaa, then you get problems with pre-pass too. Michael Nischt, posted these shots in a the first pre-pass post:
    http://micha.monoid.net/stuffu/pre-light/0_samples.png
    http://micha.monoid.net/stuffu/pre-light/8_samples_nearest.png
    http://micha.monoid.net/stuffu/pre-light/8_samples_centroid_linear.png
    Check near the "trees" to see the artifacts you get.
    With deferred shading you could render the diffuse channel in sepperate pass to a mssa surface and you similar to pre-pass result.

    SPU is something I do not know that much about, so do not wanna comment. In Adrian Stone's post there are some disccusion in this in the comments though.

    ReplyDelete
  6. Andrew:
    Cannot give any chances right now. We are looking into, but there are many obstacles to overcome (technical, design, financial, publisher, etc)

    ReplyDelete
  7. There is never progress without sacrifice. You know what you're doing, and a solution seems to be in sight. Pre pass has it's problems too, so it's for the better to get rid of it in my opinion.

    ReplyDelete
  8. Glad you recognized a bad idea and stopped working on it instead of marching along thoughtlessly.

    ReplyDelete
  9. please do a console release. not for me, but for my friends. amnesia would have worked brilliantly on ps3's move controllers, and its a damn shame that only pc gamers have the chance to play the game. i'm not sure how well the kinect would work, personally i like buttons, but who knows.

    ReplyDelete
  10. @Thomas: Ah yes, it'd be a shame if no one took it on. But hopefully a game such as yours with a dedicated fan base, doing something innovative and getting the player reviews that it does would hopefully find a publisher. Best of luck to you guys.

    ReplyDelete
  11. As has been said, making a mistake doesn't necessarily have to be all bad. Now that you have ruled out pre-pass lightning, you can focus more whole-heartedly on the old system without distractions.

    ReplyDelete
  12. Good post to read, man. I will be sure to make sure we stay with the deferred stuff in grit engine and no one gets ideas about pre-pass :P

    ReplyDelete
  13. Thomas, I hope you get some notifications on comments - it would be great to hear how did you implement specular color and emissive in deferred shading. If you could give few hints - I'm planning on doing it in my own engine and I haven't found much information on this topic.
    Thanks!

    ReplyDelete

Note: only a member of this blog may post a comment.