godot icon indicating copy to clipboard operation
godot copied to clipboard

Add a material preview to visual shader editor

Open Chaosus opened this issue 1 year ago • 11 comments

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).

visual_shader_preview

Previews will also use these parameter values to updates its look (rather than gather them from a scene):

visual_shader_preview2

  • Closes https://github.com/godotengine/godot/issues/55575

Chaosus avatar Jul 11 '24 13:07 Chaosus

@Calinou Check again, I think I've fixed all your remarks.

Chaosus avatar Jul 15 '24 19:07 Chaosus

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:

image

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:

image

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:

image

Calinou avatar Jul 15 '24 22:07 Calinou

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

изображение

Chaosus avatar Jul 16 '24 08:07 Chaosus

Documentation should be added for the newly exposed methods in the class reference.

Done

Chaosus avatar Jul 16 '24 18:07 Chaosus

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".

KoBeWi avatar Jul 24 '24 18:07 KoBeWi

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.

QbieShay avatar Jul 25 '24 09:07 QbieShay

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.

Chaosus avatar Jul 25 '24 10:07 Chaosus

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.

KoBeWi avatar Jul 25 '24 11:07 KoBeWi

I think preview params should be ignored at export-time to avoid needles texture loading when loading a shader

QbieShay avatar Jul 25 '24 12:07 QbieShay

That requires a custom ExportPlugin for VisualShaders, but it's doable.

KoBeWi avatar Jul 25 '24 12:07 KoBeWi

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.

Chaosus avatar Aug 16 '24 17:08 Chaosus

Thanks!

akien-mga avatar Aug 26 '24 21:08 akien-mga