+2 votes

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.

in Engine by (204 points)

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: https://github.com/godotengine/godot/issues

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 :p

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! : )

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.