본문 바로가기

Unity

Shader Cull off + Normal Map

2D/3D 그래픽 작업물은 제가 아닌 다른 팀원 분들의 작업물입니다! 이용을 금지합니다!

 

2D 우물만 파던 나에게 갑자기 쉐이더의 난관이 찾아왔다. 3D 작업을 도맡는 건 처음이라 솔직히 말도 많고 탈도 많을 것 같지만.. 이 또한 배움이니까...

아무튼!

이 초짜는 어디서 막혔나?

모델러 팀원님이 유니티에서 실행하신 결과 안쪽이 안보인다며 도움을 요청하셨다.

하지만 나도 3D가 처음이라 정말 처음에는 청천벽력같은 소리여따...

 

이것저것 찾아본 결과, Unity에서는 Cull on이 기본 옵션이라고 한다. 당장에 Quad만 생각해도 밑면이 안보이게 구성되어 있다.

Cull off의 문제는 Shader에서 해결해야 한다. 즉! Shader script를 만져야 한다는 뜻이다. 하지만 두려워하지 말자! 한 줄이면 끝이다.

cull off

이 한 줄만 추가하면 된다. 

 

그래서 material에 shader를 추가하면...

ㅋㅋㅋ

cull off는 제대로 먹혔지만 normal map이 사라졌다.

그야... 우리가 만든 material에서는 normal map이 표시되지 않기 때문이다.

cull off가 적용되지 않은 원래의 meterial

 

cull off가 적용됐으나 normal map이 없는 새로운 material

 

그러면 shader script에서 inspector 창에 normal map을 추가할 수 있도록 해야 한다. 

 

▼ 참고 영상

https://www.youtube.com/watch?v=LDmByHOa65I

Shader "Custom/CulloffShader"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _NormalTex("Normal Texture", 2D) = "bump"{}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        cull off

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex, _NormalTex;

        struct Input
        {
            float2 uv_MainTex, uv_NormalTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            fixed4 n = tex2D(_NormalTex, IN.uv_NormalTex);

            o.Albedo = c.rgb;
            o.Normal = UnpackNormal(n);
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

이렇게 하면 material이 이렇게 뜬다.

결과물은

정말 잘 나왔다. 광명!

흑... 쉐이더 교재를 사야겠다... 살짝 이런 것도 몰라도 되나?! 싶을 정도로 간결해서 놀랐다. ...

'Unity' 카테고리의 다른 글

애니메이션으로 알파값 조정  (0) 2023.10.31
블러 사용하기(2D, 3D 무관)  (0) 2023.10.31
게임 종료/Play 모드 종료  (0) 2023.10.30
애니메이션 이벤트  (0) 2023.09.27
버튼 클릭이 안 돼요!!  (0) 2023.09.27