반응형

 

 

 

Stencil_Write(Mask)

Shader "Stencil/Sh_StencilWrite"
{
    Properties
    {
		_Color("Color", Color) = (1,1,1,1)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
			Stencil
			{
				Ref 2
				Comp Always
				Pass Replace

			}
			//Blend Zero One
			ZWrite Off


            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
         

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };


			fixed4 _Color;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex); 
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
				return _Color;
            }
            ENDCG
        }
    }
}

 

 

Stencil_Read

Shader "Stencil/Sh_StencilRead"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

		Stencil
		{
			Ref 2
			Comp Equal
		}

        CGPROGRAM
      
        #pragma surface surf Standard fullforwardshadows
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = dot(c.rgb, float3(0.333f,0.333f,0.333f));
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
			
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

반응형

'Unity > Shader & VFX' 카테고리의 다른 글

[Tutorial] Hexagon Barrier  (0) 2020.02.14
Vertex Fragment - Shadow Receive & Cast  (0) 2020.02.12
Unity Normal Map 구현 & 분석  (6) 2020.02.05
Hexagon Barrier  (1) 2020.01.31
[Unity Shader Effect] Cosmic Shader - ScreenPos UV  (1) 2020.01.08

WRITTEN BY
CatDarkGame
Technical Artist dhwlgn12@gmail.com

,