- Home /
iOS simple shader does not work
Hi
I have been on this for days without any ideas come up. I wrote a very simply shader to draw a line using vertex.
Shader "Custom/LineShader" {
Properties { _Color ("Color", Color) = (1, 1, 1) }
SubShader { Color[_Color] Pass{} } }
And instantiate material with this shader
lineRenderer = line.AddComponent(LineRenderer);
var lineShader = Shader.Find("Custom/LineShader");
var lineMaterial = new Material(lineShader);
lineRenderer.material = lineMaterial;
lineRenderer.material.color = color;
These code work well on Editor (even with iOS platform switched on) but when deploying on iPad, all the line is just black no matter color i tried to set, i attach debugger and dont find any color property of this material. What happen? i think it should be very simple but it is not. Any recommendation would be so helpful now because i really out of idea. Thanks
Answer by Eric5h5 · Dec 06, 2012 at 04:15 AM
Unity does not include any resources that are not directly referenced, but referencing them by code doesn't count since there is no good way for Unity to tell. So you need to have the shader be used in a material that's used on an object in the scene, or else put the shader in the Resources folder, since everything in Resources is included in a build regardless of whether it's directly referenced or not.
Yes, i have already placed the shader in Resources folder, it is strange that everything works fine in Editor or Desktop build but iOS. I attached debugger and see that in Desktop build, material that used this shader has color and texture properties (even i dont define texture it in shader file), in iOS there is nothing in material. I think in Desktop build it is default that any material will have some essential properties but iOS it is not support, and i need to rewrite an relevant shader that has color property to set. the matter here is i dont know where is the error of my simple shader.
Thanks for your suggest, i remove my shader (which is on resource folder already) , import built in mobile vertex color shader of Unity, move shader file from standard folder to Resource (i tried it before but did not copy to Resources and it null on iPad) and voila :) Thanks again. You made my day.
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
See through issue in iOs 0 Answers
Materials are colored differently on rotated objects 1 Answer
UI Triangle Color picker 0 Answers