AXEL FRANZÉN

GRAPHICS & ENGINE PROGRAMMER

DECAL RENDERING

Since our main rendering pipeline is deferred, the implementation of deferred decals that could read information from the gbuffer was relatively simple, but there were a few things that I wanted to fix.

A problem that stood out to me was that when the direction of the decal projection got too close to being parallel with the surface it projected on it would create this ugly smear effect that is a result of the pixels of the parallel surface all using the same texture coordinates.

There are surely more elegant ways to fix this problem but the way I solved it was to take the dot product of the pixels world normal and the decals projection direction, and discard that pixel if the value was too close to 1.

RENDERING LAYERS


Another problem with the decals was that they could affect dynamic objects like the player or enemies if they were to walk into the projection area, which wasn’t ideal.

To fix this I added the option for objects to define what rendering layer they belong to. By setting an unsigned integer through bitmasking I could decide that the players mesh should have a certain value, and by writing this value to another gbuffer texture the decals can then sample this gbuffer texture and discard pixels based on the bitmask value.

The rendering layer bitmask enum. Through the use of bitmasking, a mesh can choose one or multiple layers that it should belong to.

A capture of what the gbuffer texture could look like. In this case the character is part of both the Player-layer and the NotAffectedByDecals-layer and therefore all pixels of the mesh have been saved to the texture with a value of 20 in the red channel (In reality the whole texture is red, but since the colors can’t be visualized past a value of 1 they have been normalized, hence why only the player character is visible here).

This is how the decal shader utilizes the RenderLayer gbuffer texture to discard pixels that are part of the NotAffectedByDecals-layer.

Lights can also use this rendering layer to control what layers they want to cast light onto or if shadows should not be cast for certain layers. I added this because our player character has a chest-mounted flashlight and this was a problem since the character’s arms often comes in the way of the lightbeam, so while it may not be very realistic I made the flashlight ignore the player mesh for gameplay reasons.