Unity/Shader

[5.4] Shader Lightening

ljw4104 2021. 5. 4. 17:00

Standard / Lambert / BlinnPhong 모델

뭔차인지 모르겠다. (Lambert랑 BlinnPhong이랑 뭔차인지 모르겠다)

 

 

Standard.shader

Shader "Custom/Standard"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpTex ("Albedo (RGB)", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Standard

        sampler2D _MainTex;
        sampler2D _BumpTex;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpTex;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 n = tex2D (_BumpTex, IN.uv_BumpTex);

            o.Normal = UnpackNormal(n);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

Lambert.shader

Shader "Custom/Lambert"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpTex ("Albedo (RGB)", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Lambert

        sampler2D _MainTex;
        sampler2D _BumpTex;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 n = tex2D (_BumpTex, IN.uv_BumpTex);

            o.Normal = UnpackNormal(n);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

BlinnPhong.shader

Shader "Custom/BlinnPhong"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _SpecColor ("Specular Color", Color) = (1,1,1,1)
        _Specular ("Specular", Range(0,1)) = 1
        _Gloss ("Gloss", Range(0,1)) = 0
        _BumpTex ("Albedo (RGB)", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf BlinnPhong

        sampler2D _MainTex;
        sampler2D _BumpTex;
        float _Gloss;
        float _Specular;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 n = tex2D (_BumpTex, IN.uv_BumpTex);

            o.Normal = UnpackNormal(n);
            o.Specular = _Specular;
            o.Gloss = _Gloss;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 


struct SurfaceOutput

Member Name What?
fixed3 Albedo 기본색상
fixed3 Normal 반사각을 결정하는 면의 방향
fixed3 Emission 객체가 스스로 생성하는 빛의 양
half Specular 빛을 반사하는 정도
fixed Gloss Specular 반사가 퍼지는 정도
fixed Alpha 투명도
  • Specular가 0에 가까워지면 가까울수록 객체가 모든것을 반사하게 되어 안보인다.
  • BlinnPhong에서 _SpecColor는 유니티가 정해놓은 변수이다. 변경할 수 없고 밑에서 선언할 수 없다.