system
January 1, 2017, 9:26pm
1
Hey there!
I’m trying to make a shadow for my game but somehow none of the shaders are seem to be working for what I need…
Here is what I get with a gradient texture and with an Unlit/Transparent Cutout shader:
I tried http://answers.unity3d.com/questions/1195044/gradient-transparent.html this shader here, but the results are nearly the same:
What could be the problem?
Thank you for your replies in advance!
Namey5
January 23, 2017, 11:01am
2
Sorry, for some reason I didn’t get a notification for this thread until now. The following shader does what you require, keep in mind that it will only work if the UVs are set up properly.
Shader "Custom/Shadow Gradient"
{
Properties
{
_Color ("Color 1", Color) = (0,0,0,1)
_Color2 ("Color 2", Color) = (0,0,0,0)
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.uv, _MainTex);
return o;
}
fixed4 _Color;
fixed4 _Color2;
half4 frag (v2f i) : SV_Target
{
half col = tex2D (_MainTex, i.uv).r;
return lerp (_Color, _Color2, col);
}
ENDCG
}
}
}