Can I write a shader that lets the user set the render_mode flags?

Godot Version

4.2.1

Question

I’m writing a custom shader. It would be nice if I could provide a way for the user to set flags related to blending and transparency, but it seems like the only way I can do this is write several variations of the same shader with different flags for each one.

It would be nice to have behavior like what you get with the StandardMaterial3D material which ets you do this. I presume it is generating it’s own shader code behind the scenes based on the parameters the user sets.

Maybe an easier thing to ask can you change a render flag dynamically in the shader? If yes, one comberson way would be to create a union that exposes an enums to which is checked by a function before executing the rest of the shader.

Not at the moment, there is a proposal for it.

What you can do is to write a custom material type, that select one of the shader variants depending on a toggle you set.