스토리지

[5.7] 외곽선 본문

Unity/Shader

[5.7] 외곽선

ljw4104 2021. 5. 7. 12:16

결과

 

Member 특성
float4 vertex : POSITION Vertex 위치
float4 tangent : TANGENT Normal Map에서 사용
float3 normal : NORMAL Vertex의 Normal 값
float4 texcoord : TEXCOORD0 첫번째 UV좌표
float4 texcoord1 : TEXCOORD1 두번째 UV좌표
float4 texcoord2 : TEXCOORD2 세번째 UV좌표
float4 texcoord3 : TEXCOORD3 네번째 UV좌표
fixed4 color : COLOR Vertex Color

 

Cull Back / Front / Off

  • Cull : 특정한 부분을 렌더링하지 않는 기능
    • Back : 시선 뒷부분을 렌더링하지 않음
    • Front : 시점 방향을 렌더링하지 않음'
    • Off : 모든 면을 렌더링 (특수한 경우에 사용)

*참고 : docs.unity3d.com/kr/530/Manual/SL-CullAndDepth.html

 

유니티 - 매뉴얼: ShaderLab: Culling & Depth Testing

ShaderLab: Culling & Depth Testing 컬링은 시점과 반대편을 향한 폴리곤을 렌더링하지 않는 최적화입니다. 모든 다각형은 앞면과 뒷면이 있습니다. 컬링은 오브젝트의 대부분이 닫혀있는 사실을 이용합

docs.unity3d.com

void vert (inout appdata_full) 이라는 함수를 사용하여 Vertex를 조정

 

Shader "Custom/Test"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Stroke ("Stroke", Float) = 1
        _StrokeColor ("Stroke Color", Color) = (0,0,0,0)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        Cull Front
        //카메라에 보이지 않는 부분을 렌더링하지 않음.
        //Back - 반대 면의 폴리곤을 렌더링하지 않음

        CGPROGRAM

        //앞면 뒤집고 빛을 끄고 Normal 방향으로 Vertex크기를 늘려줌.
        #pragma surface surf _NoLight vertex:vert noshadow noambient 

        sampler2D _MainTex;
        float _Stroke;
        float4 _StrokeColor;

        struct Input
        {
            float4 color:COLOR;
        };

        void vert(inout appdata_full v)
        {
            v.vertex.xyz +=  v.normal.xyz * _Stroke / 100;

        }

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

        float4 Lighting_NoLight(SurfaceOutput s, float3 lightDir, float atten)
        {
            return float4(_StrokeColor.rgb, 1);
        }
        ENDCG

        Cull Back    
        //2Pass
        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"
}
Comments