domenica 27 dicembre 2015

Day 107: Multiple shaders!

Finally I managed to complete the automatization of the batch for geometry shaders. It shouldn't take that much to completely remove the other batches, and make a single, general purpose batch to handle multiple shaders of multiple types.

Today I started by adding the concept of a "global uniform", which is a uniform tht has the same value for all the instances. For example, in a single frame, every model has the same uniform for the camera matrix, so the info can be stored in the shader instead of the material. The global uniforms must be declared as "g_Name", so the system can recognized them, and must be set through the shader instead of the material.

Then I made a switch to send uniforms to the shader according to the type. This was the last step to have an "abstract" batch. So I created a second geometry shader, and the batch take care of them both. The DeferredRenderer class doesn't have a geometry shader, but simply call the render function on the batch. And it also send the same uniforms to all the shaders in that batch (namely the camera matrices).

Ideally the lighting shader will do the same, but send different uniforms.

The system will be hable to handle whatever shader, the only requirement is that the uniforms used by the deferred renderer class are present.

In the picture, the bottom right emitter has a different shader for the particles material. It takes another uniform (the time), and the resulting color is white multiplied by the sin of the time, to give a "pulsating" effect. This could be emulated with the particle material itself, but the difference behind it is substantial.

This also works with different attributes (and in different numbers)


Nessun commento:

Posta un commento