Need help with Sprite shadow shader!!!
Hello everyone! I'm having a problem with my project. Again shaders are killing me XD So I need a Sprite shader that is: - Unlit - Transparent ( so for example the image is a blue circule with the rest with alpha = 0, the alpha part needs to be transparent) - Only recieve shadows - It needs to have a property color that allow me to change the overall alpha to make a fading effect (shown in the image 3 as a gif).
I have a shader that accomplishes everything except the fading effect. I was wondering if someone could fix this one for me since I have 0 knowledge of shaders XS.
The Sprite/Default shader accomplishes everything except receiving shadows like image 1 (shown in image 2).
The one I already have was given to me by another user.
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UnlitShadows/UnlitShadowReceive" {
Properties{
_MainTex("Base (RGB)", 2D) = "white" {}
_CutOff("Cut off", float) = 0.1
}
SubShader{
Pass{
Tags{ "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#include "AutoLight.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
uniform float _CutOff;
struct v2f {
float4 pos : SV_POSITION;
LIGHTING_COORDS(0,1)
float2 uv : TEXCOORD2;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
fixed4 frag(v2f i) : COLOR
{
float4 color = tex2D(_MainTex, i.uv);
if(color.a < _CutOff) discard;
float attenuation = LIGHT_ATTENUATION(i);
return color * attenuation;
}
ENDCG
}
Pass{
Blend One One
Tags{ "LightMode" = "ForwardAdd" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_fwdadd_fullshadows
#include "AutoLight.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
uniform float _CutOff;
struct v2f {
float4 pos : SV_POSITION;
LIGHTING_COORDS(0,1)
float2 uv : TEXCOORD2;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
fixed4 frag(v2f i) : COLOR
{
float4 color = tex2D(_MainTex, i.uv);
if(color.a < _CutOff) discard;
float attenuation = LIGHT_ATTENUATION(i);
return color * attenuation;
}
ENDCG
}
}
Fallback "VertexLit"
}
image 1: Provided shader - dont work with fading effect.
image 2: Sprite Default shader - dont work with shadows
image 3: Fading effect using Sprite Default
So basically I need to transform the Sprite / Default shader so it can receive shadows, without changing its behaviour
Your answer
Follow this Question
Related Questions
How to continue material between sprites. 1 Answer
Sprite Material Problem 0 Answers
2D Shadows with 3D effect 0 Answers
How can I remove shadows from alpha cutout? 1 Answer
Lightweight render pipeline causing sprites to render black 1 Answer