// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Custom/Sprites/DefaultShadowFlatten"
{
Properties
{
[HideInInspector]_MainTex("Main Tex", 2D) = "white" {}
_RadiusX("_RadiusX", Range(0, 2)) = 1
_RadiusY("_RadiusY", Range(0, 2)) = 1
_AlphaX("_AlphaX", Range(0, 1)) = 0.5
_AlphaY("_AlphaY", Range(0, 1)) = 0.5
_ScaleY("_ScaleY", Range(0, 1)) = 0.5
_Offset("Offset", vector) = (0, 0, 0, 0)
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
float _AlphaX;
float _AlphaY;
float _RadiusX;
float _RadiusY;
float _ScaleY;
float4 _Offset;
float4 _MainTex_ST;
struct v2f
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
};
v2f vert_normal(appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
v2f vert_offset(appdata_base v)
{
v2f o;
float4x4 _RotMatrix = unity_ObjectToWorld;
_RotMatrix[0][3] = 0;
_RotMatrix[1][3] = 0;
_RotMatrix[2][3] = 0;
float4 vertexPos = mul(_RotMatrix, v.vertex);
vertexPos.x += _Offset.x * vertexPos.y + _Offset.x;
vertexPos.y += _Offset.y * vertexPos.y + _Offset.y;
vertexPos.z += _Offset.z * vertexPos.z + _Offset.z;
float3 tempPos = float3(unity_ObjectToWorld[0][3], unity_ObjectToWorld[1][3], unity_ObjectToWorld[2][3]);
vertexPos.xyz += tempPos;
o.pos = mul(UNITY_MATRIX_VP, vertexPos);
o.uv = v.texcoord;
return o;
}
float4 frag_normal(v2f i) : COLOR
{
float4 texcol = tex2D(_MainTex, i.uv);
return texcol;
}
float4 frag_color(v2f i) : COLOR
{
float4 color = tex2D(_MainTex, i.uv);
float x2 = (i.uv.x - 0.5) * (i.uv.x - 0.5) * _RadiusX * _AlphaX;
float y2 = (i.uv.y - 0.5) * (i.uv.y - 0.5) * _RadiusY * _AlphaY;
float alpha = (1 - (x2 + y2));
color *= float4(0, 0, 0, alpha);
return color;
}
ENDCG
SubShader
{
Tags{ "Queue" = "Transparent" }
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_offset
#pragma fragment frag_color
ENDCG
}
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_normal
#pragma fragment frag_normal
ENDCG
}
}
FallBack "Diffuse"
}
贴图阴影shader(扁平)
最新推荐文章于 2024-03-01 19:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)