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

Question Shader for clipping along the axes?

Discussion in 'Shader Graph' started by JaimeGranel, Mar 27, 2023.

  1. JaimeGranel

    JaimeGranel

    Joined:
    Nov 6, 2020
    Posts:
    22
    Hello, I'm trying to make a shader that clips an object along the axes of the world and I'm having some issues. This is the logic that I'm using.
    upload_2023-3-27_13-8-58.png

    My first problem is that I would like to use a value ranging from 0 to 1 to clip half of a shape. In the following example, I'm using a plane, a sphere, and a cube in Unity. As you can see, it works well for the cube and the sphere, but it fails for the plane (as they both share the same material).


    upload_2023-3-27_13-19-36.png

    My second problem is that in the project I'm working on, I have been provided with objects that don't have the center of coordinates at the center of the mesh (this is inevitable due to how scenes are constructed). Here's an example of the second source of the problem. As you can see, despite having the same values as the previous shape, the displaced center of coordinates doesn't place the clip at the center.

    upload_2023-3-27_13-21-44.png
     
    Last edited: Mar 27, 2023
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,973
    Would it be possible to use UVs as input? Then it can work with 1 material on multiple meshes
     
  3. JaimeGranel

    JaimeGranel

    Joined:
    Nov 6, 2020
    Posts:
    22
    Maybe it would be an option. What do you suggest doing with the UVs?
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,973
    You can get UV (you can use multiple UVs if needed for texturing as well) info and then for example start to clip halfway.
     
  5. JaimeGranel

    JaimeGranel

    Joined:
    Nov 6, 2020
    Posts:
    22
    Apparently, I am lacking some knowledge in this subject as I was assigned this task because we don't have a shader specialist. Would you recommend me any guide, website or video that explains how to do it?
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,973
    Google unity shader graph uv scroll

    Might get you to understand them better