Tag Archives: shaders

New Vulkan example: Deferred shading and shadows

Based on the recently updated deferred shading example, I have added a new example to my open source C++ Vulkan samples. This example adds dynamic shadows from multiple light sources, showcasing a few technologies that can be used to make rendering of multiple shadows more efficient. To achieve this, the example uses a layered depth attachment with one layer per light source that is sampled in the final scene composition. Traditionally one would do multiple passes to render the depth maps for the scene's light source, and to avoid this the example also uses shader instancing by doing multiple invocations in the geometry shader. The geometry shader then uses the invocation index to output into the different layers of the depth attachment, with the matrices from the different point-of-views of the light sources getting passed as an array. This is an approach that fits modern GPUs very well and allows for an arbitrary number of shadow casting light sources to be added without the need to add multiple render passes. https://www.youtube.com/watch?v=8rNl4A0qGao  

Omni-directional lights using cubemap shadows

It looks like my dungeon crawler prototype isn’t actually evolving into a game, but much more into a personal testbed for more-or-less current rendering techniques (due to Projekt “W” I’ve been lacking in the field of recent rendering techniques a bit). And so one of the things I always wanted to implement were shadows for omni-directional light sources. I’ve been doing that with stencil shadows years ago, but stencil shadows aren’t the preferred way of doing this nowadays due to their limitations, including sharp edges (yes, there are ways to get around this, but they’re expensive in terms of computing) and a high demand for fillrate.

And I’ve also done shadow mapping some time ago, but back then only for a spotlight, and that’s pretty easy (basically it’s just a way of projecting something onto the scene). But omni-directional lights are a step further and It took me some time to get them to work. One of the hardest things holding me back were troubles using depth cubemaps in my shader. So now I’m using a normal cubemap (RGBA) for the light source and each face stores a custom calculated depth value (done in a separate shader) that’s then used in the final calculation to apply shadows to the scene (done in the same shader that does lighting and parallax mapping).