Unity3d Texture map Mobile effects create lava, waterfall effects

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.