Uniform Nodes + Python API
Due to the way nodes in Blender currently work, it is quite difficult to make a Python script that would allow efficient control of node materials in real-time. When trying to pass custom data to a node material, you often end up having to change values that are constants in underlying shader code. As such, changing these values requires recompiling a part of the node material each frame you modify them. With more complex materials this can lead to significant performance issues. This also affects animating certain values in nodes, which can lead to a sub-par playback speeds in viewport.
What I am proposing is to add a way to pass uniform values into nodes. These are values that one could supply to the shader code externally and easily change without requiring the code to be recompiled.
Here's my idea of how this could potentially work:
-
Uniforms are stored within a given
NodeTree. -
In nodes interface you can configure them in the right panel (N panel) under a new
Uniforms
tab, which consists of a basic
UIList, and for each selected element below you can select uniform type from an enum (likelyVector,Color,Valuefor now would make sense to match with available node connections) as well as set default value. - Within the node tree in UI you can add a new node called Uniform within which you can select one of defined uniforms from a dropdown and it's output type matches accordingly.
-
In Python, new uniform values can be added to a given
NodeTreewithnode_tree.add_unfirom("Uniform name", type='VALUE', default=0.0)as an example and removed withnode_tree.remove_uniform("Uniform name")which both in turn recompile the shader code. This is essential for automation when creating new node groups in Python. -
In Python, for existing uniforms in a given
NodeTreeupdated values can be passed withnode_tree.set_uniform("Uniform name", value)which in turn does not recompile the shader .
This should open up the door for more customizable shaders and materials without the headache of ~2 FPS viewport playbacks and interactions.
0 Comments