美文网首页Unity3D 成神之路
片段级模型动态变色(实现汽车动态换漆)

片段级模型动态变色(实现汽车动态换漆)

作者: Moment__格调 | 来源:发表于2017-08-11 11:35 被阅读22次

Unity 一个面片的最大顶点数为65524,所以大于这个数,请拆分成多个面片1.获取汽车x轴的最大值和最小值[-2.5,2.5]+R !

Shader "Sbin/SurfaceShader" {
    Properties{
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0

        _UpColor("UpColor",color) = (1,0,0,1)
        _DownColor("DownColor",color) = (0,1,0,1)
        _Center("Center",range(-0.7,0.7)) = 0
        _R("R",range(0,0.5)) = 0.2
    }
        SubShader{
        Tags{ "RenderType" = "Opaque" }
        LOD 200

        CGPROGRAM
#pragma surface surf Standard vertex:vert fullforwardshadows
        //说明:pragma surface method1 Standard vertex:method2 fullforwardshadows

#pragma target 3.0

        sampler2D _MainTex;

    struct Input {
        float2 uv_MainTex;
        float x : TEXCOORD0;
    };

    half _Glossiness;
    half _Metallic;

    float4 _UpColor;
    float4 _DownColor;
    float _Center;
    float _R;

    void vert(inout appdata_full v,out Input o) {
        o.uv_MainTex = v.texcoord.xy;
        o.x = v.vertex.x;
    }

    void surf(Input IN, inout SurfaceOutputStandard o) {
        fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
        o.Albedo = c.rgb;
        o.Metallic = _Metallic;
        o.Smoothness = _Glossiness;
        o.Alpha = c.a;

        float d = IN.x - _Center;//融合带
        float s = abs(d);
        d = d / s;//正负值分别描述上半部分和下半部分,取值1和-1

        float f = s / _R; //范围>1:表示上下部分;范围<1:表示融合带
        f = saturate(f);
        d *= f;//表示全部[-1,1];范围>1:表示上部分;范围<1:表示融合带;范围<-1:表示下部分

        d = d / 2 + 0.5;//将范围控制到[0,1],因为颜色值返回就是[0,1]
        o.Albedo += lerp(_UpColor,_DownColor,d);
    }
    ENDCG
    }
        FallBack "Diffuse"
}

效果:

Paste_Image.png

相关文章

网友评论

    本文标题:片段级模型动态变色(实现汽车动态换漆)

    本文链接:https://www.haomeiwen.com/subject/smylrxtx.html