Untiy Shader实现纹理贴图滚动
更新时间:2019年03月01日 11:20:45 作者:fredshao
这篇文章主要为大家详细介绍了Untiy Shader实现纹理贴图滚动,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
滚动纹理,可以实现一些如瀑布,河流,熔岩流等效果,本质上就是UV坐标的偏移,在Unity中新建一个Shader,然后修改成下面代码的样子,新建一个材质,选择此shader,赋予一张贴图,然后将材质应用于一个mesh上,运行即可看到效果
Shader "Custom/UVOffset" {
Properties {
_MainTint("Diffuse Tine",Color) = (1,1,1,1)
_MainTex("Base (RGB)",2D) = "white"{}
_ScrollXSpeed("X Scroll Speed",Range(0,10)) = 0
_ScrollYSpeed("Y Scroll Speed",Range(0,10)) = 2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
// 定义 Properties 中的属性
fixed4 _MainTint;
fixed _ScrollXSpeed;
fixed _ScrollYSpeed;
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed2 scrolledUV = IN.uv_MainTex;
fixed xScrollValue = _ScrollXSpeed * _Time;
fixed yScrollValue = _ScrollYSpeed * _Time;
scrolledUV += fixed2(xScrollValue,yScrollValue);
// 对贴图进行采样输出
half4 c = tex2D(_MainTex,scrolledUV);
o.Albedo = c.rgb * _MainTint;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章
C#中System.Array.CopyTo() 和 System.Array.Clon()&nbs
System.Array.CopyTo()和System.Array.Clone()是用于数组复制的两种不同方法,本文就来介绍C,#中System.Array.CopyTo() 和 System.Array.Clon() 的区别,具有一定的参考价值,感兴趣的可以了解一下2024-04-04
C#中的Task.WaitAll和Task.WaitAny方法介绍
这篇文章介绍了C#中的Task.WaitAll和Task.WaitAny方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-04-04


最新评论