Surface Shader

  • SurfaceOutput
  • Input
  • lighting
  • shadow
Shader "Custom/NewSurfaceShader"
{
    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  //  金属光泽
    }
    SubShader  //  无pass通道,surface为我们生成
    {
        Tags { "RenderType"="Opaque" }  //  渲染类型
        LOD 200  //  层级细节

        CGPROGRAM  //  CG语言的代码块
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard // fullforwardshadows alpha addshadow  //  编译指令:#pragma surface 函数名  光照模型(函数) 其他选项

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0  //  默认2.0 
        // 重新声明变量
        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        sampler2D _MainTex; // 纹理

        struct Input
        {
            float2 uv_MainTex;  //  uv_纹理名 固定名称 类型在CG有多种,详见Unity手册
        };


        // 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)  //  surf函数对应上面 无返回值 Input对应上方结构体 inout in/out 输入输出/输入/输出 传递类型SurfaceOutputStandard/SurfaceOutputStandardSpecular
        {
            // 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;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

“您的支持是我持续分享的动力”

微信收款码
微信
支付宝收款码
支付宝

采唐
采唐的狐言狐语🦊
公告

欢迎欢迎!这是采唐的新博客页!
最新评论

加载中...