Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DataWorm · May 28, 2013 at 01:18 PM · androidshadercolorblackgl

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();
     }

 }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graham-Dunnett ♦♦ · May 28, 2013 at 02:37 PM 0
Share

Any warnings or errors in adb logcat?

avatar image temptest123 · May 28, 2013 at 08:42 PM 0
Share

maybe related: http://answers.unity3d.com/questions/254732/gllines-are-black-on-ipad-when-mesh-are-on-screen.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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] }}}");
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Varaughe · Oct 24, 2014 at 06:19 AM 0
Share

bravo majstore !

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Shader no work on Android(some device) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges