Deferred Rendering Example

I’ve been experimenting a little bit with deferred rendering now that we have MRT support. Although it wasn’t a showstopper, but it’s a lot easier and performant with.

There’s a bunch of things to improve and fix, but it’s a start anyway.

TODO:

  • Attenuation is a bit simple and not exactly physically correct since linear + quadratic attenuation doesn’t work with light volumes
  • Fix culling + depth testing for volumes to avoid light leaking
  • Better light volume batching, they can’t be rendered in a single batch right now
  • Specular component for the light calculation
24 Likes

Looks great! Any plans of sharing some examples? :grin:

3 Likes

Of course! I’ve pushed it to a branch on my public-examples rep: https://github.com/Jhonnyg/my-public-defold-examples

But it’s not in a decent state yet so I wouldn’t use any of this in a game just yet, but if you want to see how it’s done atm take a look there :slight_smile:

5 Likes

Small update:

  • Added a simple specular component
  • Some minor performance improvements, like culling and depth testing

Here’s a video with 256 lights:

Down the line I’d like to merge this with a PBR pipeline, I think I have an example of that somewhere but right now I’d rather wait until @JCash new gltf model importer has been merged so I can access the tangents without having custom buffers :slight_smile: There’s a PR for that in the works so it should be available soon, can’t wait!

14 Likes

These are exciting times for Defold!

6 Likes

Looks amazing! 256 light sources! :heart_eyes:

What resolution without lags in the browser on an average system can be?

Well, now I’m not sure that my experiments with slow forward shading so relevant :sweat_smile:.

5 Likes

There’s at least one PR that needs to be merged before we can enable MRTs on webgl I think :slight_smile: but I don’t have a good idea, it really depends on your needs. Bigger light volumes will take more power since more fragments are rendered, you’ll have to test and see :slight_smile: there’s more optimization I need to look at, all lights are separate draw calls for example. And you could always turn off lights far away in game code

6 Likes

Wow it’s indeed very exciting! Thank you for sharing Jhonny! :heart: I’m itching to make something in 3D more and more! :sweat_smile:

5 Likes

As a Defold user who’s not dipping too deep into shaders and other more complex graphic manipulation it’s wonderful to see videos like this to see what might be possible to do in the future with Defold.

It would be great, for people like me, to learn what practical applications improvements like this might have in my game.

In this case, having read up on “deferred rendering” it seems effectively rendered multiple light sources is the goal. This is especially exciting, because I’ve been toying with the idea to add a “night mode” to a 3D racing game I’m dabbling with in my spare time. I haven’t yet come up with a good way to illuminate the scene with streetlights or other points of light around the scene.

In short, this looks amazing! :fire::fire::fire:

6 Likes