Add a material preview to visual shader editor
This PR adds a new panel with a material preview to visual shader. You can control the parameters applied to that preview (they are saved within a shader).
Previews will also use these parameter values to updates its look (rather than gather them from a scene):
- Closes https://github.com/godotengine/godot/issues/55575
@Calinou Check again, I think I've fixed all your remarks.
The preview gets cut off if the editor window isn't wide enough, due to the minimum width for the visual shader editor becoming much greater:
For instance, in a 1600×900 editor window, it's not possible to have the shader preview display fully unless you enable distraction-free mode to hide the docks:
I suggest making the visual shader toolbar use an HFlowContainer so it can rearrange items on several rows if there isn't enough width. We use this in the 2D/3D editor toolbars already:
@Calinou Okay, I think I've managed to make it without breaking the compatibility in GraphEdit. Check again - I think it's good now, the only downside I cannot fix is the toolbar panel will now be expanded to a graph size:
Documentation should be added for the newly exposed methods in the class reference.
Done
Saving preview parameters in the shader sounds questionable to me tbh, but the worse part is that you can't remove them. I tried clearing a texture parameter and it's still stored, as preview_params/tex_frg_2 = "null".
I have a feedback on the parameter setting for preview: I think it'd be really nice if we can pick a material that's open in the open scene as an option, and thus making also the nodes preview work with the input of that material.
EDIT: this can definitely come in a future PR, just noting it down to make sure the code can support it in the future without big refactors.
Saving preview parameters in the shader sounds questionable to me tbh, but the worse part is that you can't remove them. I tried clearing a texture parameter and it's still stored, as preview_params/tex_frg_2 = "null".
It should be automatically removed when you disconnect the parameter from the output and resave a shader.
It should be automatically removed when you disconnect the parameter from the output and resave a shader.
Yeah except it's the only way to remove it. When I add a texture parameter, it's not saved in the shader. But once I assign it, the only way to remove it is by disconnecting as you said. It's rather cumbersome.
Then again, an extra property is harmless and I don't use VisualShaders anyway, so if fixing is problem you can leave it as is.
I think preview params should be ignored at export-time to avoid needles texture loading when loading a shader
That requires a custom ExportPlugin for VisualShaders, but it's doable.
I think preview params should be ignored at export-time to avoid needles texture loading when loading a shader
Done. New methods wrapped by TOOLS_ENABLED macro and added check by Engine::is_editor_hint function.
Thanks!