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

Using object-space coordinate as uv, handle vertical faces

Discussion in 'Shaders' started by bitinn, May 28, 2020.

  1. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    So here is something I am trying to do:

    - Given any object, a Cube for example,
    - Take it's object-space xz as uv coordinate, pass from vertex to fragment,
    - Sample a tiling texture in fragment.

    This works really well for the top face, but not so much for the vertical faces.

    - What I want to do, is to project all these vertical faces (vertices), to as-if they are on the same plane as the top face, so that the UV is continuous, but aligned to the top face.

    Questions:

    - I want to do it in the vertex shader, any tips on how can I make it happen?
    - I can probably hack to make it work on a cube, but how about any primitive shape?

    Thx!