Tuesday, November 5, 2013

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 particular. Straight right after implementing it, I wrote this post. At 1st, pre-pass lighting sounded fantastic: quicker light rendering and much more variation in components. Possessing noticed that businesses such as Crytek and Insomniac Games utilised it, I believed it would be the subsequent logical step to take.

Even so, even as implemented it, the problems began. The very first one was that specular lighting has to be created by means of hacks or one thing that tends to make it closer to deferred lighting. The subsequent was that implementation become far more messy. I abruptly necessary to redraw all objects in two separate passes and this created the material and shader code tougher to sustain. Standard deferred shading has this good design and style exactly where all material info is rendered in one pass to one particular buffer. But in pre-pass lighting, this spread out and makes more annoying to add new stuff and to update current.

Nevertheless, I stuck to it, due to the fact I was certain that the speed and material assortment would make up for it. One of the attributes I was seeking forward to was creating much more fascinating decals, with normals and such. Because only the light data is written to an accumulation buffer I thought this would enable me to very easily place much more effects to the decals. However, I rapidly realized that I had been quite foolish and not considered that pretty much each and every exciting portion of a materials is added when lighting it. The surface normals, specular, and so forth are all baked into the light data. So I ended up undertaking tricks that I could really function with typical deferred shading.

So what ended up with was lighting of worse high quality, compared deferred shading, and with no far more space for specific effects. Nevertheless, this rendering is considerably faster correct? Properly, I did some checks which I collected in this post. It turns out that pre-pass is in fact slower unless in quite particular circumstances. None of the improvements I was hoping for turned out to be correct.

Nevertheless, I stuck to it. I am not positive why, but I guess I did not want to face the truth right after having place so considerably time and effort into it. Going back to the old renderer was one thing I did not want to think about.

Then final week, as I was starting creating undergrowth for the terrain, it suddenly occurred. I realized that I had to render the vegetation twice, making a lot more overdraw and generating it a lot much more cumbersome to implement. At this point I decided that I need to seriously take into account going back to the old deferred renderer. What I was most worried about about was that it would exclude us from consoles, but I located out that games like Burnout Paradise used a deferred shader as well, and assuring me that consoles would nonetheless be feasible to do.

This post by Adrian Stone, with an in-depth discussion on the subject, sealed the deal for me and I got to perform with going back to deferred shading. I had truly come across Adrian's post before when implemented pre-pass lighting, but by no means read it carefully. I guess it would not had created me quit then considering that I wanted to verify it out myself, but it is fascinating to see how one can convince oneself that something is correct, to the point of avoid contradictory sources. This is a really crucial lesson to learn and 1 need to usually be prepared to reconsider and "kill your darlings".

Correct now I have fully implemented the deferred shader once again and even updated it a bit also. For one particular factor, I fixed so the decals assistance all the feature I had in the pre-pass lighting shader. Considering that we are aiming for a tiny greater specs (shader model three or 4) for our subsequent game, I took that into account and was able to add some other entertaining stuff. Examples are colored specular and saving the emission in the g-buffer (enabling to cheaply to a selection of effects).

I am actually satisfied to back to the old renderer and now that I am adding new features items are going a lot smoother. The pre-pass renderer was not all in vain even though. I cleaned up the rendering code a lot and it also produced me rethink how some functions could be added. Final but not least, it also reminded me that I should by no means get too attached to an notion.

No comments:

Post a Comment