Tiled Forward Shader

In our first blog post we will try to describe the lighting model that we use in our game!

The game:
We are currently developing a top down 3d game for a course called ”Advanced Computer Graphics” at our University. This game is an intense MOBA with loads of spells flying around – and we wanted our spells to emit light! So we thought of a way to do this efficiently on mobile devices!

We believe this approach is suited for pretty much all top down 3d games, possibly even 2d games that want to use normal-dependant shading.

The idea:
The idea is based on tiled forward shading, but as the usecase is a top down game we can avoid the prepass and just cull the light sources very simply and basic on the cpu so that only light sources that are affecting the environment are used for the shading. Because we do not need a prepass I believe this approach can be used with great success on mobile devices, and our tests show that this assumption is correct.

The source (which can be found further down) is somewhat documented, but if there are any unclarities we would love to try and answer your questions. Any suggestions for improvements are also welcome!

Performance:
Here’s a table over the maximum amount of lights we can support with 60(30) fps on the devices we have so far tested on.

Device:       Normal Shader      Our Shader
Galaxy s3     9(20)              17(38)
Galaxy s2     11(23)             19(45)
Nexus 4       X(22)              22(X)

From what we read/hear, fragment shaders are limited to a maximum amount of vec4 uniforms (i cant recall the results when I tested this myself..) and that is why the maximum supported light sources are 48 for our method (and 24 for the normal point light method, as that one needs to send radius and color in uniforms aswell.). We will work towards removing this cap in a later version by sending the positions aswell as the color and radius in the texture that now contains only the color and radius. We have not yet done this because it will require some testing (of how many channels are needed for each position float) to make sure that the precision is high enough. We suppose this will also depend on the size of the gameworld.

One important aspect to take into consideration when considering this technique is: the smaller part of the screen that each light affects, the more we benefit from this method!
Loads of small lights = use this!
Loads of superlarge lights = it might not matter too much which approach you pick.

We would love it if you guys would test the -> DEMO <- and provide some info about how well the shader performs on your device.

Source:
The source can be found -> HERE <- and contains all source for the desktop version of the demo, including shaders and assets.

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *

Följande HTML-taggar och attribut är tillåtna: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>