martedì 14 novembre 2017

Day 201: Shader Preprocessor

Today I decided to refactor the code of the compute and regular shaders I'm using for directional lights. I immediately found out that OpenGL has no way to include header files, so I took some time to write my own preprocessor in order to achieve that.
It is now possible to start a shader with one (or more) of the following commands:

E(path)
G(path)

The first one loads a .glinc file (custom extension I'm using) with a path relative to the engine folder, the second relative to the game folder. The loading operation involves replacing the command with the actual code contained in the file.
With the preprocessor in action I managed to simplify tremendously both shaders, which now share most of the code in a "DirectionalLight" library, and also several things from a "Global" library, in which I'll put useful functions and UBOs that need to be shared by every shader.

This work led to a refactoring of the deferred renderer as well, and now the directional light code is simple, well organized and reusable. However, I found a very bad memory leak in the Material class, and in how it handles uniforms. I'll need to make a huge refactoring there, as I'm not happy at all with the amount of allocations it performs, as well as the fact that it is leaking.
Tomorrow if I've time I'll also start refactoring point and spot lights to do the same as the directional ones. The new shader preprocessor will make it very easy and clean to add culling, as it will be just a function at the beginning of the compute shader, while the light code is in the library.

Nessun commento:

Posta un commento