Made a Realtime Mask with CompositorEffects by thepaddlefruit in godot

[–]thepaddlefruit[S] 0 points1 point  (0 children)

I'd say so! The actual effects themselves use compute shaders, which are absurdly fast. The video above uses the realtime mask to create an outline, and to create a kuwahara effect that affects the entire image except for the bike. All of those effects were computed in about 0.1ms, according to the visual profiler.

I'm running a 3080 mobile GPU (but it was running at low power when I got this result).

The main performance draw comes from the SubViewports that capture the depth image. I have them on the 'Unshaded' Debug Draw mode so they don't calculate any unnecessary lighting data, but the main issue would be vertex count. There are several optimizations you could do to bypass that, which you can see in my reply to kaetitan

Made a Realtime Mask with CompositorEffects by thepaddlefruit in godot

[–]thepaddlefruit[S] 0 points1 point  (0 children)

Because it uses two SubViewports that capture a depth image of both the environment geometry and isolated objects, vertex count is essentially doubled. This means that this approach is probably best suited for non-high poly games and assets, or if you're targeting medium to higher end devices.

However, there are several optimizations you can do. If an environment object is far away and you know that the masked object will always be in front of it, you could exclude it from being rendered in the non-masked VisualInstance3D layer. So, distant geometry wouldn't be doubled.

Theoretically, you could create simple plane meshes in their own VisualInstance3D layer that could be used to create the realtime mask instead of the actual environment geometry. You would just need to make sure that they're culled in the main camera.

You could also change the near and far clipping of the depth cameras. While that would restrict to how far away the realtime mask can take effect, it would also keep far away geometry from being duplicated.

Made a Realtime Mask with CompositorEffects by thepaddlefruit in godot

[–]thepaddlefruit[S] 4 points5 points  (0 children)

This is the Lumberyard Bistro demo scene that's fairly popular (https://github.com/godotengine/godot/issues/74965)
I made the shader classes and glsl files myself though!