Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Random UV offset flickering

Discussion in 'Shader Graph' started by od3098, Jul 24, 2023.

  1. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    I am using this simple shader to randomly offset UV of a texture:
    upload_2023-7-24_15-29-49.png

    The problem is that in game/scene view, the offset flickers randomly. like the result of the random range will change sometimes.
    - Tried using different seeds. same.
    - Tried using different seeds before combining, same.

    What may have caused this?

    flickering.gif
     
  2. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    Update: Tried Unity 2022.3.5f1
    Same results
     
  3. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    What values are you using for a Seed input parameter?
     
  4. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    1 to 7 and some float values. I was trying to implement your Hash23 from your YouTube and saw the flickering. I suspected the problem was for my implementation, so I tried to use a built-in random generation method and saw this.
     
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    If you provide us specific values, then everyone should be able to reproduce your case.
    I tried to recreate your graph and by pure luck I was able get some flicker, but then I could not reproduce it no matter what and I don't know what number was there.

    The whole thing looks like some precision issue, but I fail to see why that would happen.
    Also I observe your gif now and what is the condition to trigger this? It looks like it started flickering when you selected the object.
     
  6. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    The gif is captured with 1 as seed value.
    - Scene-View: I suspect moving mouse cursor/ changing view direction in scene view/ selecting and deselecting objects will trigger the flickering. So maybe on repaint event or something? (Always refresh is on)
    - Game-View: When I enter play mode, it begins.
     
  7. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    I copied the shader to my MacBook, and it did not happen there.
    Host 1 - Windows 11 + NVIDIA GeForce RTX 3070 Laptop + 536.67 GeForce Driver version
    Host 2 - MacBook Pro M2 Max
     
    Qriva likes this.
  8. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    There is a weakness in the algorithm we're using in the Random Range node. It's similar to the one I introduced in my YouTube video. It's using the sine function, and unfortunately, the sine function is implemented in different ways in different hardware. Some hardware implements it in a more robust way, and other hardware uses a faster approximation that can be slightly inaccurate. For some applications, these issues aren't noticeable, but the one you've created here - basing your UV grid on the random value, makes the inaccuracy very obvious. We've fixed these issues recently in the Gradient Noise, Simple Noise, and Voronoi nodes with the addition of the Hash Type dropdown. The Deterministic option in that new dropdown uses our new noise algorithm which is much more robust. But the Random Range node is still using the older, weaker algorithm. I'll put in a bug report to get the Random Range node updated. In the mean time, can you use the Simple Noise node to get the effect you're trying to achieve?
     
    lilacsky824, Qriva and od3098 like this.
  9. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    Thank you for following up. Yes, I will try to achieve that with simple noise node.
     
  10. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    So in short some hardware can produce different results for the same input for sine?