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

Strange behavior of the shader with the alpha channel in the Particle System Effect.

Discussion in 'General Graphics' started by Volchok, Mar 7, 2021.

  1. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Hi!

    Please help me fix this shader behavior in the material (or anywhere else) in the fire effect.

    When the fire appears, I see (in the game and in the editor scene) squares with a translucent alpha channel. If I look at them from a certain angle, they disappear, but mostly they are always visible.

    I tried changing different parameters of the material, of the particle effect and textures - nothing helps.

    How can I get rid of black squares?

    Thanks!

     
    Last edited: Mar 8, 2021
  2. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,105
    What is the issue? is no clear from your screenshots
     
  3. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    There is the description at the beginning (before screenshots).
     
  4. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,105
    in the screenshots is not clear what is the problem
     
  5. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Sorry, I don't understand, what can be unclear there? Fire particles textures from the set of textures fly out from particle system. Textures of the fire for some reason are not completely transparent along the border of square. If I look at the fire from a different angle, everything looks as it should (but this angle is small - perhaps the texture is transparent only on one side). What can I give you to understand why this is happening? Shader? The material? Video? What exactly is unclear to you?
     
    Last edited: Mar 8, 2021
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    What appears to be happening is something on the fire particles is writing to the depth buffer. Generally speaking you want to be very careful when you have transparent objects write to the depth buffer as it means any transparent objects that render afterwards can get depth rejected, which is what's happening with your fog particles. Because the fog is a large particle system it's having a hard time sorting properly. Exact transparent sorting for real time rendering is an unsolved problem, so instead it's approximated with what's known as Painter's Algorithm. That is objects that are further away are rendered first, then closer objects are rendered on top of them. As long as transparent objects don't intersect, this works pretty well. Unfortunately when you have a single particle system that covers a large area, the entire particle system is treated as a single "object" and is sorted as such rather than each particle being sorted individually against other transparent objects in the scene.

    You may want to break up your ground fog into smaller parts so they can sort more easily, though that won't solve the issue entirely. As I said, this is an unsolved problem for real time rendering as a whole, not just a Unity thing.

    As for what is writing to the depth buffer I couldn't say from the screenshots or information you've provided. The legacy additive particle doesn't write to the depth, so unless it's been replaced in your project with an identically named shader that has
    ZWrite On
    , it's not that. So either some script is adding another material to your particle effects, or there's another particle system that happens to be placed in the same position as your fire that is using a transparent material that's writing to the depth buffer.

    There's a few things I would try:
    Does modifying the size of the fire or smoke particles while the scene is running have an effect on the size of the area being blocked? If not, then it's not actually those particles and it's something else in the scene that shouldn't be there.

    If changing the size of the particles does affect those, then make sure you don't have any scripts that are modifying the
    .materials
    or
    .sharedMaterials
    on the particle system renderer to add an extra pass. You can search your scripts, or you can try using the Frame Debugger window to step through the rendering and see if the fire particles show up twice, perhaps with one of those times seemingly nothing rendering. Or you can write a script to print out the
    .sharedMaterials
    at runtime. The UI does not support showing more than one material per particle system renderer, but you can do that from script, hence why I bring it up.
    https://docs.unity3d.com/ScriptReference/ParticleSystemRenderer.html

    Lastly, I'd see if there's a duplicate shader with the same name in your project. You can easily test this if you click on the "Edit..." button next to the shader name on the material. If nothing happens, it's using the built in shader. If it opens up a new window with the shader code in it, then you have a shader in your project with the same name (the part in quotes at the start of the file after
    Shader
    ), and which likely has
    ZWrite On
    somewhere within the text or the
    ZWrite Off
    line removed. If this is the case, then you'll either need to remove this shader or rename it, depending of what it was being used for, and reassign the real additive particle shader to your particle materials.

    For reference, this is what the additive shader should look like:
    https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Particle Add.shader
     
    Volchok likes this.
  7. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Thank you for such a detailed answer! :):):) I will read everything carefully, check it out, and give you an answer as soon as possible.
     
  8. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,105
    sorry man, it was that I did not understood the issue, wanted to help, glad you got an answer :)
     
    Volchok and richardkettlewell like this.
  9. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    :):):)
     
  10. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    You are right. :) I turned off the fog and this problem disappeared. I'll try to do something with the fog particles, as you suggested. It may be possible to at least minimize this problem.
     
  11. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I've reduced the size of the fog particles and put the particle system higher on the Y-axis. The problem has disappeared almost completely, and that's enough for me in this situation. :) If I go deeper into this trouble later, I will comment here a result.

    Thanks to bgolus! :)
     
    richardkettlewell likes this.