Unity 2D Sprite becomes invisible when applying custom material

Unity 2D Sprite becomes invisible when applying custom material


I posted this on stackoverflow, and they recommended I try my luck here.
I’ve recently picked up unity and I’m messing around in 2D, so I might be missing something basic. But I’ve been trying to apply a material with a custom shader to sprites, and whenever I apply it, it turns the sprite invisible.
The custom shader code comes from here: https://github.com/bricevdm/FogSprites/blob/master/Assets/Sprites-DiffuseWithFog.shader, and here is what it looks like:
Shader “Sprites/Diffuse with Fog”
{
Properties
{
[PerRendererData] _MainTex (“Sprite Texture”, 2D) = “white” {}
_Color (“Tint”, Color) = (1,1,1,1)
[MaterialToggle] PixelSnap (“Pixel snap”, Float) = 0
[HideInInspector] _RendererColor (“RendererColor”, Color) = (1,1,1,1)
[HideInInspector] _Flip (“Flip”, Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex (“External Alpha”, 2D) = “white” {}
[PerRendererData] _EnableExternalAlpha (“Enable External Alpha”, Float) = 0
}

SubShader
{
Tags
{
“Queue”=”Transparent”
“IgnoreProjector”=”True”
“RenderType”=”Transparent”
“PreviewType”=”Plane”
“CanUseSpriteAtlas”=”True”
}

Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha

CGPROGRAM
#pragma surface surf Lambert vertex:vert nolightmap nodynlightmap keepalpha noinstancing finalcolor:applyFog
#pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma multi_compile_fog
#include “UnitySprites.cginc”

struct Input
{
float2 uv_MainTex;
fixed4 color;
float fogCoord;
};

void vert (inout appdata_full v, out Input o)
{
v.vertex.xy *= _Flip.xy;

#if defined(PIXELSNAP_ON)
v.vertex = UnityPixelSnap (v.vertex);
#endif

UNITY_INITIALIZE_OUTPUT(Input, o);

o.color = v.color * _Color * _RendererColor;
//o.fogCoord = UnityObjectToClipPos(v.vertex).z;
UNITY_TRANSFER_FOG(o, UnityObjectToClipPos(v.vertex));
}

void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = SampleSpriteTexture (IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb * c.a;
o.Alpha = c.a;
}

void applyFog (Input IN, SurfaceOutput o, inout fixed4 color)
{
// apply fog
UNITY_APPLY_FOG(IN.fogCoord, color.rgb);

color.rgb *= o.Alpha;
}

ENDCG
}

//Fallback “Transparent/VertexLit”
}

I’m not sure if I’m not applying it correctly. I created a standard surface shader, added a 2D light sprite, and have been manually dragging the material onto the sprites in the scene. I’ve also tried changing it directly in the sprite renderer but it gives the same effect.
Here is what it looks like when I try to apply the material

Thanks in advance for any advice yall have, and let me know if I need to provide any additional info!



Source link