[학원 Unity]/[게임 그래픽 프로그래밍]

09-05 수업내용 ) NPR 렌더링

롤링페이퍼 2024. 9. 5. 15:43

 

 

 

1. Vertex Shader를 이용한 오브젝트 확장하기

Shader "Custom/2Pass"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _ShadowTex ("Shader Texture", Range(0, 0.01)) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        Cull Front

        //1Pass
        CGPROGRAM
        #pragma surface surf _NoLight vertex:vert noshadow
        #pragma target 3.0

        sampler2D _MainTex;

        float _ShadowTex;

        // vertex:vert 에 대한 함수 따로 추가
        void vert (inout appdata_full v)
        {
            // 외각선 굵기 조절 normal로 전체 크기를 조절 가능
            // 즉 normal * 길이 를 vertex.xyz축 전체만큼 더한다.
            v.vertex.xyz = v.vertex.xyz + (v.normal.xyz * _ShadowTex);
            
        }

        struct Input
        {
            float2 uv_MainTex;
            //float4 color : COLOR;
        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            // fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            // o.Emission = c.rgb + abs(sin(_Time.y));
            // o.Alpha = c.a;
        }

        float4 Lighting_NoLight(SurfaceOutput s, float3 lightDir,float atten)
        {
              return 0;
        }
        ENDCG

        Cull Back

        //2Pass
        CGPROGRAM
        #pragma surface surf Lambert
        #pragma target 3.0

        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"
}