Search Unity

Alpha cutoff in particle system

Discussion in 'General Graphics' started by Nicksaccount, Jun 29, 2018.

  1. Nicksaccount

    Nicksaccount

    Joined:
    Jan 10, 2013
    Posts:
    24
    Is it possible to control the alpha cutoff from the particle system?

    Alternatively, can the particle system do something similar to "Step" in the new shader graph stuff?

    Thanks!
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    The standard particle shaders come with an alpha test threshold, if you set the material to Cutout mode.
     
  3. Nicksaccount

    Nicksaccount

    Joined:
    Jan 10, 2013
    Posts:
    24
    @richardkettlewell Thanks - I've created a cutout material which gives me an "Alpha Cutoff" slider in the Inspector, but I don't see any extra options in the particle system for how to control that.
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    It’s a particle shader added in 2018.1 as a built in shader, it’s not in the particle component. I’ll be back online later and can be more specific if you still can’t find it.. gotta dash now tho :)
     
  5. Nicksaccount

    Nicksaccount

    Joined:
    Jan 10, 2013
    Posts:
    24
    I tried with some of the LRP standard shaders and found one with the Alpha Clip Threshold.

    I still can't work out how to make a particle system control that value though, so I'd be grateful for any extra help.

    Untitled-1.png

    Untitled-2.png
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Yep, you found it. You should be able to keyframe the slider in an animation, or drive it with a script material.SetFloat, or material property block, or shader.SetFloat.

    Or if you want different values per particle, you need to hook up a custom shader. We walk you through it at the end of this talk:
    there is a link to the project file in the video comments.
     
    mitaywalle and karl_jones like this.
  7. Nicksaccount

    Nicksaccount

    Joined:
    Jan 10, 2013
    Posts:
    24
    Thanks for the video, that makes it clearer - that we need a custom shader to accomplish it and particle systems don't natively support it, which is a bit of a shame as it'd be a very useful feature.

    Out of interest, do you know if I can yet get Custom Vertex Streams to work with the new Shader Graph stuff? If so then I could use it as an input into the Step node and bypass writing that custom shader.
     
  8. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I’ve never tried it but I’m 99% sure custom vertex streams will work with shadergraph. The custom streams just get mapped to the TEXCOORD (uv) streams, which you can see in the renderer module ui.
     
  9. Nicksaccount

    Nicksaccount

    Joined:
    Jan 10, 2013
    Posts:
    24
    I get it now - I'd looked before at the Custom Vertex Streams but didn't quite understand them before. I'll document what I did below.

    To make the effect I want, I need to first create a custom curve in my particle system. This runs between about 0.1 and 1 so Step will work nicely.

    c.png

    Then, enable custom vertex streams. Unity may ask you to create some default streams required for your material. Add the "Custom1.x" stream. We're only adding Custom1.x as we only created a 1d curve above.

    d.png

    Note that when we created the stream for Custom1.x, Unity automatically assigned it to TEXCOORD0.z. What this means is that in shader graph we'll be able to access that custom value by reading data from UV0 (matching TEXCOORD0) and reading the 3rd channel. The Custom Vertex Streams uses the channels names xyzw, and the shader graph uses rgba, but the 3rd channel is still the 3rd channel.

    The below shader graph, then, reads data from UV0, splits that data so we only get the 3rd channel, and then passes it into a Step node, which on a greyscale image will create an effect like an alpha cutoff.

    e.png
     
    M-Elwy, Caffeen and richardkettlewell like this.
  10. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
  11. SF_futurlab

    SF_futurlab

    Joined:
    Feb 4, 2016
    Posts:
    19
    Hi, great info here. I used this to achieve the same effect (using ShaderForge as we aren't migrating our project yet).

    I then tried a different way that I thought I'd share. Its more simple and works for my needs and might work for yours...

    This way you can use the alpha parameter in 'Colour over Lifetime' to dissolve the particle and it doesn't require any custom channels.

    Thanks for the info anyway - nice to see what can be done with custom streams!
     

    Attached Files:

  12. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    So far, I have yet to get this to work on two separate projects. My only connection between the two is that they are using the HDRP.

    @richardkettlewell, would you happen to have any thoughts as to why it wouldn't be working? It should be that the particles are random colors base on the xy of the custom data, but that isnt the case it would seem. Color isn't the goal for this, but this was just a simple mock up.
    Help.png Help2.png
     
  13. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I can’t see an obvious problem with your setup.. but probably I’m missing something.. :confused:
     
  14. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    So I just rebuilt it exactly in LWRP and it works. But not in HDRP... uh ok?

    Went ahead and reported as a bug to verify if there is something missing:
    (Case 1060778) HDRP Particle system to Shader Graph UV incorrect results

    Update:
    Matt found a potential cause
    https://twitter.com/MatthewDean3D/status/1018972518823047169
     
    Last edited: Jul 16, 2018
    richardkettlewell likes this.
  15. TuomoLuukkanen

    TuomoLuukkanen

    Joined:
    Apr 27, 2015
    Posts:
    3
    This just about describes the entirety of Unity support when it comes to Shader Graph.