shown in other instead.
Material Editor (Experimental)
Material Editor enables you to create your own materials visually without writing a single line of code - simply create and connect nodes building a graph! Material Editor gives you an immediate feedback reflecting all your changes on the preview sphere, it is simple enough for users who are new to materials creation. And powerful enough to let you do a lot of things including:
- Modify appearance of your surfaces procedurally changing their look based on useful information about it (normals, world position, distance from the camera, and orientation relative to the view direction, etc.)
- Animate and warp UVs
- Perform repeated actions without overcomplicating your graph by using loops
- Share functionality between multiple graphs and users via subgraphs
- Expose your material's settings to the Parameters window, to quickly tweak your material right in the UnigineEditor when building and setting up your scene
- Create custom function graph nodes implementing desired functionality via shader code in UUSL
- Use quick type conversion and data rearrangement via port adapters
- Blend multiple materials easily to create a unique look
- Use familiar image adjustment operations to change the look of your objects
Material Editor enables you to blend multiple materials easily - just add a special mixer node (PBR Material Mixer) and specify materials you want to blend by connecting Material Reference nodes to the mixer, then provide a blending control value - that's it!
Working with Material Graphs#
A Material Graph asset (.mgraph) is a source for generation of a normal base material (node-based description to be compiled into a normal material). To create a new Material Graph open the Create menu, then select Create Material Graph from the dropdown (or just hit Tab or Space on the keyboard), and choose one of the following templates:
- mesh_pbr_deferred - a template of a deferred material to be assigned to meshes
- mesh_pbr_forward - a template of a forward (transparent) material to be assigned to meshes
- subgraph - a template of a subgraph (functional block to be used in other material graphs)
In the dialog that opens specify a name for your graph. A new *.mgraph asset will be created in the current folder of your project. Double-clicking the asset opens the Material Editor window.
When you open the Material Graph (not a subgraph) you start with a sort of a 'Master Node' (Deferred PBR Material or Forward PBR Material). You connect your structures of nodes (including subgraphs) to the Master Node to create the look of your material.
You can quickly change the look of your surface by changing the default values! You can add as many textures and a lot of complex interactions. To add a new node simply right-click somewhere in the window and select Create Node.
Almost each Material Graph node has a number of inputs, some of them have default values that you can customize anyway you want.
Adding a texture (or other assets) is also really easy, just create a node of that asset type and connect it! Textures can be dragged directly from the Asset Browser.
Finally the output from the Master Node is connected to the Final Material node.
Controls in the Material Editor generally match the controls of other tools in the UnigineEditor. For example, the material graph can be navigated as with other linked object editors, the material preview mesh can be oriented as per other mesh tools, etc.
|Mouse Wheel drag on background||Pan material graph|
|Mouse Wheel scroll||Zoom in/out|
|RMB||Display context menu (node creation, operations on current selection)|
|LMB drag on background||Select nodes with rectangle tool|
|LMB click on node||Select node|
|Shift + LMB on node||Toggle node selection|
|LMB drag on node||Move selected nodes|
|Delete Key||Delete selected nodes|
|Space / Tab Key||Display node creation menu|
A port defines an input (left side) or output (right side) of a node. Connecting edges to a port allows data to flow through the Material Graph node network.
Each port has a data type defining edges that can be connected to it. All data types are color-coded, meaning that each of them has an associated color used for identification.
Only one edge can be connected to any input port but you can connect multiple edges to an output port.
An edge represents a connection between two ports (input and output). Edges define how data flows through the Material Graph node network. You can only connect an edge from an output port to an input port.
Each edge has a data type defining ports it can be connected to. Color coding for ports and edges is the same.
A new edge is created by dragging from a desired output port to the desired input port. Dragging an edge from the input Port creates a default input value for the corresponding parameter. To remove an edge select it with the left mouse button and hit Delete.
Port adapter is a feature giving you an ability to select data components in an arbitrary order, combine and rearrange them, providing convenient access to elements and a lot of flexibility. It is available for the following 3D related data types:
When you drag a new edge to an input port, a number of available connection options shall appear.
You can change the adapter later by selecting a port and editing the Swizzle field
Adding New Nodes#
In order to add a new node right-click on the background, choose Create Node and select a node type from the popup or type its name in the Search field to find it. You can also press Space or Tab key to start typing the name immediately.
Sometimes you need to perform certain actions multiple times, cloning the relevant groups of nodes will make your graph overcomplicated very quickly, even if only 10 iterations are required. In UNIGINE you can create loops for that just like in programming.
To create a loop simply hit Space or Tab on the keyboard and choose Create Loop. Two connected nodes (Loop Input and Loop Output) will be created. The Output node has the break input and output ports by default (the default break condition is 1)
To add a new port, select the Input or Output node, depending on the type of the port you want to add, then right-click and choose Add Slot from the popup menu. Then in the dialog that opens specify a Name and a Type for the new port to be added, and click Add.
So, you add ports for all necessary input and output parameters of your loop and build a loop graph implementing the functionality of a single iteration, then you add break condition, implement loop variable management (increment, decrement, etc.), initialize necessary ports and your loop becomes functional!
No matter how advanced the materials system is, you might want something specific, maybe too complicated to be implemented via basic nodes. Or sometimes it might be quicker to write several lines of code for mathematical operations instead of spawning a bunch of nodes and connecting them. The solution is simple - create an Inline Source Function node and wrap any shader function into it. Input and output ports for the node shall be automatically generated according to the function's signature.
To add or edit code to the node right-click on the node and choose Edit, the Code Editor window will open:
Sometimes, especially in complex material graphs, there are too many crisscrossing edges making the whole graph look like a spiderweb, and the data flow very hard to understand. A portal is a set of special nodes including a single input and one or more outputs, all having the same name. Portals serve to reduce the number of edges and make the graph more 'readable'.
You can quickly find all the points connected by a portal:
- To select portal's input right-click on one of its output nodes and choose Select input.
- To select portal's outputs right-click on its input node and choose Select outputs.
A Subgraph is a special type of material graph, which can be referenced from inside other material graphs. This can be very useful when the same operations are to be performed multiple times in a single graph or across multiple graphs. You simply pack these operations into a box with a set of inputs and outputs, an then use this box anywhere you need. A Subgraph differs from a Material Graph in three main ways:
- A Subgraph does not generate any material, it is used as a building block in material graphs.
- A Subgraph does not have a Master Material Node (like Deferred PBR Material or Forward PBR Material). But instead, it must have two nodes called Subgraph Input and Subgraph Output defining all input and output ports.
Basically, the process of construction of a Subgraph is the same as when you create a Material Graph.
Configuring Inputs and Outputs#
To add a new port, select the Input or Output node, depending on the type of the port you want to add, and right-click anywhere in the Node Editor and choose Add Slot from the popup menu. Then in the dialog that opens specify a Name and a Type for the new port to be added, and click Add.
You can modify existing ports, change their names and types at any time, in the Selection Properties panel, when the Input or Output node is selected. To remove a port simply click Remove above its name.
To add a subgraph to your material graph currently opened in the Editor, simply drag the subgraph asset from the Asset Browser directly to the Material Editor and connect necessary edges to input and output ports of the subgraph.
There is a set of core subgraphs implementing basic functionality (like contrast, refract, object_triplanar, etc.) stored in the core/nodes folder. All of these subgraphs are automatically added to the palette on loading the UnigineEditor, so if your start typing a name of such a subgraph in the search field of the node creation menu, it will be displayed in the list.