How to use Shader Graph in STYLY

Introduction

This article explains how to use the Unity feature, Shader Graph, with STYLY.

We are using Unity 2022.3.24f1, STYLY Plugin 2.0.0, and Shader Graph 14.0.11.

You can download the latest version of the STYLY Plugin from the article below.

Sample Scene

Shader Graph Sample Scene

Shader Graph Sample Scene

How to Introduce Shader Graph

Select Shader Graph from the Unity Registry in the Package Manager and click Install.

Package Manager→Unity Registry→Shader Graph→Install

Package Manager→Unity Registry→Shader Graph→Install

If the Package Manager is not displayed, click Window→Package Manager.

Window→Package Manager

Window→Package Manager

Right-click in the Assets and select Create→Shader Graph→Builtin→Lit Shader Graph to add it.

Create→Shader Graph→Builtin→Lit Shader Graph

Create→Shader Graph→Builtin→Lit Shader Graph

After adding Shader Graph, right-click on the icon and select Create→Material to create a material. The material created this way is automatically linked to the Shader Graph.

Create→Material

Create→Material

Right-click in the Hierarchy and create a 3D Object→Sphere.

Drag and drop the material created earlier onto the Sphere.

3D Object→Sphere

3D Object→Sphere

This completes the preparation for Shader Graph.

How to Use Shader Graph

From here, we will create a sample using Shader Graph.

This is the kind of shader we will create this time.

Shader Graph Sample

Shader Graph Sample

First, double-click the Shader Graph you created earlier to open the Shader Graph editing screen.

The screen layout is as follows:

ShaderGraph

ShaderGraph

Creating the BaseColor

Here, we will use a noise texture, so please download a texture from the following site and add it to your Assets. You may also prepare your own texture.

https://www.textures4photoshop.com/tex/bokeh-and-light/electric-power-lightning-texture-seamless.aspx

First, click the “+” icon on the Blackboard and add [Texture2D].

[Texture2D]

[Texture2D]

After adding it, drag and drop it to add it as a node.

Think of the Blackboard as a place to store variables.

To save or update the content of the Shader Graph, click Save Asset at the top-left corner of the screen.

Save Asset

Save Asset

It is recommended to save frequently.

Drag and drop the image into the Default field of the added Texture2D.

Drag&Drop

Drag&Drop

To add nodes in Shader Graph, right-click and select Create Node.

CreateNode

CreateNode

In the Create Node search bar, search for “Sample” and add [Sample Texture 2D].

[Sample Texture 2D]

[Sample Texture 2D]

Connect the [Texture2D] to the Texture (T2) input of [Sample Texture 2D].

The texture is now displayed.

[Texture2D]

[Texture2D]

Next, we will animate the texture.

Add a Float in the Blackboard, name it [Tiling Speed], and set the Default to 0.1.

[Tiling Speed] [Tiling Speed]

Add [Time], [Multiply], and [Tiling And Offset].

Connect the nodes as shown below to make the texture move.

[Time], [Multiply], [Tiling And Offset] [Time], [Multiply], [Tiling And Offset][/caption>

To change the speed of the texture, adjust the value of [Tiling Speed].

To add movement in the opposite direction, duplicate [Sample Texture 2D] and [Tiling And Offset] using Ctrl+[D].

Add [One Minus] and connect the nodes as shown below.

Ctrl+[D]
Ctrl+[D]

Add [Add], connect the two [Sample Texture 2D] nodes to it, and then connect [Add] to the BaseColor of the Fragment.

Node

Node[/caption>

 

The shader will now be displayed in the Preview in the bottom-right corner of the screen.

If you want to group multiple nodes, select all the nodes you want to include in the group and press Ctrl+[G].

[caption id="attachment_56984" align="aligncenter" width="1000"]Ctrl+[G] Ctrl+[G]

Creating Emission

Add a Color to the Blackboard, name it [Fresnel Color], and change it to a greenish color.

[caption id="attachment_56985" align="aligncenter" width="1000"][Fresnel Color] [Fresnel Color]

Add [Fresnel Effect] and [Multiply], and connect the nodes as shown below.

[caption id="attachment_56986" align="aligncenter" width="1000"][Fresnel Effect], [Multiply] [Fresnel Effect], [Multiply]

Change the Power of [Fresnel Effect] to 4.

This makes the edges appear softly green.

Add [Time], [Remap], and [Multiply], and modify the values in [Remap].

Connect the nodes as shown below to create a blinking Fresnel effect.

Fresnel Effect

Fresnel Effect

Finally, connect [Multiply] to the Emission of the Fragment.

Node

Node

Creating a Vertex Shader

Next, use a vertex shader to make the sphere appear wavy.

First, add two Floats to the Blackboard and name them [Displacement Speed] and [Noise Scale], setting both Defaults to 0.1.

[Displacement Speed], [Noise Scale]

[Displacement Speed], [Noise Scale]

Add [Time], [Position], [Multiply] × 2, [Add], and [Simple Noise], and connect the nodes as shown below.

[Time], [Position], [Multiply]×2, [Add], [Simple Noise]

[Time], [Position], [Multiply]×2, [Add], [Simple Noise]

Add [Normal Vector], [Position], [Multiply], and [Add], and connect them to the Position of the Vertex to make the sphere’s surface appear wavy.

[Normal Vector], [Position], [Multiply], [Add]

[Normal Vector], [Position], [Multiply], [Add]


Node

Node

Important Notes

Sometimes, the Shader Graph preview may display correctly, but the appearance in the Scene is different.

Select the object using the Shader Graph material and check the Inspector.

Inspector

Inspector

In the Inspector’s Shader Input section, the textures and values are still set to their defaults. Assign the correct values to each field.

Shader Input

Shader Input

Shader Input[/caption>

The values, textures, and colors here do not automatically apply even after saving the Shader Graph. You will need to manually adjust them to match the values and colors in the Shader Graph at the end.

Uploading to STYLY

Create a STYLY account

How to create an account