鸟语天空
合并图片
post by:追风剑情 2019-11-25 15:44

一、新建Standard Surface Shader

11111.png

二、Shader


Shader "Custom/ShipComposeShader"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
	_SecondTex ("Second (RGB)", 2D) = "black" {}
	_SecondMinX ("Second min x", Range(0, 1)) = 0.1
	_SecondMinY ("Second min y", Range(0, 1)) = 0.1
	_SecondMaxX("Second max x", Range(0, 1)) = 0.9
	_SecondMaxY("Second max y", Range(0, 1)) = 0.9
	_Cut("Cut", Range(0,1)) = 0.5
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        // 开户Alpha裁剪
        #pragma surface surf Standard fullforwardshadows alphatest:_Cut

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
		sampler2D _SecondTex;
		fixed _SecondMinX;
		fixed _SecondMinY;
		fixed _SecondMaxX;
		fixed _SecondMaxY;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;

            //合成Logo
            fixed2 main_uv = IN.uv_MainTex;
            //是否在矩形区域内
            if (main_uv.x >= _SecondMinX && main_uv.x <= _SecondMaxX && main_uv.y >= _SecondMinY && main_uv.y <= _SecondMaxY)
            {
                 fixed2 uv_SecondTex;
                 uv_SecondTex.x = 1 - (main_uv.x - _SecondMinX) / (_SecondMaxX - _SecondMinX);
                 uv_SecondTex.y = (main_uv.y - _SecondMinY) / (_SecondMaxY - _SecondMinY);
                 fixed4 second_c = tex2D(_SecondTex, uv_SecondTex);
                 fixed a = step(second_c.a, 0.5);
                 o.Albedo = c.rgb * a + second_c.rgb * _Color * (1 - a);
            }
        }
        ENDCG
    }
    FallBack "Diffuse"
}


三、查看效果

22222.png

33333.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容