0
\$\begingroup\$

I create a mesh in Unity3D based on a point cloud in this way:

// The standard sequence for creating a mesh
Mesh mesh = new Mesh();
Vector3[] points = new Vector3[numPoints];
int[] indecies = new int[numPoints];
Color[] colors = new Color[numPoints];

// Fill in points, indecies, colors

mesh.vertices = points;
mesh.colors = colors;
mesh.SetIndices(indecies, MeshTopology.Points, 0);

I learned that it is possible to set the size of points in PSIZE through Vertex Shader. Applied such a Shader, but without result.

Shader "VertexColor" 
{    
    Properties     
    {         
        _PointSize("Point size", Float) = 5.0     
    }       
    SubShader     
    {         
        Pass         
        {             
            LOD 200                         

            CGPROGRAM             
            #pragma vertex vert
            #pragma fragment frag               

            uniform float _PointSize;               

            struct VertexInput             
            {                 
                float4 vertex: POSITION;                 
                float4 color: COLOR;            
             };               

             struct VertexOutput          
             {
                 float4 pos: SV_POSITION;                 
                 float4 col: COLOR;                 
                 float size: PSIZE;            
              };               

              VertexOutput vert(VertexInput v)             
              {                 
                  VertexOutput o;                 
                  o.pos = UnityObjectToClipPos(v.vertex);                 
                  o.col = v.color;                 
                  o.size = _PointSize;

                  return o;             
              }               

              float4 frag(VertexOutput o) : COLOR             
              {                 
                  return o.col;             
              }             
              ENDCG         
          }     
      } 
}

Tell me, please, how to set the size of points correctly?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

I found that if the launch Unity with the flag -force-opengl the shader you have supplied will work.

\$\endgroup\$
0
\$\begingroup\$

_PointSize is defaulting to 0; use:

uniform float _PointSize = 2;

and expose it as a param at the top of the shader if you want to adjust it in the material

Properties
{
    _PointSize ("Point Size", Float) = 1
}         
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .