Untiy Shader实现纹理贴图滚动
程序员文章站
2022-07-22 18:27:12
滚动纹理,可以实现一些如瀑布,河流,熔岩流等效果,本质上就是uv坐标的偏移,在unity中新建一个shader,然后修改成下面代码的样子,新建一个材质,选择此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" }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。