Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Particle Outline Shader

Discussion in 'Shaders' started by Slink472, Sep 3, 2021.

  1. Slink472

    Slink472

    Joined:
    Jul 22, 2017
    Posts:
    6
    Hello! I was poking through the forum looking for a shader that would put a dark outline around each particle in a particle system. I found a thread that talked about exactly that, but the original poster put only a snippet of the completed shader in his post (linked here).

    I've been trying to piece it together but I still can't seem to put it together into a functioning shader. Would anyone be able to point me in the right direction to complete the script? I included the snippet from that forum post below. Thanks so much!

    Code (CSharp):
    1.  struct appdata {
    2.  
    3.                float3 vertex : POSITION;
    4.  
    5.                float4 color : COLOR;
    6.  
    7.                float3 center : TEXCOORD0;
    8.  
    9.            };
    10.  
    11.          
    12.  
    13.            struct v2f {
    14.  
    15.                float4 pos : POSITION;
    16.  
    17.                float4 color : COLOR;
    18.  
    19.                float3 center : TEXCOORD0;
    20.  
    21.              
    22.  
    23.            };
    24.  
    25.            uniform float _Outline;
    26.  
    27.            uniform float4 _OutlineColor;
    28.  
    29.            v2f vert(appdata v) {
    30.  
    31.                v2f o;
    32.  
    33.                o.center = v.center;
    34.  
    35.                float3 vert = v.vertex - v.center;
    36.  
    37.                vert *= ( 1 + _Outline);
    38.  
    39.                v.vertex = vert + v.center;
    40.  
    41.                o.pos = UnityObjectToClipPos(v.vertex);
    42.  
    43.          
    44.  
    45.                o.color = _OutlineColor;
    46.  
    47.                return o;
    48.  
    49.            }
    50.  
    51.  
    52.  
    53.            half4 frag(v2f i) :COLOR { return i.color; }