Search Unity

  1. We are looking for feedback on our SRP Rendering APIs through this Survey.
    Dismiss Notice
  2. Unity 2020.2 has been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted How to set point size of vertex in shader?

Discussion in 'Shaders' started by flymaxty, Nov 27, 2020.

  1. flymaxty

    flymaxty

    Joined:
    Sep 22, 2020
    Posts:
    2
    I'm trying to put pointcloud into scene, but the cloud is sparse. PSIZE looks like not be supported by Unity, is there anyway to set point size, or other way to draw the cloud?

    Here's the code I use and the result:

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2.  
    3. Shader "Custom/VertexColor" {
    4.     SubShader {
    5.     Pass {
    6.         LOD 200
    7.  
    8.  
    9.         CGPROGRAM
    10.         #pragma vertex vert
    11.         #pragma fragment frag
    12.  
    13.         uniform float _PointSize = 5;
    14.  
    15.         struct VertexInput {
    16.             float4 v : POSITION;
    17.             float4 color: COLOR;
    18.         };
    19.        
    20.         struct VertexOutput {
    21.             float4 pos : SV_POSITION;
    22.             float4 col : COLOR;
    23.             float size: PSIZE;
    24.         };
    25.        
    26.         VertexOutput vert(VertexInput v) {
    27.        
    28.             VertexOutput o;
    29.             o.pos = UnityObjectToClipPos(v.v);
    30.             o.col = v.color;
    31.             o.size = 3;
    32.            
    33.             return o;
    34.         }
    35.        
    36.         float4 frag(VertexOutput o) : COLOR {
    37.             return o.col;
    38.         }
    39.         ENDCG
    40.         }
    41.     }
    42. }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,575
    I don’t think this is a Unity limitation. Modern GPUs & Graphics APIs don’t support PSIZE anymore. Point rendering this way is considered a dead technique, so new Graphics APIs stopped actually supporting it a over decade ago, and most GPUs phased out support of it after that.

    The modern approach would be to use indirect instancing to draw meshes.
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    6,387
    works still with -force-glcore mode in Windows though (and macs, androids)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,575
    On some GPUs, not all.
     
unityunity