Search Unity

Question A material (shader) blinks (flickers) at a certain angle.

Discussion in 'Shaders' started by Volchok, May 26, 2021.

  1. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Hi!

    Please tell me why, at a certain angle, a plane with a certain material (shader) blinks (flickers)? I read different forums, changed a lot of camera settings, light settings, material settings, and Unity Project Settings, turned off all the effects (smoke, snow). Nothing helps.

    I don't know what to do? Please tell me how I can get rid of this render defect?

    Thank you!





     
    Last edited: May 26, 2021
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Volchok likes this.
  3. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
  4. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    One month ago I wrote to the author. The problem turned out to be in the ice shader. This shader cannot work with more than one light on the scene. That is, 2, 3, N lights create such an error in the shader - it starts to flicker. :( The author tried to fix this error, but still can't do it. Hopefully, over time, he will solve this problem. If he solves it, I will report here. :) In the project I just use one light source, now. It is a pity that it is not possible to use several light sources - the ice turns out to be more beautiful.
     
    Last edited: Jun 30, 2021
  5. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I found that the problem is more serious than I thought. Any light on the scene in any object lying on the ice flickers. :( Watch the reflected light from objects on the ice in the video… It is very annoying? I wrote to the author of the asset. I hope he will fix the error. But, to tell the truth, for 2 months now, for some reason, he can't do this.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That strikes me as a different "bug".

    Unity's has a setting for the max number of per pixel lights per forward rendered object, which the ice is going to be. If your ice sheet is a single giant mesh, only that many lights can affect it at one time and Unity will disable any beyond that limit based on some very basic heuristic for which ones are more "important" (likely not much more advanced than what order they appear in some internal list of all lights).

    Check your project's Graphics settings. Right at the top under the "Rendering" section there should be an option called "Pixel Light Count". It's probably set to something like 3 or 4. You can set that to a higher number to get around this, but the "real" fix might be to cut up your ice sheet into smaller separate game objects / quads so each can be lit individually.

    This isn't really a bug, but rather a common limitation of any forward renderer. Especially very old ones like Unity's. Note, even if you're using deferred lighting for your project, the ice is a custom shader not using the Standard lighting, and thus has to be rendered using forward rendering, just as any transparent material will as well.
     
    Olls_hay and Volchok like this.
  7. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Very interesting! Thank you so much for the information! I'll pass it on to the author. We are currently discussing this problem with him and trying to solve it. By the way, we have already changed Pixel Light Count in different ways: 4, 5, 10, 20, 33, 100 - nothing changes.



    But the most interesting thing is that this does not happen with the standard Unity shader with transparency Unlit/Transparent. So, logically, there is an error somewhere in the shader code itself, I think.

     
    Last edited: Jul 20, 2021
  8. NatureManufacture

    NatureManufacture

    Joined:
    May 20, 2014
    Posts:
    2,026
    Ice use standard lighting. From our test pixel light count should fix it.
    https://gyazo.com/ca01127cfd6e549ce7d9738986bed94f
     
    Volchok likes this.
  9. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    In my case, this method does not work.

    There is only one global Directional Light on the scene that illuminates the ice.



    And it does not depend on the effects of particles.
    If I turn off the blizzard and/or snow, everything will be the same.

     
    Last edited: Jul 20, 2021
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That glow you're seeing popping in and out, those are from additional lights. I suspect every single item on the ground has an effect on it that is using a light... possibly several lights per object.

    This frame in particular is especially telling:
    upload_2021-7-20_11-2-5.png
    This has most of the lights "disappearing", but some are still visible, which makes me think you have some effects using per particle lights with a lot of particles, which can easily explode the number of lights in your scene and cause the issue you're seeing.

    I've noticed per particle lights are a very popular thing to add to vfx assets as they can make them look a lot better, especially when shown one effect at a time. But in real use you should almost never ever use per particle lights for this exact reason.
     
    Volchok likes this.
  11. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I'd also suggest bringing out the frame debugger and trying to pause the game when the problem shows up. Then step through the rendering and see how many times the ice is being rendered. I'm going to predict that when you have your pixel light count set to 30, and you see some things flicker off, the ice is still getting rendered 30 times.
     
    Volchok likes this.
  12. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    There are no particle lights as far as I know. Blinking occurs even without objects on the ice. Look in the beginning of this issue - there the ice blinks simply because it is illuminated by more than one light (Directional Lights).



    Objects on the ice have add lights when they appear on the scene. And the blinking appears again. Blinking occurs if more than one light source appears on the scene and the rays of additional lights fall into the camera.
     
    Last edited: Jul 21, 2021
  13. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    It seems that the ice shader cannot process more than one light. IMHO. :rolleyes:
     
  14. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I pulled everything into a separate scene and tested in it. I must agree with bgolus
    and NatureManufacture, they are right. It's all about the Pixel Light Count parameter. There's nothing wrong with ice shader!



    I had 4 farm objects on the scene and each had 2 lights - everything started working correctly as soon as I set Pixel Light Count = min 8 (or more). As far as I understood, I need to increase the Pixel Light Count in the original scene, for example, to 1000 and see the result (because there can be a lot of lights in it). And if this does not help, I will look for where the particles with lights appear and correct them to simple ones.

    The question is closed! Thanks for your help! :)
     
    bgolus likes this.
  15. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Hi again!

    I tried to solve this problem and count the number of light sources on the scene in runtime.

    Code (CSharp):
    1. var foundCanvasObjects = FindObjectsOfType<Light>();
    2.          
    3. pixelLightCount.text = "PixelLightCount: " + QualitySettings.pixelLightCount;
    4.  
    5. lights.text = "Lights: " + foundCanvasObjects.Length;
    But both in the assembly and in the editor, there is still a flicker. I don't understand what it depends on. Maybe I find all the active light sources by the wrong way? I set the value of PixelLightCount = 1000 - it didn't help. I turned on and off snow and blizzard - the result is the same. On the scene, I have no light sources in the particles - I removed each object after object.

    Maybe it depends on the type of light source or the overlay of layers of effects, or on the number of frames per second (fps)?

    Please help me figure out how to get rid of this flicker!

    Thanks!



     
    Last edited: Aug 10, 2021
  16. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I have already left one light source on the stage and increased PixelLightCount = 1000, checked all objects and particle systems by the method of exceptions and shutdowns - the result is the same.

    Most likely, I assume that the flickering of light at a certain angle comes from the customizable effects of snow and blizzard and fog (in Window-->Rendering-->Environment-->Other Settings-->Fog-->Density).

    In short, apparently by the communication with the author of the asset and for many other reasons, I'm starting to think that this is a problem of the Unity Engine itself.



    If someone can dissuade me in it and somehow help solve this problem - I will be very grateful!
     
    Last edited: Aug 20, 2021
  17. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    Recently I had a similar problem on MacBook (with Radeon GPU). It was caused by enabled Screen Space Reflections from Post Processing Stack v2. Problem was fixed by updating Post Processing Stack into the newest version (3.0.3.).
     
    Volchok likes this.
  18. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Interesting information. Thanks! Do you know what version of the Post Processing Stack is in Unity 2020.2.3.f1? As far as I understood v2 (https://docs.unity3d.com/2018.2/Documentation/Manual/PostProcessing-Stack.html). Can it be upgraded to v3? Or is it necessary to switch to the Unity 2021 version?
     
  19. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I recently discovered that this problem is also present in other scenes. :eek: I will provide the video below.
     
    Last edited: Aug 20, 2021
  20. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    Post Processing Stack is installed manually from Window - > Package Manager (Advanced - > Show Preview Packages). Maybe your project has assets from Assetstore which automatically installed PPS and use it.
     
    Volchok likes this.
  21. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    Unity 2020 fully supports PPS v3:

    upload_2021-8-20_20-18-40.png
     
    Volchok likes this.
  22. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I see this in my Package Manager.





    Do I need to upgrade Post Processing to version 3.0.3.?
     
  23. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Unfortunately, I found that this flicker is not only on your Ice World (https://assetstore.unity.com/packages/vfx/shaders/ice-world-83543) shader, but also on the R. A. M 2019 - River Auto Material 2019 (https://assetstore.unity.com/packages/tools/terrain/r-a-m-2019-river-auto-material-2019-145937) shader.

    Here is a video where there are 2 shaders on the same location - your R. A. M 2019-River and Wet Stuff (https://assetstore.unity.com/packages/tools/particles-effects/wet-stuff-118969).

    Attention! Wet Stuff is not used in the winter location.
    So that you don't say that Wet Stuff is to blame for everything.



    Here is the information about the scene.
    One global light source, camera, quality, light.







    Now I'm inclined to believe that something is still wrong in shaders in Ice World and in R.A.M 2019 - River (NatureManufacture).
     
  24. NatureManufacture

    NatureManufacture

    Joined:
    May 20, 2014
    Posts:
    2,026
    For r.a.m use non tesseled shader or add decal:blend line into pragma surf. We proff you many times its not about shaders but setup with tons of lights at same time
     
    Volchok likes this.
  25. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    YES, update to 3.0.3
    .
     
  26. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I updated it to version 3.1.1. The graphics seem to have become better, the flickering has decreased slightly, but they are still present. But for the advice, thank you! I needed to update the version. :)
     
  27. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Thanks for the answer!

    >>> use non tesseled shader <<<
    >>> add decal:blend line into pragma surf <<<

    You know, I don't know much about shaders. Can you tell me in more detail what and where to change? Moreover, as far as I remember, we have already changed the code in the shader - We have already added decal:blend into the shader code and this led to the fact that the shader was just white.

    >>> We proff you many times its not about shaders but setup with tons of lights at same time. <<<
    I checked everything - I don't have such a large number of light sources on scenes - watch the video above. In addition, if this were the case, then reflections on the Wet Stuff shader would also blink.

    Or I don't understand something again... )

    I just need to get rid of the flicker on your shaders and that's all - I didn't think it would result in such a problem. :(
     
  28. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Finally, as far as I understand:


    ---It didn't help!---

    1) Unity Forum administrators advise me to contact the author of the asset, because this is his mistake.
    >>>Contact the author of that asset, NatureManufacture.<<<


    ---It didn't help!---

    2) The author of the asset (Nature Manufacture) tells me of having a lot of light sources in the location (although I reported above about how I count light sources). It turns out that Pixel Light Count does not play a big role.
    >>>We proff you many times its not about shaders but setup with tons of lights at same time<<<
    It's not true, no one has yet been convinced of anything. Why then do other shaders with reflections behave correctly in the same location right near to the shader from NatureManufacture? If I incorrectly count the number of lights in the scene, please suggest your own variant.


    ---It didn't help!---

    3) Some say that this is an overlay of transparent effects and particles on top of each other (the problem is in the Depth Buffer or Post Processing Stack). I removed all the effects and updated the Post Processing Stack to version 3.1.1 - the problem has not disappeared.


    ---???---
    4) >>>For r.a.m use non tesseled shader or add decal:blend line into pragma surf.<<<
    I don't know much about shaders. Can you tell me in more detail what and where to change? Moreover, as far as I remember, we have already changed the code in the shader - We have already added decal:blend into the shader code and this led to the fact that the shader was just white.


    How can I solve this issue? Does anyone else have any ideas?
     
  29. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    As a result, can anyone help me somehow solve this problem?
    Or is it not solvable in the Unity engine?

     
  30. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Get a frame where things look wrong. Step through and try and make note of what order objects / passes are rendering in. Try to compare to a frame where things are looking how they should.

    This is either going to end up being an issue with something drawing in the wrong order, or something not getting the data it needs. My inclination at this point is you're running into some kind of Unity pass order bug. But without knowing exactly what passes / objects are being rendered and in what order, I have no idea.

    It absolutely presents as a light limit bug, but since it's showing up when you have your pixel light count set to insanely high numbers there is a bug in Unity that can show up sometimes that causes passes to render in the wrong order that can cause this too. If it's the later, than it might not be anything that can be fixed, or might be something that requires modifying the ice shader to solve.

    The suggestions involving tessellation, decal:blend, or post processing sound like red herrings to me as these should have zero impact on this particular bug.
     
    Volchok likes this.
  31. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Thanks for the reply! I'll think and try to catch this bug. :)

     
    Last edited: Sep 12, 2021
  32. RageEntertainment

    RageEntertainment

    Joined:
    Jan 23, 2017
    Posts:
    3
    I hope you got your problem fixed. I had a very similar issue. It was being caused by the material underneath the material that was blinking. I fixed it by changing the Render Queue value on the underneath material to be 1 less than the material I was experiencing the blinking on. It was probably just not setup right from the beginning or I did something else wrong that made that work but just wanted to note this for anyone else that needs something to try.