Emissive Blended Decal
Hey All,
I've been trying to get an emissive blended decal with a texture to define the emissive map, color and intensity settings working.
I've gotten it working so far in the sense that the decal now accepts an emissive map, emits light and sets intensity and color properly. My problem now is that I've lost the z-fighting fix and transparency of the shader I based this on. The original BlendedDecal is from the BootCamp demo I believe. Thanks in advance all!
I'm not using the standard shader as a cutout because of z-fighting and my target is WebGL.
Shader "Custom/EmissiveBlendedDecal"
{
Properties
{
_Color ("Tint", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
_Emissive("Emissive", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (1,1,1,1)
_EmissiveIntensity("EmissiveIntensity", Range(0,10) ) = 0.5
}
SubShader
{
Lighting On
ZTest LEqual
ZWrite Off
Tags { "Queue" = "Transparent" }
LOD 250
Pass
{
Alphatest Greater 0
Blend SrcAlpha OneMinusSrcAlpha
Offset -1, -1
SetTexture [_MainTex]
{
ConstantColor[_Color]
Combine texture * constant
}
}
CGPROGRAM
#pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap halfasview
inline fixed4 LightingMobileBlinnPhong(SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
{
fixed4 c;
c.rgb = (s.Albedo * _LightColor0.rgb + _LightColor0.rgb) * (atten*2);
c.a = 0.0;
return c;
}
sampler2D _MainTex;
sampler2D _Emissive;
float4 _EmissiveColor;
float _EmissiveIntensity;
struct Input
{
float2 uv_MainTex;
float2 uv_Emissive;
};
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a;
float4 Tex2D1=tex2D(_Emissive,(IN.uv_Emissive.xyxy).xy);
float4 Multiply0=Tex2D1 * _EmissiveColor;
float4 Multiply2=Multiply0 * _EmissiveIntensity.xxxx;
o.Emission = Multiply2;
}
ENDCG
}
FallBack "Custom/BlendedDecal"
}
Edit: I wrote another shader based on the decal example in the manual, here is the result posted below if anyone else is looking for a setup like I was.
Edit 2: Added a toggle for emission so it can be toggled via script.
Shader "Custom/EmissiveDecal"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Emissive("Emissive", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (1,1,1,1)
_EmissiveIntensity("EmissiveIntensity", Range(0,10) ) = 0.5
[Toggle(EMISSION)]
_ToggleEmission ("Emission", Float) = 0
}
SubShader
{
Tags
{
"RenderType"="Opaque"
"Queue"="Geometry+1"
"ForceNoShadowCasting"="True"
}
LOD 200
Offset -1, -1
CGPROGRAM
#pragma surface surf Lambert decal:blend
#pragma shader_feature EMISSION
sampler2D _MainTex;
sampler2D _Emissive;
float4 _EmissiveColor;
float _EmissiveIntensity;
struct Input
{
float2 uv_MainTex;
float2 uv_Emissive;
};
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
#ifdef EMISSION
float4 Tex2D1=tex2D(_Emissive,(IN.uv_Emissive.xyxy).xy);
float4 Multiply0=Tex2D1 * _EmissiveColor;
float4 Multiply2=Multiply0 * _EmissiveIntensity.xxxx;
o.Emission = Multiply2;
#endif
}
ENDCG
}
}