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

Shader that draws a grid in pixels

Discussion in 'Shaders' started by valtteri_m, Sep 18, 2019.

  1. valtteri_m

    valtteri_m

    Joined:
    Aug 6, 2014
    Posts:
    15
    Im having a real hard time getting this, so Ive come here for help.

    I just want a shader that draws pixel thick grid lines vertically and horizontally with a property for how big those grid cells are in pixels.

    I would use it to render a grid overlay onto the screen using blit by the way.
     
  2. Sh-Shahrabi

    Sh-Shahrabi

    Joined:
    Sep 28, 2018
    Posts:
    56
  3. valtteri_m

    valtteri_m

    Joined:
    Aug 6, 2014
    Posts:
    15
    Any examples that dont require the viewport resolution (iResolution) ?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    ShaderToy shaders are just using the resolution to get usable UVs as the only input ShaderToy has is the screen pixel index (gl_fragCoord). If you're planning on doing with a blit, you can just use the UVs, though the aspect ratio won't match the screen unless you correct for it ... using the screen resolution in _ScreenParams.xy.

    However if you're not planning on doing pixel perfect grid, I highly recommend you use an anti-aliased line solution, like shown here:
    https://www.shadertoy.com/view/XtBfzz
     
    Rowlan likes this.