godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.13k stars 93 forks source link

Expose more OpenGL blend modes as shader `render_mode` #2621

Open ghsoares opened 3 years ago

ghsoares commented 3 years ago

Describe the project you are working on

Trying to experiment with some shader effects

Describe the problem or limitation you are having in your project

I'm trying to create a fire effect by taking a viewport that renders particles with radial gradient, procedurally calculate normal from this texture and use it as fake 3D effect in a canvas_item shader, this way it should look like multiple fire spheres overlapping each other. The problem is that I want to achieve a depth effect using max blend mode, but the current Godot's shader language API doesn't have this mode exposed

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Viewing the OpenGL Wiki page about blending (https://www.khronos.org/opengl/wiki/Blending), there's other blend modes like GL_MIN and GL_MAX, so my proposal is to expose these modes into the Godot's shader language.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I ain't sure how it's implemented in the rasterizer and in the shader language, but it seens not too hard to expose/add those modes.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not possible, it requires modification in the engine rendering core.

Is there a reason why this should be core and not an add-on in the asset library?

Because it requires modification in the engine rendering core.

Calinou commented 3 years ago

Does OpenGL ES 3.0 (and ideally 2.0) expose these blending modes? If not, they'll have to be emulated in a shader, which is slower.

ghsoares commented 3 years ago

@Calinou OpenGL ES 3.0 does have trough the glBlendEquation https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glBlendEquation.xhtml, but version 2.0 don't have min and max blend modes https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glBlendEquation.xml