Search Unity

MeshTopology.Points very strange on iOS (Unity 2017.3.0.b10)

Discussion in 'General Graphics' started by cecarlsen, Nov 22, 2017.

  1. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    862
    This has been driving me nuts. Rendering points on iOS using DrawProcedural or DrawProceduralIndirect seem to result in large quads.

    Before posting a bug it would be nice to see if anyone else can reproduce it. I have attached an example package. Build to iOS, see if you get the same.

    I testing on an iPhone7.

    Carl Emil

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PointTopologyTest : MonoBehaviour
    4. {
    5.     public Shader shader;
    6.     Material _material;
    7.  
    8.     void OnRenderObject()
    9.     {
    10.         if( !_material ) _material = new Material( shader );
    11.         _material.SetPass(0);
    12.         Graphics.DrawProcedural( MeshTopology.Points, 100, 1 );
    13.     }
    14. }
    Code (CSharp):
    1. Shader "Hidden/PointTopologyTest"
    2. {
    3.     SubShader
    4.     {
    5.         Tags { "RenderType"="Opaque" }
    6.         LOD 100
    7.  
    8.         Pass
    9.         {
    10.             CGPROGRAM
    11.             #pragma target 4.5
    12.             #pragma vertex vert
    13.             #pragma fragment frag
    14.          
    15.             #include "UnityCG.cginc"
    16.  
    17.             struct v2f
    18.             {
    19.                 float4 vertex : SV_POSITION;
    20.             };
    21.  
    22.             v2f vert( uint id : SV_VertexID )
    23.             {
    24.                 v2f o;
    25.                 o.vertex = UnityObjectToClipPos(float4(id*0.1,sin(id*0.1)*5,0,1));
    26.                 return o;
    27.             }
    28.  
    29.             fixed4 frag( v2f i ) : SV_Target
    30.             {
    31.                 return fixed4( 1, 1, 0, 1 );
    32.             }
    33.             ENDCG
    34.         }
    35.     }
    36. }

    Image.jpg
     

    Attached Files:

    Last edited: Nov 22, 2017
  2. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    862
    Oddly enough, MeshTopology.Lines works nicely on iOS. Really strange.

    IMG_0036.PNG
     
  3. aaronm37

    aaronm37

    Joined:
    Jun 9, 2017
    Posts:
    2
    Yes, same experience here as well. (Unity 2017.3.0f3)
    I haven't tested with older versions of Unity.
     
  4. tkm0

    tkm0

    Joined:
    Mar 11, 2018
    Posts:
    1
    Hi, I think the reason is "Metal" the graphics api.
    In my case, I changed Graphics API OpenGLES2 from Metal.
    Then, it became to looks like good.

    Unity2017.3.0f.3
    iPad iOS11.2

    Code (CSharp):
    1. void Start () {
    2.       MeshFilter meshFilter = GetComponent<MeshFilter>();
    3.       meshFilter.mesh.SetIndices(meshFilter.mesh.GetIndices(0), MeshTopology.Points, 0);
    4. }

    (with OpenGLES2)
    Image uploaded from iOS (1).png


    (with Metal)
    Image uploaded from iOS (2).png

    regards.
     
    Last edited: Mar 12, 2018
  5. andrewgotow

    andrewgotow

    Joined:
    Dec 28, 2013
    Posts:
    18
    Sorry to bring up an old post, but here's a solution for anyone struggling with this issue.

    In Metal, the size of drawn points is undefined unless otherwise specified, so you're seeing points drawn at some arbitrary size (in this case, like half the screen!)

    You can define a point size by specifying a value in your vertex shader using the PSIZE semantic.

    Code (CSharp):
    1. float4 vert (appdata_base v, out float pointSize : PSIZE) : SV_Position {
    2.     pointSize = 1;
    3.     return UnityObjectToClipPos(v.vertex);
    4. }
     
  6. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    Thank you!

    For anyone who needs more info on how to inject PSIZE into a shader, theres another example here: https://gamedev.stackexchange.com/q...s-when-building-a-mesh-based-on-a-point-cloud
     
    Last edited: Mar 29, 2021