- Home /
Question by
DTownTony · Dec 11, 2019 at 06:09 PM ·
shadershadowstransparency
Is there a way to have a transparent vertex shader recieve and cast Shadows?
I'm an extreme novice when it comes to Shaders but have cobbled together this shader that allows me to have a texture slowly blend to another one. This version has transparency (from the png files) but will not cast or receive any shadows. Any help would be greatly appreciated.
Shader "Unlit/Blend_Textures_Alpha"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_SecondTex("2nd Texture", 2D) = "white" {}
_LerpValue("Transition Float", Range (0,2)) = 0
_SColor("Shadow Color", Color) = (0.195,0.195,0.195,1.0)
_CutOff("Cut off", float) = 0.1
}
SubShader
{
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
LOD 200
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "Lighting.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _SecondTex;
float4 _SecondTex_ST;
float _LerpValue;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = lerp(tex2D(_MainTex, i.uv),tex2D(_SecondTex, i.uv),_LerpValue);
return col;
}
ENDCG
}
//Shadow Casting
Pass
{
Tags {"LightMode" = "ShadowCaster" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
struct v2f {
V2F_SHADOW_CASTER;
};
v2f vert(appdata_base v)
{
v2f o;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float4 frag(v2f i) : SV_Target
{
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
}
Comment