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\$
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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.