Search Unity

Scaling particles in shader

Discussion in 'Shaders' started by Zenchuck, Apr 19, 2018.

  1. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    Hi there,

    I am sending the Custom Vertex Stream "Size" attribute to the shader in hopes of using it there to control the particle size.

    Any idea how I would use this data in the vertex program?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    The size property is the size it is already being scaled to. Why do you need to scale it in the shader?
     
  3. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    I wan't to create an interactive experience where I can push the particles away, in a similar way to foliage bending. I also want the particles to shrink at the same time. I am using a simple vertex offfset at the moment, but I would like to create a hole by shrinking the particles at the same time.
     

    Attached Files:

  4. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    A second issue I am having is getting working normals. I have sent the tangent data to the shader but I am not able to figure it out from there.
     

    Attached Files:

  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    The size value you’re passing to the shader is to tell the shader what size the particle was generated at. It’s not a way to drive the size of the particle; setting those values in the shader doesn’t directly do anything.

    To do what you’re looking to do you should be passing the particle’s position, and using that to scale the particle down. You don’t actually need to know the particle’s size assuming you just want to scale the particle size down to zero. The short version is calculate the world position of each vertex, then lerp that position towards the particle position.

    This page should help. Look at the section labeled:
    Environment reflection with a normal map
    https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
     
    Zenchuck likes this.