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

Writing Particle Shader?

Discussion in 'Shaders' started by the_lemur, Oct 23, 2016.

  1. the_lemur

    the_lemur

    Joined:
    Apr 3, 2013
    Posts:
    104
    I've been learning cg shaders this week and would like to know how to write a particle shader.

    The NVIDIA cg tutorial has extremely scant information on this, which isn't explained at all.

    They simply output [color,position] for every vertex.. but if that's the case.. wouldn't those positions be interpolated across the polygon, like anything else?

    Perhaps no triangles are defined, so the vertices are standalone.. but in this case the particles would all be single points, with no size.

    How do you write your shader to draw individual particles with size... without defining 100 tiny meshes? Is that what you do? Define 100 tiny 0.01x0.01 meshes? I mean.. I can do that.. but the NVIDIA tutorial seems to suggest it's simplier than that.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You'll need to be more specific, perhaps a link to the tutorial you're referring to.

    In Unity when someone uses the phrase "particle shader" most of the time they are going to be taking about writing a shader for Unity's Shuriken particle system which does indeed dynamically build a mesh with hundreds (or thousands) of quad meshes that is then rendered just like any other mesh. The shaders for those kinds of particles are different from most Unity shaders just in the fact they use vertex color.

    In your case I suspect you're talking about a shader used with a mesh setup to render as points, in which case the GPU is expanding each vertex into a point on screen or a quad of some kind.
     
    PeteUnity3D likes this.