셰이더(Light Lambert, Blinn Phong, Standard)

#Default(물리 기반 셰이더)

-물리 기반 셰이더는 SurfaceOutputStandard 구조를 사용합니다.

 #pragma surface surf Standard
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;
        sampler2D _Occlusion;
        float _Metallic;
        float _Smoothness;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Occlusion = tex2D(_Occlusion, IN.uv_MainTex);
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Albedo = c.rgb;
            o.Metallic = _Metallic;
            o.Smoothness = _Smoothness;
            o.Alpha = c.a;
        }

#램버트

-SurfaceOutput 구조 사용

Shader "Custom/Lambert"
{
    Properties
    {
        _MainTex("Albedo (RGB)", 2D) = "white" {}

    }
        SubShader
    {
        Tags { "RenderType" = "Opaque" }
        CGPROGRAM
        
        #pragma surface surf Lambert

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf(Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
            
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
        FallBack "Diffuse"
}

#블린퐁

Shader "Custom/BlinnPhong"
{
    Properties
    {
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _SpecColor("spec color",Color) = (1,1,1,1) //반드시 변수명 고정, SubShader안에 변수 정의 X
        _SpecStrength("spec str",Range(0,1)) = 0
        _Gloss("gloss",Range(0,1)) = 0
    }
        SubShader
    {
        Tags { "RenderType" = "Opaque" }
        CGPROGRAM
        #pragma surface surf BlinnPhong
        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf(Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
            o.Specular = 0.5; //스펙큘러의 크기
            o.Gloss = 1; //스펙큘러의 강도
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
        FallBack "Diffuse"
}

#디지털 조명

*Directional Light – 직진성을 가진 빛


셰이더(Light Lambert, Blinn Phong, Standard) 1

*포인트 라이트 – 모든 방향으로 퍼지는 특징


셰이더(Light Lambert, Blinn Phong, Standard) 2

*포인트 라이트 – 특정 부분을 강조하고 표현할 때 사용


셰이더(Light Lambert, Blinn Phong, Standard) 3

* 맞춤형 조명 만들기

        #pragma surface surf Test noambient //custom light, noambient-엠비언트 라이트 제거
float4 LightingTest(SurfaceOutput s, float3 lightDir, float atten)
        {
            return float4(1, 0, 0, 1);
        }


셰이더(Light Lambert, Blinn Phong, Standard) 4

*라베르트 라이트 작동

Shader "Custom/Test5"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("NormalMap",2D) = "bump"{} //normal map 추가
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Test noambient //custom light, noambient-엠비언트 라이트 제거

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); //NormalMap
            o.Alpha = c.a;
        }
        float4 LightingTest(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = saturate(dot(s.Normal, lightDir)); //saturate 0~1
            //return float4(1, 0, 0, 1);
            return ndotl;
        }
        ENDCG
    }
    FallBack "Diffuse"
}


셰이더(Light Lambert, Blinn Phong, Standard) 5
*노멀맵 추가, noambient

*Half-Lambert-Light 연산(기존 Lambert 연산이 0~1로 떨어지고, 빠르게 변하기 때문에 자연스럽지 못함)

Shader "Custom/Test5"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("NormalMap",2D) = "bump"{} //normal map 추가
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Test noambient //custom light, noambient-엠비언트 라이트 제거

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); //NormalMap
            o.Alpha = c.a;
        }
        float4 LightingTest(SurfaceOutput s, float3 lightDir, float atten)
        {
            //float ndotl = saturate(dot(s.Normal, lightDir)); //saturate 0~1 , Lambert
            float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5; //half-lambert
            return ndotl;
        }
        ENDCG
    }
    FallBack "Diffuse"
}


셰이더(Light Lambert, Blinn Phong, Standard) 6

*Lambert 조명 완성(빛 색상 _LightColor0.rgb, 강도, 조명 감쇠, 알베도에 알베도 텍스처 추가)

float ndotl = saturate(dot(s.Normal, lightDir));
            float4 final;
            final.rbg = ndotl * s.Albedo * _LightColor0.rgb * atten;
            final.a = s.Albedo;
            return final;


셰이더(Light Lambert, Blinn Phong, Standard) 7

*림 라이트 – 프레넬 공식

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

        CGPROGRAM
        #pragma surface surf Lambert noambient

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}


셰이더(Light Lambert, Blinn Phong, Standard) 8
*조명에 영향을 받지 않는 기본형(noambient)

*림 라이트 추가

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

        CGPROGRAM
        #pragma surface surf Lambert noambient

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
            float3 viewDir; //view vector 추가
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = 0;

            //Rim Light
            float rim = dot(o.Normal, IN.viewDir);
            o.Emission = pow(1 - rim, 3);
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}


셰이더(Light Lambert, Blinn Phong, Standard) 9

* 림 라이트의 색상과 너비를 사용자 지정

Shader "Custom/RimTest"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("NormalMap",2D) = "bump"{}
        _RimColor("RimColor",Color) = (1,1,1,1)
        _RimPower("RimPower",Range(1,10))=3
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Lambert

        sampler2D _MainTex;
        sampler2D _BumpMap;
        float4 _RimColor;
        float _RimPower;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpMap;
            float3 viewDir; //view vector 추가
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

            //color,power추가
            float rim = saturate(dot(o.Normal, IN.viewDir));
            o.Emission = pow(1 - rim, _RimPower) * _RimColor.rgb;

            //Rim Light
            //float rim = dot(o.Normal, IN.viewDir);
            //o.Emission = pow(1 - rim, 3);
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}


셰이더(Light Lambert, Blinn Phong, Standard) 10


셰이더(Light Lambert, Blinn Phong, Standard) 11