Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
관리 메뉴

nomad-programmer

[CG/Unity] Toon Shader 본문

CG/Unity

[CG/Unity] Toon Shader

scii 2022. 2. 1. 18:25

Shader "Custom/NewSurfaceShader"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap ("NormalMap", 2D) = "bump" {}
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Toon Lambert 

        #pragma target 3.0

        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.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        float4 LightingToon(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten){
            float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
            if(ndotl > 0.7){
                ndotl = 1;
            }
            else{
                ndotl = 0.3;
            }

            float rim = abs(dot(s.Normal, viewDir));

            if(rim > 0.5){
                rim = 1;
            }
            else{
                rim = -1;
            }

            float4 final;

            final.rgb = s.Albedo * ndotl * _LightColor0.rgb * rim;

            final.a = s.Alpha;

            return final;
        }

        ENDCG

    }
    FallBack "Diffuse"
}

'CG > Unity' 카테고리의 다른 글

[CG/Unity] Cube Map  (0) 2022.02.01
[CG/Unity] Diffuse Warping  (0) 2022.02.01
[CG/Unity] Vertex Shader  (0) 2022.01.30
[CG/Unity] Lambert 셰이더  (0) 2022.01.16
[CG/Unity] Custom Light 만드는 방법  (0) 2022.01.15
Comments