Untiy Shader實現(xiàn)紋理貼圖滾動
更新時間:2019年03月01日 11:20:45 作者:fredshao
這篇文章主要為大家詳細介紹了Untiy Shader實現(xiàn)紋理貼圖滾動,具有一定的參考價值,感興趣的小伙伴們可以參考一下
滾動紋理,可以實現(xiàn)一些如瀑布,河流,熔巖流等效果,本質(zhì)上就是UV坐標的偏移,在Unity中新建一個Shader,然后修改成下面代碼的樣子,新建一個材質(zhì),選擇此shader,賦予一張貼圖,然后將材質(zhì)應用于一個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"
}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
C#中System.Array.CopyTo() 和 System.Array.Clon()&nbs
System.Array.CopyTo()和System.Array.Clone()是用于數(shù)組復制的兩種不同方法,本文就來介紹C,#中System.Array.CopyTo() 和 System.Array.Clon() 的區(qū)別,具有一定的參考價值,感興趣的可以了解一下2024-04-04
C#中的Task.WaitAll和Task.WaitAny方法介紹
這篇文章介紹了C#中的Task.WaitAll和Task.WaitAny方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04

