Get it on Google Play


Wm뮤 :: 스텐실

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2021. 1. 20. 09:17 Unity/shader

지우개

Shader "ahzkwid/Stencil/Invisible" {
    Properties {
        _MainTex ("MainTex", 2D) = "white" {}
        _Color ("Main Color", Color) = (1,1,1,1)
        _Stencil_Ref ("Stencil ID", int) = 3
        //_Cutoff("Cutout offset", Range(0, 1)) = 0.001
    }
    SubShader {
        Tags { 
        "RenderType"="Opaque" 
        "Queue"="Transparent"
        }
        
        //ColorMask RGB
        //Cull back
        //ZWrite off
        //ZTest Always
        Cull back
        ZWrite off
        //AlphaTest Greater [_Cutoff]
        //ZTest Always
        Stencil {
                //Ref 3
                Ref [_Stencil_Ref]
                Comp Always
                Pass Replace
        }
        Pass{
        	blend srcalpha oneminussrcalpha
            
	        SetTexture [_MainTex] 
	        {
	        	//Combine texture
	        	//Combine texture lerp(texture) constant
                //Combine texture* primary DOUBLE, texture* constant
                Combine texture* primary
	        }
	        SetTexture [_MainTex] 
	        {
	        	ConstantColor [_Color]
                Combine previous* constant
	        }
        }

    } 
}

 

 

지워질 대상

Shader "ahzkwid/Stencil/InvisibleTarget" {
    Properties {
        _MainTex ("MainTex", 2D) = "white" {}
        _Color ("Main Color", Color) = (1,1,1,1)
        _Stencil_Ref ("Stencil ID", int) = 3
        //_Stencil_Comp ("Stencil Comp", int) = 6
        //_Stencil_Pass ("Stencil OP", int) = 2
    }
    SubShader {
        Tags { 
        "RenderType"="Transparent" 
        "Queue"="Transparent"
        }

        //ColorMask RGB
        //Cull back
        //ZWrite off
        //ZTest Always
        Cull back
        ZWrite off
        //ZTest Always
        Stencil {
                //Ref 3
                Ref [_Stencil_Ref]
                Comp NotEqual
                Pass Replace
                //Comp [_Stencil_Comp]
                //Pass [_Stencil_Pass]
        }
        Pass{
        	blend srcalpha oneminussrcalpha
            
	        SetTexture [_MainTex] 
	        {
	        	//Combine texture
	        	//Combine texture lerp(texture) constant
                //Combine texture* primary DOUBLE, texture* constant
                Combine texture* primary
	        }
	        SetTexture [_MainTex] 
	        {
	        	ConstantColor [_Color]
                Combine previous* constant
	        }
        }

    } 
}

 

 

컷아웃 지우개

Shader "ahzkwid/Stencil/InvisibleCutout" {
    Properties {
        _MainTex ("MainTex", 2D) = "white" {}
        _Color ("Main Color", Color) = (1,1,1,1)
        _Stencil_Ref ("Stencil ID", int) = 3
        //_Cutoff("Cutout offset", Range(0, 1)) = 0.001
        //_Stencil_Comp ("Stencil Comp", int) = 0
        //_Stencil_Pass ("Stencil OP", int) = 2
    }
    SubShader {
        
Tags { "Queue" = "AlphaTest"
//"RenderType" = "TransparentCutout"
 "RenderType" = "Transparent" 
"IgnoreProjector" = "True" }
        //ColorMask RGB
        //Cull back
        //ZWrite off
        //ZTest Always
        Cull back
        ZWrite off
        //AlphaTest Greater [_Cutoff]
        AlphaTest Greater 0.001
        //ZTest Always
        Stencil {
                //Ref 3
                Ref [_Stencil_Ref]
                Comp Always
                Pass Replace
                //Comp [_Stencil_Comp]
                //Pass [_Stencil_Pass]
        }
        Pass{
        	blend srcalpha oneminussrcalpha

	        SetTexture [_MainTex] 
	        {
	        	//Combine texture
	        	//Combine texture lerp(texture) constant
                //Combine texture* primary DOUBLE, texture* constant
                Combine texture* primary
	        }
	        SetTexture [_MainTex] 
	        {
	        	ConstantColor [_Color]
                Combine previous* constant
	        }
        }

    } 
}

 

 

일반적으로는 컷아웃 지우개만 만들어서 아래걸 쓰면 된다

 

 

 

 

 

 

 

 

 

안쪽에 있는건 안보이게 하고 싶을때

 

원본

 

 

결과

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

마스크와 마스크 타겟

 

 

마스크

Always

Less

 

 

 

마스크 타겟

iD만 동일하면 된다

Equal

Keep

 

 

위 지우개로 마스크도 지울수 있다

아래는 예시 사진

빨강이 마스크고

파랑이 ID 4짜리 지우개

흰색이 마스크 타겟

 

 

 

Comp

0-Always

1-Never

2-Less

3-Equal

4-LEqual

5-Greater

6-NotEqual

7-GEqual

 

OP

0-Keep

1-Zero

2-Replace

3-IncrSat

4-DecrSat

5-Invert

6-IncrWrap

7-DecrWrap

posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입