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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Hide some region of pixels

Discussion in 'General Graphics' started by etri3600, Jun 30, 2017.

  1. etri3600

    etri3600

    Joined:
    Jul 29, 2016
    Posts:
    2
    Hello.

    I've made 3D model equipment system.
    My character can wear serveral parts like pants, boots, shirts, hats, etc.
    And some combinations have conflict, for example long boots and pants.

    Therefore I want to hide some region of pixels.(Some games use it)
    1st, To make box in each model for selecting hidden region by 3ds Max.
    2nd, Copying vertex positions to uv3 channel.(vertex position is changed by animation)
    3rd, Calculating all boxes for obb(oriented bounding box).
    4th, When character equips parts, send box information to shader.
    5th, In shader, make sure that vertex position(in uv3 channel) is inside box.

    But in second step, vertex and uv values are different in shader even same in cpu.
    Just change UnityObjectToClipPos(i.pos) to UnityObjectToClipPos(i.uv3_VertexPos), but all transformation (position, rotation, scale) are difference.
    I also used renderer.rootBone.TransformPoint, renderer.TransformPoint through copying position to uv, but rotation and position are difference(Scale is right).

    How can I send right vertex information to uv?
    Or Is there another good way to hide some regions?
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Wow! This is a really cool and complex concept to mask hidden parts of a mesh that overlap other parts of a mesh.

    The shader process you are attempting is most likely more optimal - if you can figure it out - and is a very cool idea, but I have no input on how it can be fixed to work correctly.

    I'm pretty sure there is no built in solution for this - however there might be an alternate way to set up a system in engine that swaps a transparent mask - depending upon the other clothes that are applied to the character.

    Using the example you provided - boots and long pants.
    If the character is wearing boots and long pants - the system would load up this transparent mask for the boots, essentially hiding the polygons you do not want to overlap with the pants.
    Dark grey used in place of black just for example purposes.
    upload_2017-6-30_10-57-58.png



    When the player is equipped with longer pants the system would load up this transparent mask for the boots.
    upload_2017-6-30_10-59-53.png

    When the player is equipped with shorter pants the system would load up this transparent mask for the boots.
    upload_2017-6-30_11-1-13.png

    And when the player is equipped with shorts and boots - the system would load up either a complete white transparent mask or just not load a mask map at all because it is not needed when the character is wearing shorts with boots.
     
  3. KILEYI

    KILEYI

    Joined:
    Mar 7, 2015
    Posts:
    52
    If it only depends on the height, y position.
    You can just disable height above that value.
    It will be a Y cut shader.Up down or down up order.
    X and Z may be the same
     
    theANMATOR2b likes this.
  4. etri3600

    etri3600

    Joined:
    Jul 29, 2016
    Posts:
    2
    Thanks for replying.
    But it's not depend on the height. Boxes can be exist any position and rotation.