Skip to content

Commit 3ed1fe5

Browse files
committed
Test for gles20
1 parent 9003913 commit 3ed1fe5

5 files changed

Lines changed: 34 additions & 6 deletions

File tree

Runtime/Scripts/MeshAnimator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class MeshAnimator : MonoBehaviour
1919
private void Awake()
2020
{
2121
_propertyBlock = new MaterialPropertyBlock();
22+
23+
MeshCache.GenerateSecondaryUv(this.meshRenderer.GetComponent<MeshFilter>().sharedMesh);
2224
}
2325

2426
[PublicAPI]

Runtime/Scripts/MeshCache.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace CodeWriter.MeshAnimation {
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public static class MeshCache {
6+
private static readonly HashSet<Mesh> CachedUv = new HashSet<Mesh>();
7+
8+
public static void GenerateSecondaryUv(Mesh mesh) {
9+
if (CachedUv.Contains(mesh)) {
10+
return;
11+
}
12+
13+
CachedUv.Add(mesh);
14+
15+
var uvs = new Vector2[mesh.vertexCount];
16+
for (int i = 0; i < uvs.Length; i++) {
17+
uvs[i] = new Vector2(1f * i, 0);
18+
}
19+
20+
mesh.SetUVs(1, uvs);
21+
}
22+
}
23+
}

Runtime/Scripts/MeshCache.cs.meta

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

Runtime/Shaders/Mobile-Diffuse-MeshAnimation.shader

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Shader "Mobile/Diffuse (Mesh Animation)" {
1616
CGPROGRAM
1717
#pragma surface surf Lambert noforwardadd vertex:vert
1818
#pragma multi_compile_instancing
19-
#pragma target 3.5
19+
#pragma target 2.5
2020
#pragma require samplelod
2121

2222
sampler2D _MainTex;
@@ -36,8 +36,8 @@ Shader "Mobile/Diffuse (Mesh Animation)" {
3636
float4 vertex : POSITION;
3737
float3 normal : NORMAL;
3838
float2 texcoord : TEXCOORD0;
39+
float2 vertcoord: TEXCOORD1;
3940
float4 color : COLOR0;
40-
uint vertexId : SV_VertexID;
4141
UNITY_VERTEX_INPUT_INSTANCE_ID
4242
};
4343

@@ -53,7 +53,7 @@ Shader "Mobile/Diffuse (Mesh Animation)" {
5353

5454
float progress = (_Time.y - t.w) * t.z;
5555
float progress01 = lerp(saturate(progress), frac(progress), looping);
56-
float2 coords = float2(0.5 + v.vertexId, 0.5 + t.x + progress01 * t.y) * _AnimTex_TexelSize.xy;
56+
float2 coords = float2(0.5 + v.vertcoord.x, 0.5 + t.x + progress01 * t.y) * _AnimTex_TexelSize.xy;
5757
float4 position = tex2Dlod(_AnimTex, float4(coords, 0, 0)) * _AnimMul + _AnimAdd;
5858

5959
v.vertex = float4(position.xyz, 1.0);

Runtime/Shaders/Unlit-MeshAnimation.shader

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#pragma fragment frag
2424
#pragma multi_compile_fog
2525
#pragma multi_compile_instancing
26-
#pragma target 3.5
26+
#pragma target 2.5
2727
#pragma require samplelod
2828

2929
#include "UnityCG.cginc"
@@ -32,7 +32,7 @@
3232
{
3333
float4 vertex : POSITION;
3434
float2 uv : TEXCOORD0;
35-
uint vertexId : SV_VertexID;
35+
float2 vertcoord: TEXCOORD1;
3636
UNITY_VERTEX_INPUT_INSTANCE_ID
3737
};
3838

@@ -65,7 +65,7 @@
6565

6666
float progress = (_Time.y - t.w) * t.z;
6767
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;
68+
float2 coords = float2(0.5 + v.vertcoord.x, 0.5 + t.x + progress01 * t.y) * _AnimTex_TexelSize.xy;
6969
float4 position = tex2Dlod(_AnimTex, float4(coords, 0, 0)) * _AnimMul + _AnimAdd;
7070

7171
v.vertex = float4(position.xyz, 1.0);

0 commit comments

Comments
 (0)