﻿Shader "Custom/Magic" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_MaskTex("Transparency Mask", 2D) = "white" {}
		_Intensity("Intensity", Range(0, 10)) = 0.0
	}
	SubShader {
		Tags { "Queue"="Transparent" "RenderType"="Transparent" }
		
		LOD 200
		Blend SrcAlpha OneMinusSrcAlpha

		Cull Off

		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		#pragma surface surf Standard fullforwardshadows alpha:fade
		// Use shader model 3.0 target, to get nicer looking lighting
		#pragma target 3.0

		sampler2D _MainTex;
		sampler2D _MaskTex;

		struct Input {
			float2 uv_MainTex;
			float2 uv_MaskTex;
		};

		half _Glossiness;
		half _Metallic;
		half _Intensity;
		fixed4 _EmissionColor;
		// 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.
		UNITY_INSTANCING_BUFFER_START(Props)
			UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
		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) * UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
			o.Albedo = c.rgb;
			// Emission takes the same color
			o.Emission = c.rgb * tex2D(_MainTex, IN.uv_MainTex).a * UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
			// Metallic and smoothness are always at minimum
			o.Metallic = 0;
			o.Smoothness = 0;
			// Alpha is mixed between the main and masking texture, if any, multiplied by the Intensity
			o.Alpha = c.a * tex2D(_MainTex, IN.uv_MainTex).a * tex2D(_MaskTex, IN.uv_MaskTex).a * _Intensity;
		}
		ENDCG
	}
	FallBack "Diffuse"
}
