I’ve just lately picked up Unity and I am messing round in 2D, so I is likely to be lacking one thing fundamental. I have been making an attempt to use a cloth with a customized shader to sprites, and each time I apply it, it turns the sprite invisible.
The customized shader code comes from right here: https://github.com/bricevdm/FogSprites/blob/grasp/Property/Sprites-DiffuseWithFog.shader, and here’s what it appears like:
Shader "Sprites/Diffuse with Fog"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Colour) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
[HideInInspector] _RendererColor ("RendererColor", Colour) = (1,1,1,1)
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex ("Exterior Alpha", 2D) = "white" {}
[PerRendererData] _EnableExternalAlpha ("Allow Exterior Alpha", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Clear"
"IgnoreProjector"="True"
"RenderType"="Clear"
"PreviewType"="Airplane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Mix One OneMinusSrcAlpha
CGPROGRAM
#pragma floor 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
#embody "UnitySprites.cginc"
struct Enter
{
float2 uv_MainTex;
fixed4 shade;
float fogCoord;
};
void vert (inout appdata_full v, out Enter o)
{
v.vertex.xy *= _Flip.xy;
#if outlined(PIXELSNAP_ON)
v.vertex = UnityPixelSnap (v.vertex);
#endif
UNITY_INITIALIZE_OUTPUT(Enter, o);
o.shade = v.shade * _Color * _RendererColor;
//o.fogCoord = UnityObjectToClipPos(v.vertex).z;
UNITY_TRANSFER_FOG(o, UnityObjectToClipPos(v.vertex));
}
void surf (Enter IN, inout SurfaceOutput o)
{
fixed4 c = SampleSpriteTexture (IN.uv_MainTex) * IN.shade;
o.Albedo = c.rgb * c.a;
o.Alpha = c.a;
}
void applyFog (Enter IN, SurfaceOutput o, inout fixed4 shade)
{
// apply fog
UNITY_APPLY_FOG(IN.fogCoord, shade.rgb);
shade.rgb *= o.Alpha;
}
ENDCG
}
//Fallback "Clear/VertexLit"
}
I am undecided if I am making use of it accurately. I created a regular floor shader, added a 2D mild sprite, and have been manually dragging the fabric onto the sprites within the scene. I’ve additionally tried altering it straight within the sprite renderer but it surely provides the identical impact.
Here’s what it appears like when I attempt to apply the fabric