Vertex unlit on mobile

Hello!

I’m trying to get vertex unlit coloring working on mobile devices. The shader below does work in the editor, but I am absolutely new to shaders and have no idea on how to make it work on mobile devices as well.

Shader "Vertex Color Unlit" {
	Properties {
		_MainTex ("Texture", 2D) = "white" {}
	}
	
	Category {
		Tags { "Queue"="Geometry" }
		Lighting Off
		BindChannels {
			Bind "Color", color
			Bind "Vertex", vertex
			Bind "TexCoord", texcoord
		}
		
		SubShader {
			Pass {
				SetTexture [_MainTex] {
					Combine texture * primary DOUBLE
				}
			}
		}
	}
}

I don’t know how to debug shaders on mobile devices, but I could sure use some help!

Thanks a lot!

Looking at the shader, it should work on mobile GPUs. What doesn’t work?

Well, that’s the thing I don’t get. When I apply another shader to the material, it does work.

I have another script which runs through all the vertexes in all the models and applies a different color to each vertex. Maybe that is messing things up? (But then again, why would a different shader still work?

That vertex color script:

public class TriangleColoring : MonoBehaviour 
{
	public Color baseColor;
	public float colorRange = 0.3f;
	
	// Use this for initialization
	void Start () 
	{
		ReColor();
	}
	
	public void ReColor()
	{
		
		foreach(MeshFilter filter in transform.GetComponentsInChildren<MeshFilter>())
		{
			Mesh mesh = filter.mesh;
			Vector3[] vertices = mesh.vertices;
			Color[] colors = new Color[vertices.Length];
	        int i = 0;
	        while (i < vertices.Length) {
				
				Color col = new Color(
					Mathf.Clamp(baseColor.r * Random.Range(1f-colorRange, 1f+colorRange), 0f, 1f),
					Mathf.Clamp(baseColor.g * Random.Range(1f-colorRange, 1f+colorRange), 0f, 1f),
					Mathf.Clamp(baseColor.b * Random.Range(1f-colorRange, 1f+colorRange), 0f, 1f), 
					1f);
				
	            colors[i] = col;
				
	            i++;
	        }
			
	        mesh.colors = colors;
		}
	}
}

You know what? After a day, nothing has changed and it suddenly works. Which is not good, because if It doesn’t work again I’ll have no idea where the problem is.

So the shader now does work on mobile. I’ll get back here if I’ve found the solution!

Thanks anyway Aras!

Alright, after another day of messing around, I found out the problem: the shader wasn’t added to any of the materials while the game was being compiled, which caused the shader not to be compiled at all and to be missing from the game on mobile.

What is so frustrating about this is that the game did not give any errors or warnings anywhere. It cost me a day :confused: