11/29

이우석·2023년 11월 29일
0

SBS 국기수업

목록 보기
77/120

NPR : 비사실적(non-photorealistic) 렌더링

  1. 투패스(TwoPass) 이용하기
  2. 역광(LimLight) 이용하기
  3. 포스트프로세스(후처리) 방식 이용하기

현재 단계에선 1,2만 사용

  1. 투페스 이용하기


업로드중..

cull front 로 뒤집힌 모델 생성

업로드중..

업로드중..
cull back (기본값)으로 정상적인 모델 생성

이하 쉐이더 파일 코드

Shader "Apply/TwoPassShader"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _OutlineColor ("Outline Color", Color) = (0, 0, 0, 1)
        _OutlineWeight ("Outline Weight", Range(1, 20)) = 5
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        cull front

        CGPROGRAM
        #pragma surface surf Nolight noambient vertex:vert noshadow
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
        };

        fixed4 _OutlineColor;
        float _OutlineWeight;

        UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
        }

        float4 LightingNolight(SurfaceOutput s, float3 lightDir, float atten)
        {
            return _OutlineColor;
        }

        void vert(inout appdata_full v)
        {
            v.vertex.xyz = v.vertex.xyz + v.normal.xyz * (_OutlineWeight / 1000);
        }
        ENDCG

        cull back
        CGPROGRAM
        #pragma surface surf Lambert noambient
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
        };

        sampler2D _MainTex;

        UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 diffTex = tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = diffTex.rgb;
            o.Alpha = diffTex.a;
        }

        ENDCG
    }
    FallBack "Diffuse"
}
  1. LimLight 이용하기

업로드중..

업로드중..

Lambert 붙이기

업로드중..

이하 전체 소스

Shader "Apply/FresnelOutlineShader"
{
	Properties
	{
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_OutlineColor ("Outline Color", Color) = (0, 0, 0, 1)
		_OutlineWeight ("Outline Weight", Range(0.1, 0.4)) = 0.3
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 200

		CGPROGRAM
		#pragma surface surf Fresnel fullforwardshadows
		#pragma target 3.0

		struct Input
		{
			float2 uv_MainTex;
		};

		sampler2D _MainTex;
		fixed4 _OutlineColor;
		float _OutlineWeight;

		UNITY_INSTANCING_BUFFER_START(Props)
		UNITY_INSTANCING_BUFFER_END(Props)

		void surf (Input IN, inout SurfaceOutput o)
		{
			fixed4 diffColor = tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = diffColor.rgb;
			o.Alpha = diffColor.a;
		}

		float4 LightingFresnel(inout SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
		{
			// Lambert
			float fNDotL = saturate(dot(s.Normal, lightDir)) * 0.5 + 0.5;

			// Diffuse
			float4 diffColor;
			diffColor.rgb = s.Albedo * fNDotL * _LightColor0.rgb * atten;

			// Outline
			float lim = abs(dot(s.Normal, viewDir));
			if(lim > _OutlineWeight)
			{
				lim = 1;
			}
			else
			{
				lim = -1;
			}

			float4 result;
			result.rgb = diffColor.rgb * lim;
			result.a = s.Alpha;
			return result;
		}

		ENDCG
	}
	FallBack "Diffuse"
}

카툰 효과를 내기 위해 그림자를 그라데이션이 아닌 층으로 만들기

업로드중..
업로드중..

Shader "Apply/ToonShader"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpTex ("Bump Map", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Toon noambient
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpTex;
        };

        sampler2D _MainTex;
        sampler2D _BumpTex;

        UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 diffColor = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = diffColor.rgb;
            o.Normal = UnpackNormal(tex2D(_BumpTex, IN.uv_BumpTex));
            o.Alpha = diffColor.a;
        }

        float4 LightingToon(SurfaceOutput s, float3 lightDir, float atten)
        {
            float3 diffColor = s.Albedo * _LightColor0.rgb * atten;
            float nDotL = dot(s.Normal, lightDir) * 0.5 + 0.5;
            nDotL = nDotL * 5;
            nDotL = ceil(nDotL) / 5;

            float4 result;
            result.rgb = nDotL * diffColor;
            result.a = s.Alpha;
            return result;
        }
        ENDCG
    }
    FallBack "Diffuse"
}
profile
게임 개발자 지망생, 유니티 공부중!

0개의 댓글