• Unity Shader (五)Surface Shader示例


    1、替换颜色

    Shader "Custom/Example_Frag_5" {
        Properties {
            _MainTex ("Albedo (RGB)", 2D) = "white" {}
            _MainColor("MainColor",color)=(1,1,1,1)
            _SecondColor("SecondColor",color)=(1,1,1,1)
            _Center("Center",range(-2.7,2.7))=0
            _R("R",range(0,0.5))=0.2 //颜色渐变的半径
            _Glossiness ("Smoothness", Range(0,1)) = 0.5
            _Metallic ("Metallic", Range(0,1)) = 0.0
        }
        SubShader {
            Tags { "RenderType"="Opaque" }
            LOD 200
            
            CGPROGRAM
        
            #pragma surface surf Standard vertex:vert fullforwardshadows
    
            #pragma target 3.0
    
            sampler2D _MainTex;
            half _Glossiness;
            half _Metallic;
            float4 _MainColor;
            float4 _SecondColor;
            float _R;
            float _Center;
    
    
            struct Input {
                float2 uv_MainTex;
                float x;
            };
    
            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;
                float f=s/_R;
                f=saturate(f);
                d*=f;
                d=d/2+0.5;
                o.Albedo*=lerp(_MainColor,_SecondColor,d)*2;
            }
            ENDCG
        }
        FallBack "Diffuse"
    }
  • 相关阅读:
    Word Break
    Binary Tree Right Side View
    41. First Missing Positive
    2 Sum ,3 Sum, 3 Sum close
    216. Combination Sum III
    190. Reverse Bits
    143. Reorder List
    142. Linked List Cycle II
    Single Number i,ii,iii
    62. Unique Paths i & ii
  • 原文地址:https://www.cnblogs.com/Jason-c/p/8582238.html
Copyright © 2020-2023  润新知