Skip to content

Implemented sub-functions for visual shaders

Chaosus requested to merge github/fork/Chaosus/vs_subfuncs into master

This commit adds the ability to define and call custom functions inside the VisualShader. This will signfically ease out writing the big shaders by giving the user way to define parts of them in separate functions and way to call them from standart Vertex/Fragment/Light and itself.

vs_new

So lets explain what this PR will do.

  • Added new button 'Add function...' on the top bar

image

  • When pressed - the new dialog will be popup

image

Here you can configure the function name, input ports and output type.

image

  • When you press "Create and open" your function will be opened for edit, and pushed to the graph list where you can easily get it. If you make any mistake at previous step and entered invalid func name or repeat the input name twise, the alert will popup.

image

The inputs are automatically created for user comfortability. ^^

  • When you finish to edit your function you can call it by using new 'Call' node located under the 'Special' tab

image

  • The Call node provide the updated list of the functions. When you change the selection, ports related to that function will be created.

image

  • If your function have multiple input ports and not all of them are used - the unused will be setted to its default values.

image

Note: The little pencil (Edit) button allows user to jump into the selected function.

  • You cannot use Call to invoke function itself cuz the recursion is not allowed.

image

  • The Remove Function button provide the way to remove the function - your undo history will be wipe out, to prevent connection errors. Every Call node in all functions including main (vertex/fragment/light), will be checked up and if its calling the removed function they will be pointed to [None].

Note: This button is visible only when the custom function is selected - the vertex/fragment/light is obviously cannot be removed

image

Note: The order of function is important since you cannot call the function located below the caller. There should be a way to lift up and down them, but at this time I pretty tired, and need to rest (will release it later as separate PR).

Note: There also no way to add/remove/change inputs other than directly edit visual shader file. Also delayed for separate PR..

I spended several days to create this submission - I changed and added many internal visual shader functions for help me make it possible, I tested them as much as I can. I think there is no critical bugs which may make the engine crash.. still - If the other contributors could test this PR - that would be pretty good !

Exposed classes/methods:

  • VisualShaderNodeCall
  • bool VisualShaderGroupBase->is_resizable
  • bool VisualShaderGroupBase->is_editable

Merge request reports