- Home /
GL.Color() has no effect on android
Hello,
the following code doesn't work similar on pc and adroid. This file just has to be stored as CircleTest.cs in Unity and attached to the main camera. Then it should draw a little red circle on center of screen and this works on windows in editor (also when i have switched to android as platform). But on a real android device it completely ignores the defined color -> it just draw a black circle. Maybe it has something to do with the generated shader, but anyway i dont understand what the problem is. I hope someone can help me!
Thx in advance! Dataworm
using UnityEngine; using System.Collections; public class CircleTest : MonoBehaviour {
private Material triangleMaterial;
public Color circleColor = Color.red;
public int numberOfTriangles = 30;
Camera cam;
float nearClip;
void Awake () {
triangleMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass {" +
" BindChannels { Bind \"Color\",color }" +
" Blend SrcAlpha OneMinusSrcAlpha" +
" ZWrite Off Cull Off Fog { Mode Off }" +
"} } }");
triangleMaterial.hideFlags = HideFlags.HideAndDontSave;
triangleMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
void Start () {
cam = camera;
nearClip = cam.nearClipPlane+0.01f;
}
void OnPostRender () {
drawCircle(new Vector2(Screen.width/2, Screen.height/2),50);
}
private void drawCircle(Vector2 position, float size) {
float value = 200f;
float originX = position.x;
float originY = Screen.height - position.y;
float r = size/2;
GL.PushMatrix();
triangleMaterial.SetPass(0);
GL.Begin(GL.TRIANGLES);
GL.Color(circleColor);
Vector3 p;
float step = 360/numberOfTriangles;
float i=0f;
while(i<360f) {
p = new Vector3(r * Mathf.Cos((90-i)*Mathf.Deg2Rad) + originX, r * Mathf.Sin((90-i)*Mathf.Deg2Rad) + originY, nearClip);
GL.Vertex(cam.ScreenToWorldPoint(p));
i += step;
p = new Vector3(r * Mathf.Cos((90-i)*Mathf.Deg2Rad) + originX, r * Mathf.Sin((90-i)*Mathf.Deg2Rad) + originY, nearClip);
GL.Vertex(cam.ScreenToWorldPoint(p));
p = new Vector3(originX, originY, nearClip);
GL.Vertex(cam.ScreenToWorldPoint(p));
}
GL.End();
GL.PopMatrix();
}
}
Answer by DataWorm · May 29, 2013 at 11:29 AM
Thx for the help, i found a solution. Instead of one material with changeable color i make multiple materials for every color. With this new shader it works on android:
private Material createMaterial(Color color) {
return new Material("Shader \"Lines/Background\" { Properties { _Color (\"Main Color\", Color) = ("+color.r+","+color.g+","+color.b+","+color.a+") } SubShader { Pass { ZWrite on Blend SrcAlpha OneMinusSrcAlpha Colormask RGBA Lighting Off Offset 1, 1 Color[_Color] }}}");
}
Your answer
Follow this Question
Related Questions
GL - Shader not working in Android 1 Answer
Black texture on Android (shader) 0 Answers
Material doesn't have a color property '_Color' 4 Answers
Simple vertex color + light shader 1 Answer