Unity2018 new features preemptive | ShaderGraph actual combat holographic effect

This article was first published on the WeChat public account of Torrent School.
Torrent School, let you learn Unity a few steps faster

Last time we talked about the configuration, creation, editing and use of ShaderGraph on the shader. In this lesson, we will use an example to see how to quickly create a holographic effect with ShaderGraph.

Holographic effect

This holographic effect is generated by rolling the Offset of the texture over time. Let's see how to make it in ShaderGraph.

1. Create a PBR Graph

2. We will use a holographic texture map

Download this sticker to use

3. Create a Node of Sample Texture 2D, and select the texture you just downloaded for the Texture property of the node

4. To make the texture scroll, use the Tiling And Offset node and create a node for this. Connect the Output of the Tiling And Offset node to the UV property of the Sample Texture 2D. Now if you modify the Y value of the Offset of the Tiling And Offset node, you will see that the texture scrolls down!

Tiling And Offset Node

5. So how to make Offset change automatically, we can use the built-in Time node.
Create a Time node and connect Time(1) to Offset and you will see the texture scroll automatically.

Note: This will actually make the X and Y of Offset scroll at the same time. Since the texture is repeated on the X axis, it cannot be seen.

6. At this time, if you connect the output RGBA (4) of the Sample Texture 2D to the node Emission (self-illumination) of the PBR Master, you can see the effect

first effect

But this effect obviously can not achieve our ideal effect.

7. We want to control the scrolling speed through a parameter.
1) Add a Vector1 parameter named Speed, the default value is set to 0.1.
2) Drag this parameter to the graph, create a Multiply (multiply) node, then multiply the Time node and the Speed ​​attribute node, and drag the Output to Offset , as shown below.

You can see that the scrolling speed has slowed down

8. We also want to be able to control the color of this holographic projection.
1) Add a color property
2) We want to make the darker parts of the map darker and the white parts lighter.
Multiply the color property with the output RGBA(4) of the Sample Texture 2D, so that the color has a gradient effect.
3) Drag the Out of Multiply to the Albedo and Emission of the PBR Master node

9. Since our map is an RGB grayscale image without a transparent channel, we need to make the transparent channel ourselves.
We can use any channel of RGB as the alpha value. At the same time, you need to set the Surface of the PBR Master to Transparent.

Note that the A channel cannot be used, because the texture itself does not have an alpha channel, so the value of the alpha channel will be all 1.

10. Finally, we can make this holographic effect a little better: the current effect will be thinner than the original effect stripes, which can be solved by adding a One Minus node (the role of One Minus: the output result is 1-input)

So we're done! That's the effect at the beginning of the article.

summary

This article covers the knowledge of input attributes and multiple nodes through the ShaderGraph of the holographic effect.
There will be more example tutorials in the future, pay attention to the Torrent School official account to get it as soon as possible.

Do you have any classmates who are tortured by shaders? You can share today's content with him, maybe you can help him.

The source code of this article can be 全息obtained .


Unity: The world's leading game, VR/AR engine
"Zheng Hongzhi's Unity 2018 Lesson", I have devoted my 8 years of development experience, combined with the latest Unity2018, to take you from entry to mastery.
Currently pre-sale group, 5.5% off!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324588094&siteId=291194637