lunedì 13 novembre 2017

Day 200: Compute Shaders

I decided to embark in the challenge of implementing tiled deferred rendering. The task would not be too hard to be implemented from scratch, but the engine is growing big, and despite my efforts to keep the codebase clean, lots of care need to be taken when changing techniques drastically.
I decided to start from directional lights, as they don't require culling, so I would just need to focus on the implementation of a simple compute shader.
A major decision was keeping both deferred and tiled deferred rendering. The first for shadow-casting lights, the second for non-shadow-casting lights. This is because tiled deferred rendering would require to precalculate all the shadow maps and store them into an array. The trade-off might be worth it, but for now I prefer to just calculate the lighting into two different ways and reuse a single shadow map. Tomorrow I plan to wrap all the lighting logic into functions that will be shared by both shaders (the regular one and the new compute one), in order to avoid code duplication.
The compute shader itself gets its data from an SSBO filled with light structures. Unfortunately, the dynamic nature of the engine forces to refill it every frame.
In general there are some problems with the code, and I'd love to make it more clean, so tomorrow I'll probably focus on  polishing and refactoring.

In the picture, directional lighting obtained through the compute shader. The grid pattern its just a mask applied in the compute shader to show the blocks of threads.I opted for 32 x 32 to have 1024 parallel thread, which results in a good number of warps (thus hiding memory access latency). When culling will be a priority (i.e. spot lights) I'll use 16x16.


Nessun commento:

Posta un commento