Untiy Shader实现纹理贴图滚动
滚动纹理,可以实现一些如瀑布,河流,熔岩流等效果,本质上就是UV坐标的偏移,在Unity中新建一个Shader,然后修改成下面代码的样子,新建一个材质,选择此shader,赋予一张贴图,然后将材质应用于一个mesh上,运行即可看到效果
Shader"Custom/UVOffset"{ Properties{ _MainTint("DiffuseTine",Color)=(1,1,1,1) _MainTex("Base(RGB)",2D)="white"{} _ScrollXSpeed("XScrollSpeed",Range(0,10))=0 _ScrollYSpeed("YScrollSpeed",Range(0,10))=2 } SubShader{ Tags{"RenderType"="Opaque"} LOD200 CGPROGRAM //PhysicallybasedStandardlightingmodel,andenableshadowsonalllighttypes #pragmasurfacesurfStandardfullforwardshadows //Useshadermodel3.0target,togetnicerlookinglighting #pragmatarget3.0 //定义Properties中的属性 fixed4_MainTint; fixed_ScrollXSpeed; fixed_ScrollYSpeed; sampler2D_MainTex; structInput{ float2uv_MainTex; }; voidsurf(InputIN,inoutSurfaceOutputStandardo){ fixed2scrolledUV=IN.uv_MainTex; fixedxScrollValue=_ScrollXSpeed*_Time; fixedyScrollValue=_ScrollYSpeed*_Time; scrolledUV+=fixed2(xScrollValue,yScrollValue); //对贴图进行采样输出 half4c=tex2D(_MainTex,scrolledUV); o.Albedo=c.rgb*_MainTint; o.Alpha=c.a; } ENDCG } FallBack"Diffuse" }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。