イラスト、モデリング、Unity、VR関連

unityとかblenderとかvr関連の作業メモ

shader Boxの中に入ったものだけ黒くするシェーダ

f:id:arumogina:20190612050912p:plain

 

Shader "Custom/ShadowPic" {
	SubShader{
		Tags {"RenderType"="Transparent"}
		GrabPass { "_GrabPassTexture" }

		Stencil {
			Ref 1
			Comp always
			Pass replace
		}

		Cull Front
		Lighting Off
		CGPROGRAM
		#pragma surface surf Lambert alpha
		struct Input {
				fixed3 Albedo;
		};
		void surf (Input IN, inout SurfaceOutput o) {
				o.Alpha = 0;
		}
		ENDCG

		Stencil {
			Ref 1
			Comp Equal
		}

		Cull Back
		Lighting Off
		CGPROGRAM
		#pragma surface surf Lambert alpha
		struct Input {
				fixed3 Albedo;
		};
		void surf (Input IN, inout SurfaceOutput o) {
			discard;
		}
		ENDCG

		Stencil {
			Ref 1
			Comp NotEqual
		}

		Cull Back
		Lighting Off
		CGPROGRAM
		#pragma surface surf Lambert alpha
		struct Input {
				fixed3 Albedo;
		};
		void surf (Input IN, inout SurfaceOutput o) {
			o.Albedo = float3(0,0,0);
			o.Alpha = 1;
		}
		ENDCG
	}
	FallBack "Diffuse"
}