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

Resolved 80s style grid shader noise

Discussion in 'Shader Graph' started by Red_Dragon69, Aug 15, 2023.

  1. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    90
    Hi,
    I'm currently trying to create an 80s style grid shader, but when I set the grid to very high values, it's showing (at least afaik) a moire effect. Does anyone know how to reduce or remove this effect? Or am I barking up the wrong tree?

    Shader:
    upload_2023-8-15_22-39-44.png

    Effect:
    upload_2023-8-15_22-40-16.png

    br,
    Max
     
  2. NXRT_MA

    NXRT_MA

    Joined:
    Jun 13, 2023
    Posts:
    4
    Red_Dragon69 likes this.
  3. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    This is a tricky problem. The issue you're seeing is aliasing - which is a classic issue in computer graphics that engineers have been trying to solve for decades. When you sample a texture, for example, the graphics hardware has built-in hardware for filtering to solve this problem.

    You're generating the pattern procedurally, so you have to build the solution into your graph itself rather than relying on the hardware to do it for you. If you sampled a small grid texture instead of using a procedural solution, that would probably be the easiest way to solve it.

    Another solution would be to generate the grid using a Signed Distance Field - where up close and when looking straight at it, the SDF produced sharp results, but at glancing angles and further away, it produced slightly blurry results. If I get some free time this week, I'll see if I can implement something like that and post it. In the mean time, see if you can implement the solution that Inigo Quilez developed that's quoted in the Stackoverflow link that NXRT_MA posted above.
     
  4. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    90
    Thank you for your reply Ben and NXRT_MA. Already played around with the provided link and it worked out pretty nice, even when the grid is moving! The shader is a little bit more complicated now, but that's not a problem :)

    upload_2023-8-17_18-2-44.png
    upload_2023-8-17_18-10-49.png
    upload_2023-8-17_18-10-58.png
    upload_2023-8-17_18-13-20.png
     

    Attached Files:

  5. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    Great work, congrats!
     
    Red_Dragon69 likes this.
  6. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    58
    Ah, that's cool. I had suggested a similar solution of averaging towards a single pixel color in an older thread but never worked out how the graph for it might work. I'll have to test through and try this out at some point.
     
    Red_Dragon69 likes this.