Skip to content

Commit f705043

Browse files
committed
Add Unlit shader
1 parent e3a9607 commit f705043

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Shader "Unlit/Unlit (Mesh Animation)"
2+
{
3+
Properties
4+
{
5+
_MainTex ("Texture", 2D) = "white" {}
6+
7+
[Header(Mesh Animation)]
8+
_AnimTex ("Animation", 2D) = "white" {}
9+
_AnimMul ("Animation Bounds Size", Vector) = (1, 1, 1, 0)
10+
_AnimAdd ("Animation Bounds Offset", Vector) = (0, 0, 0, 0)
11+
[PerRendererData] _AnimTime ("Animation Time", Vector) = (0, 1, 1, 0) /* (x: start, y: length, z: speed, w: startTime) */
12+
[PerRendererData] _AnimLoop ("Animation Loop", Float) = 1
13+
}
14+
SubShader
15+
{
16+
Tags { "RenderType"="Opaque" }
17+
LOD 100
18+
19+
Pass
20+
{
21+
CGPROGRAM
22+
#pragma vertex vert
23+
#pragma fragment frag
24+
#pragma multi_compile_fog
25+
#pragma multi_compile_instancing
26+
#pragma target 3.0
27+
#pragma require samplelod
28+
29+
#include "UnityCG.cginc"
30+
31+
struct appdata
32+
{
33+
float4 vertex : POSITION;
34+
float2 uv : TEXCOORD0;
35+
uint vertexId : SV_VertexID;
36+
UNITY_VERTEX_INPUT_INSTANCE_ID
37+
};
38+
39+
struct v2f
40+
{
41+
float2 uv : TEXCOORD0;
42+
UNITY_FOG_COORDS(1)
43+
float4 vertex : SV_POSITION;
44+
};
45+
46+
sampler2D _MainTex;
47+
float4 _MainTex_ST;
48+
sampler2D _AnimTex;
49+
float4 _AnimTex_TexelSize;
50+
51+
float4 _AnimMul;
52+
float4 _AnimAdd;
53+
54+
UNITY_INSTANCING_BUFFER_START(Props)
55+
UNITY_DEFINE_INSTANCED_PROP(float4, _AnimTime)
56+
UNITY_DEFINE_INSTANCED_PROP(float, _AnimLoop)
57+
UNITY_INSTANCING_BUFFER_END(Props)
58+
59+
v2f vert (appdata v)
60+
{
61+
UNITY_SETUP_INSTANCE_ID(v);
62+
63+
float4 t = UNITY_ACCESS_INSTANCED_PROP(Props, _AnimTime);
64+
float looping = UNITY_ACCESS_INSTANCED_PROP(Props, _AnimLoop);
65+
66+
float progress = (_Time.y - t.w) * t.z;
67+
float progress01 = lerp(saturate(progress), frac(progress), looping);
68+
float2 coords = float2(0.5 + v.vertexId, 0.5 + t.x + progress01 * t.y) * _AnimTex_TexelSize.xy;
69+
float4 position = tex2Dlod(_AnimTex, float4(coords, 0, 0)) * _AnimMul + _AnimAdd;
70+
71+
v.vertex = float4(position.xyz, 1.0);
72+
73+
v2f o;
74+
o.vertex = UnityObjectToClipPos(v.vertex);
75+
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
76+
UNITY_TRANSFER_FOG(o,o.vertex);
77+
return o;
78+
}
79+
80+
fixed4 frag (v2f i) : SV_Target
81+
{
82+
fixed4 col = tex2D(_MainTex, i.uv);
83+
UNITY_APPLY_FOG(i.fogCoord, col);
84+
return col;
85+
}
86+
ENDCG
87+
}
88+
}
89+
}

Runtime/Shaders/Unlit-MeshAnimation.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)