Texture map Mobile effects create lava, waterfall effects
The principle is to change the value of the texture coordinate UV dynamically and make it move
First, prepare a decal.
Build a shader
Variable at a glance:
_maintex Main Texture Map
_maintint Main Colors
_scrollxspeed x-axis movement speed
_scrollyspeed y-Axis movement speed
Properties {_maintex ("Base (RGB)", 2D) = "White" {}_maintint ("Diffuse Tint", Color) = (1, 1, 1, 1) _scrollxspeed ("X SCR Oll speed ", range (0, ten)) = 2_scrollyspeed (" Y Scroll Speed ", range (0, 10)) = 2}
It's mostly done in the surf function.
Fixed xscrollvalue = _scrollxspeed * _time;
Fixed yscrollvalue = _scrollyspeed * _time;
x, y offset increases over time
void Surf (Input in, InOut surfaceoutput o) {fixed2 Scrolleduv = in.uv_maintex;fixed Xscrollvalue = _scrollxspeed * _time; Fixed yscrollvalue = _scrollyspeed * _time;scrolleduv + = Fixed2 (Xscrollvalue, yscrollvalue); Half4 C = tex2d (_maintex, SCR OLLEDUV); O. Albedo = C.rgb * _maintint;o. Alpha = C.A;}
_time is a unity Shaderlab built-in value
Float4 _time:time (t/20, T, T*2, T*3)
is a four-dimensional vector
Scrolleduv + = Fixed2 (Xscrollvalue, Yscrollvalue);
x, y values of uvs accumulate offsets over time
Finally integrate the UV and main colors onto the current texture
Produced the effect of this movement
The shader code is as follows
Shader "Custom/testshader" {Properties {_maintex ("Base (RGB)", 2D) = "White" {}_maintint ("Diffuse Tint", Color) = (1, 1, 1, 1) _scrollxspeed ("X Scroll Speed", range (0, ten)) = 2_scrollyspeed ("Y Scroll Speed", range (0, ten)) = 2}subshader {Tag s {"Rendertype" = "Opaque"}lod 200cgprogram#pragma surface Surf Lambertfixed4 _maintint;fixed _scrollxspeed;fixed _ Scrollyspeed;sampler2d _maintex;struct Input {float2 uv_maintex;}; void Surf (Input in, InOut surfaceoutput o) {fixed2 Scrolleduv = in.uv_maintex;fixed Xscrollvalue = _scrollxspeed * _time; Fixed yscrollvalue = _scrollyspeed * _time;scrolleduv + = Fixed2 (Xscrollvalue, yscrollvalue); Half4 C = tex2d (_maintex, SCR OLLEDUV); O. Albedo = C.rgb * _maintint;o. Alpha = C.A;} ENDCG} FallBack "Diffuse"}
Can look at my article also used this knowledge unity3d old movie-style screen effects
--------by wolf96
Unity3d Texture map Mobile effects create lava, waterfall effects