- Home /
Custom Sprite Shader Ignore Light
Hi!
The "Sprite-Default" shader used for 2D sprites ignores the built-in light.
I have "written" (modified a shader I found online) a custom shader that outlines a sprite and the outlining works well.
However, this custom shaders does not ignore the built-in light, which means the sprite is rendered differently from the other sprites that ignore the light.
What do I need to add to my custom shader to make it ignore the built in light?
I have looked a the Sprite-Default shader and I can't figure out what to do.
This is how my custom shader looks;
Shader "Custom/Outline2D" {
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_OutLineSpread ("Outline Spread", Range(0,0.012)) = 0.007
_Alpha ("Alpha", float) = 1
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite On Blend One OneMinusSrcAlpha Cull Off
LOD 110
CGPROGRAM
#pragma surface surf Lambert alpha
struct Input
{
float2 uv_MainTex;
fixed4 color : COLOR;
};
sampler2D _MainTex;
float _OutLineSpread;
float _Alpha;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 mainColor =
(tex2D(_MainTex, IN.uv_MainTex+float2(_OutLineSpread,_OutLineSpread))
+ tex2D(_MainTex, IN.uv_MainTex+float2(-_OutLineSpread,-_OutLineSpread))
+ tex2D(_MainTex, IN.uv_MainTex+float2(-_OutLineSpread,_OutLineSpread))
+ tex2D(_MainTex, IN.uv_MainTex+float2(_OutLineSpread,-_OutLineSpread)))
* fixed4(_Color.r, _Color.g, _Color.b, _Alpha);
mainColor = fixed4(1,1,1, mainColor.a);
fixed4 addcolor = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
if(addcolor.a > _Alpha - 0.05){
mainColor = addcolor;}
o.Albedo = mainColor.rgb;
o.Alpha = mainColor.a;
}
ENDCG
}
}
Answer by Dreach913 · Mar 13, 2015 at 04:39 PM
Have you tried
Lighting Off
Maybe thats what you are missing. I don't see it where you describe your cull mode.
Your answer
Follow this Question
Related Questions
"Interesting" Shader 2 Answers
Unity 3d Lights, Shadows and material of objects? 1 Answer
Glass shadow problem 3 Answers
Odd shadow effect, help! 1 Answer
Marmoset + Unity 4 vs Unity 5 Lighting 0 Answers