How to Invert the Game Color using a PNG image as a transparent mask?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Corruptinator
:warning: Old Version Published before Godot 3 was released.

Hello! I have a question related to a game project I am currently working on, and it involves creating a 2D Black Hole as a weapon to quickly take out enemies.

The Black Hole has two layers of sprites (Both of them are PNG images BTW), one is the Event Horizon(A green overlaying barrier that surrounds the black hole), and the Void (Simply a large Black Circle behind the event horizon).

What I want to do is to take the Void and use it as a filter mask to make anything within the black void become inverted of color so then the black hole weapon stays unique and still make anything behind the black hole visible to the gameplay without sacrificing the view behind the black hole.

I can imagine that this is probably going to be done by material shading, and if so can it be done by both the Shader Script or the Shader Graph?

Any options are welcome, I prefer the Shading Node Graph because its less complicated than the Shader Script but if no other choice then I’ll consider doing shading script for this part.

What you are looking for is the reverse of the Subtract blending mode. In OpenGL, it is available as GL_FUNC_REVERSE_SUBTRACT, where pixels drawn before are subtracted from those you are drawing. If you draw white this way, you’ll get inverted colours. However, Godot doesn’t exposes this blend mode for some reason. You can ask here if you need it: Issues · godotengine/godot · GitHub

Without this blend mode available, I would do the complicated way, which is to render the whole scene without black holes in a RenderTexture, then draw it, and draw black holes over it with a shader that can access the scene’s pixels and “emulate” the blending by inverting colours. The screen reading shaders demo can be helpful for this technique.
But I would really prefer the OpenGL blend mode as it is simpler and efficient :stuck_out_tongue:

Zylann | 2016-07-04 00:52

Thanks for the Suggestion, I guess this is another feature that isn’t on the Godot Engine, I’ll ask on the Github Issue, THANKS! : )

Corruptinator | 2016-07-04 04:25

You might have better luck asking the Godot shader gurus over at the shader subforum on the Godot Developer’s Forum.

ericdl | 2016-07-06 13:14