Advertisement
Bunny83

PointCloudShader

Feb 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. Shader "Custom/SpherePoint" {
  2.      Properties {
  3.          _Color ("Color", Color) = (1,1,1,1)
  4.          _Radius ("Sphere Radius", float) = 0.01
  5.      }
  6.      SubShader {
  7.          Tags { "RenderType"="Opaque" }
  8.          LOD 200
  9.          Cull Off
  10.          Pass {
  11.              CGPROGRAM
  12.              #pragma vertex vert
  13.              #pragma fragment frag
  14.              #pragma geometry geom
  15.              #pragma target 4.0                    // Use shader model 3.0 target, to get nicer looking lighting
  16.              #include "UnityCG.cginc"
  17.              struct vertexIn {
  18.                  float4 pos : POSITION;
  19.                  float4 color : COLOR;
  20.                  float3 normal : NORMAL;
  21.              };
  22.              struct vertexOut {
  23.                  float4 pos : POSITION;
  24.                  float4 color : COLOR0;
  25.                  float3 normal : NORMAL;
  26.              };
  27.              struct geomOut {
  28.                  float4 pos : POSITION;
  29.                  float4 color : COLO0R;
  30.                  float3 normal : NORMAL;
  31.              };
  32.              //Vertex shader: computes normal wrt camera
  33.              vertexOut vert (vertexIn i) {
  34.                  vertexOut o;
  35.                  o.pos = UnityObjectToClipPos(i.pos);
  36.                  o.color = i.color;
  37.                  o.normal = ObjSpaceViewDir(o.pos);
  38.                  return o;
  39.              }
  40.              float _Radius;    
  41.              static const fixed SQRT3_6 = sqrt(3)/6;
  42.              float4 _Color;
  43.              [maxvertexcount(3)]
  44.              void geom(point vertexOut i[1], inout TriangleStream<geomOut> OutputStream)
  45.              {
  46.                  geomOut p;
  47.                  float a = _ScreenParams.x / _ScreenParams.y; // aspect ratio
  48.                  float s = _Radius;
  49.                  float s2 = s*SQRT3_6 *a;
  50.      
  51.                  p.color = i[0].color * _Color;
  52.                  p.normal = float3(0,0,1);
  53.                  p.pos = i[0].pos + float4(0,s2*2,0,0);
  54.                  OutputStream.Append(p);
  55.                  p.pos = i[0].pos + float4(-s*0.5f,-s2,0,0);
  56.                  OutputStream.Append(p);
  57.                  p.pos = i[0].pos + float4(s*0.5f,-s2,0,0);
  58.                  OutputStream.Append(p);
  59.                  OutputStream.RestartStrip();
  60.              }            
  61.  
  62.              float4 frag(geomOut i) : COLOR
  63.              {
  64.                  return i.color;
  65.              }
  66.              ENDCG
  67.          }
  68.      }
  69.      FallBack "Diffuse"
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement