UnityShader-属性介绍Properties

着色器属性模块可有可无。

Shader "Unlit/MyShader"
{
    Properties
    {
        //颜色
        [HDR]_Color("WLQ_Color",Color) = (1,1,1,1)
        //整型
        _Int("WLQ_Int",Int) = 1
        //浮点型
        _Float("WLQ_Float",Float) = 0.98
        //浮点型,带范围
        _Float2("WLQ_Float2",Range(0,100)) = 0
        //浮点型,带范围微调
        [PowerSlider(0.8)]_Float3("WLQ_Float3",Range(0,1)) = 0.5
        //整型
        [IntRange]_Float4("WLQ_Float4",Range(0,5))=0
        //开关
        [Toggle]_Float5("WLQ_Float5",Range(0,1)) = 0
        //枚举
        [Enum(UnityEngine.Rendering.CullMode)]_Float6("WLQ_Float6",Float) = 1

        //四维向量
        _Vector("WLQ_Vector",Vector) = (1,1,1,1)

        //2D 纹理
        _MainTex ("WLQ_Texture", 2D) = "white" {}
        [NoScaleOffset]_MainTex2 ("WLQ_Texture2", 2D) = "white" {}
        [Normal]_MainTex3 ("WLQ_Texture3", 2D) = "white" {}

        //3D纹理
        _MainTex4("WLQ_Texture4", 3d) = "" {}

        //立方体纹理
        _MainTex5("WLQ_CubeMap", CUBE) = "" {}

        //通用属性
        //注释
        [Header(This is Another Int)]_Int2("WLQ_Int2",Int) = 1
        //隐藏暴露于属性面板
        [HideInInspector]_Int3("WLQ_Int3",Int) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
    }
}

UnityShader-属性介绍Properties
以上列举Shader属性模块整型、浮点数、开关、枚举、2D纹理、3D纹理、四维向量、立方体纹理以及一些属性标签的使用说明。

上一篇:UnityShader20.1:CommandBuffer初见(下)


下一篇:shader从入门到颈椎康复(一)