码迷,mamicode.com
首页 > 其他好文 > 详细

Untiy Shader - 纹理贴图滚动

时间:2015-06-15 22:13:10      阅读:147      评论:0      收藏:0      [点我收藏+]

标签: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"
}

Untiy Shader - 纹理贴图滚动

标签:shader

原文地址:http://blog.csdn.net/linkrules/article/details/46507509

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!