Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Pointcloud Render Shader ,erro buildin to URP

Discussion in 'Scripting' started by firepad9, May 24, 2024.

  1. firepad9

    firepad9

    Joined:
    May 20, 2016
    Posts:
    15
    When I used the buildin shader below to render my point cloud it worked (although pointsize doesn't seem to work), but when I used the modified URPshader the point cloud didn't show up. Please help me solve this annoying problem. Of course, it would be better if pointsize can also control the size of the point, thank you!
    buidin:
    Code (CSharp):
    1.  
    2. Shader "Wsh/Point Cloud"
    3. {
    4.      Properties
    5.      {
    6.          _PointSize("Point Size", Float) = 0.05
    7.      }
    8.      SubShader
    9.      {
    10.          Pass
    11.          {
    12.              CGPROGRAM        
    13.              #pragma multi_compile_fog
    14.              #pragma vertex VSMain
    15.              #pragma fragment PSMain
    16.              #pragma target 5.0
    17.  
    18.              StructuredBuffer<float3> buf_Points;
    19.              StructuredBuffer<float3> buf_Colors;
    20.              float _PointSize;
    21.              
    22.              #include "UnityCG.cginc"
    23.            
    24.              struct shaderdata
    25.              {
    26.                  float4 vertex : SV_POSITION;
    27.                  float4 color : TEXCOORD0;
    28.                  float psize : PSIZE;
    29.              };
    30.  
    31.              shaderdata VSMain(uint id : SV_VertexID)
    32.              {
    33.                  shaderdata vs;
    34.                  float4 pt = float4(buf_Points[id], 1.0);
    35.                  vs.vertex = UnityObjectToClipPos(pt);
    36.                  vs.color = float4(buf_Colors[id],1.0);
    37.                  vs.psize = _PointSize;
    38.                  return vs;
    39.              }
    40.  
    41.              float4 PSMain(shaderdata ps) : SV_TARGET
    42.              {
    43.                  return ps.color;
    44.              }
    45.            
    46.              ENDCG
    47.          }
    48.      }
    49. }
    50.  
    URP:
    Code (CSharp):
    1.     Shader "Wsh/Point Cloud URP"
    2.     {
    3.         Properties
    4.         {
    5. //            _PointSize("Point Size", Float) = 0.05
    6.         }
    7.         SubShader
    8.         {
    9.             Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }
    10.             Pass
    11.             {
    12.                 HLSLPROGRAM      
    13.                 #pragma vertex VSMain
    14.                 #pragma fragment PSMain
    15.                 #pragma target 5.0
    16.    
    17.                 StructuredBuffer<float3> buf_Points;
    18.                 StructuredBuffer<float3> buf_Colors;
    19.                 // float _PointSize;
    20.                 //float4x4 _Transform;
    21.              
    22.                 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    23.              
    24.                 struct shaderdata
    25.                 {
    26.                     float4 vertex : SV_POSITION;
    27.                     float4 color : TEXCOORD0;
    28.                     // float psize : PSIZE;
    29.                 };
    30.                 shaderdata VSMain(uint id : SV_VertexID)
    31.                 {
    32.                     shaderdata vs;
    33.                     float4 pt = float4(buf_Points[id], 1.0);
    34.                     vs.vertex = TransformObjectToHClip(pt.xyz);
    35.                     vs.color = float4(buf_Colors[id],1.0);
    36.                     // vs.psize = _PointSize;
    37.                     return vs;
    38.                 }
    39.    
    40.                 float4 PSMain(shaderdata ps) : SV_TARGET
    41.                 {
    42.                     return ps.color;
    43.                 }
    44.              
    45.                 ENDHLSL
    46.             }
    47.         }
    48.     }
     
    Last edited: May 24, 2024