Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Taylor-Libonati · Mar 25, 2016 at 12:11 AM · androidmobileunity5openglgeometry shader

Unity 5 Geometry Shader Broken on Android

I am working on a geometry shader that draws quads based on a supplied set of points. This is working on Windows, but as soon as I change my build target to Android it stops working (Both in Editor and on device).

Everything I am reading is telling me that if my android device supports OpenGL ES3.1 + Android Expansion Pack that it should work.

Any ideas on what I am doing wrong?

Here is my Shader:

 Shader "PORT/PointCloudGeometry"
 {
     Properties
     {
         _Sprite ("Sprite", 2D) = "white" {}
         _Color("Color", Color) = (1,1,1,1)
         _Size("Size", Vector) = (1,1,0,0)
     }
     SubShader
     {
         Tags { "Queue" = "Overlay+100" "RenderType"="Transparent" }
 
         LOD 100
         Blend SrcAlpha OneMinusSrcAlpha
 
         Cull off
         Zwrite off
 
         Pass
         {
             CGPROGRAM 
 
             //Pragmas
             #pragma target 50
             #pragma vertex vert
             #pragma geometry geom
             #pragma fragment frag
 
             #pragma multi_compile_fog
             
             #include "UnityCG.cginc" 
             
             //User defined variables
             uniform sampler2D _Sprite;
             uniform float4 _Color; 
             uniform float2 _Size;
             uniform float3 _worldPos;
 
             int _StaticCylinderSpherical = 0; 
 
             struct data{
                 float3 pos;
             };
 
             StructuredBuffer<data> buf_Points;
 
             //Base input structs
             struct vertexOutput{
                 float4 pos: SV_POSITION;
                 float2 uv : TEXCOORD0;
                 UNITY_FOG_COORDS(1)
             };
             
             //Vertex function
             vertexOutput vert(uint id: SV_VertexID){
                 vertexOutput o;
                 o.pos = float4(buf_Points[id].pos + _worldPos, 1.0f);
                 return o;
             }
 
             //Geometry function
             [maxvertexcount(4)]
             void geom(point vertexOutput p[1], inout TriangleStream<vertexOutput> triStream){
                 float2 halfS = _Size;
                 float4 v[4];
 
                 //if(_StaticCylinderSpherical == 0){
                     v[0] = p[0].pos.xyzw + float4(-halfS.x, -halfS.y,0,0);
                     v[1] = p[0].pos.xyzw + float4(-halfS.x, halfS.y,0,0);
                     v[2] = p[0].pos.xyzw + float4(halfS.x, -halfS.y,0,0);
                     v[3] = p[0].pos.xyzw + float4(halfS.x, halfS.y,0,0); 
                 //}
 
                 vertexOutput pIn;
 
                 pIn.pos = mul(UNITY_MATRIX_VP, v[0]);
                 pIn.uv = float2(0.0f,0.0f);
                 UNITY_TRANSFER_FOG(pIn, pIn.pos);
                 triStream.Append(pIn);
 
                 pIn.pos = mul(UNITY_MATRIX_VP, v[1]);
                 pIn.uv = float2(0.0f,1.0f);
                 UNITY_TRANSFER_FOG(pIn, pIn.pos);
                 triStream.Append(pIn);
 
                 pIn.pos = mul(UNITY_MATRIX_VP, v[2]);
                 pIn.uv = float2(1.0f,0.0f);
                 UNITY_TRANSFER_FOG(pIn, pIn.pos);
                 triStream.Append(pIn);
 
                 pIn.pos = mul(UNITY_MATRIX_VP, v[3]);
                 pIn.uv = float2(1.0f,1.0f);
                 UNITY_TRANSFER_FOG(pIn, pIn.pos);
                 triStream.Append(pIn);
 
             }
             
             //fragment function
             float4 frag(vertexOutput i) : COLOR { 
                 fixed4 col = tex2D(_Sprite, i.uv) * _Color;
 
                 UNITY_APPLY_FOG(i.fogCoord, col); // Apply Fog
                 return col;
             }
             
             ENDCG
         }
     }
 }

Here is where I am setting the Shaders values:

 using UnityEngine;
 using System.Collections;
 
 public class PORT_PointCloud_Geometry : PORT_PointCloud {
     public Shader geomShader;
     Material mat;
 
     public Texture2D sprite;
     public Vector2 size = Vector2.one;
     public Color color = new Color(.75f,.5f,0,1);
 
     private ComputeBuffer outputBuffer;
 
     private PointData[] points;
 
     struct PointData{
         public Vector3 pos;
     };
 
     void Start(){
         mat = new Material (geomShader);
 
         points = new PointData[] {new PointData (){ pos = Vector3.zero }};
 
         outputBuffer = new ComputeBuffer (points.Length, 12);
         outputBuffer.SetData (points);
 
     }
 
     void OnRenderObject(){
         mat.SetPass (0);
         mat.SetColor ("_Color", color);
         mat.SetBuffer ("buf_points", outputBuffer);
         mat.SetTexture ("_Sprite", sprite);
         mat.SetVector ("_Size", size);
         mat.SetVector ("_worldPos", transform.position);
 
         Graphics.DrawProcedural (MeshTopology.Points, outputBuffer.count);
     }
 
     void OnDestroy(){
         outputBuffer.Release ();
     }
 }
 




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 revolute · Mar 25, 2016 at 07:52 AM 0
Share

It breaks actually on mobile devices or in editor?

avatar image Taylor-Libonati revolute · Mar 25, 2016 at 04:18 PM 0
Share

It will render nothing in editor and on an Android device. But it will render a sprite in editor if I switch to a standalone platform.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Taylor-Libonati · Mar 30, 2016 at 04:58 PM

After contacting and getting help from Unity Support I have found the solution. To get it working in editor I had to select "Edit > Graphics Emulation > None". And for it to work on an Android device I had to use a phone with Android 6.0+ with Android Extension Pack on it. In essence only really new phones, and apparently not all hardware supports it so its kind of hit or miss at this point.

Comment
Add comment · 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

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

63 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 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 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 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 avatar image avatar image avatar image

Related Questions

Unity5 Android mip-mapping problem 1 Answer

Unity Remote 5 only works when I plug usb in after Unity has started 0 Answers

Graphics Emulation - OpenGL 3 1 Answer

Unity Android plugin problem build CommandInvokationFailure 2 Answers

Is Gyroscope supported on all mobile Android iOS devices with a gyroscope? 3 Answers


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