Godot PR - CAMERA_VISIBLE_LAYERS

I made my first engine contribution to Godot.

I was trying to make a game prototype with multiple viewports and with multiple cameras representing different view-modes (like normal vs thermal) so they overlapped.

And as of Godot 4.1 its officially included in the engine! The pull request is here

img

There are already tools built into Godot to facilitate rendering masks, so that actors were only visible to certain cameras depending on their mask. However, I wanted all actors to be visible to both cameras, I just wanted to change the material for the different cameras. I wanted the thermal camera to render the actor with a different texture than the normal one. And I wanted both cameras to be active at the same time.

This could be solved with the render-masking tool provided. I would just have two versions of the actor inhabiting the same space. This, however, would be an abysmal development workflow, making sure they were always coordinated.

Instead, I decided to modify the engine to pass the current-camera’s render mask as a shader uniform. It was actually pretty easy! Godot’s codebase has a lot of abstraction that I’ve barely even scratched the surface of, but I was able to understand it enough to make this change.

I got to experience the full pull-request flow, from making a proposal, doing a pitch in the weekly contributor’s meeting, and then finally getting it integrated.

In the demonstration image, The top viewport is a camera with an all-encompassing view mask, the bottom right renders only layer 1, and bottom left only renders layer 2.

The shader is then able to switch what color is output depending on that layer mask.

Written on October 1, 2022