Viktor Pramberg Game Programmer

DeviceRGB

A plugin for UE4 that allows developers to control RGB devices from various manufacturers using materials.

April 15, 2019

DeviceRGB is a plugin I wrote for UE4 over a couple weeks. It allows the user to control RGB devices from different manufacturers using materials. It has a layer system, and allows the user to mask what LEDs use some material. There is also a simple interface to add support for new manufacturers, if desired. If you want to see the code, it is available on GitHub.

How it works

The idea was to make it extremely easy to make advanced effects, and since modern RGB devices are basically just very low resolution displays, I thought it would make sense to use materials to modify the LEDs. On a high level, the way I do that is by generating what are essentially UVs based on the LEDs location on a device and cache that on startup. Additionally, an index buffer is generated, that can be used to isolate certain LEDs/keys to some material. In the video above, WASD is in the index buffer, for example.

These two buffers are uploaded to the GPU, to be accessed by a custom compute shader. For each layer I dispatch the compute shader, using the index buffer to only access the LEDs that should be modified. After that, the output buffer is read back on the CPU, and sent to each manufacturer’s API’s to actually set the colors.

Why use compute shaders?

One could argue that using compute shaders for this is overkill, and I’d agree. There aren’t enough LEDs to warrant the extra complexity of sending data back and forth between the CPU and GPU. The reasonable solution is likely just to perform these animations on the CPU. The main reason for using compute shaders is that they enable using the material graph right out of the box, nice and simple. It also gave me a reason to learn more about extending the rendering pipeline, and using the Render Dependency Graph.

Render Dependency Graph

The RDG is used by Unreal to manage render resources, and it makes it fairly easy to add your own passes using the FRDGBuilder. A full walkthrough of RDG is way beyond this article, but the best resource I found was Epic’s RDG 101 presentation, or looking at the existing code in the engine. I found the Color Correct Regions plugin to be helpful. I hope DeviceRGB is a helpful reference too!

Thoughts

I am very happy with this plugin. I learned a lot, and got a lot of experience with new technical features in Unreal, in addition to the fact that I got the plugin to work exactly the way I wanted it to. Of course, it’s not perfect yet. The biggest issue is that supporting multiple manufacturers is difficult since they all do things differently, something that makes the per-key masking very challenging.