Search Unity

Question ShaderGraph position node works differently depending on mesh position and size (not scale)

Discussion in 'Shaders' started by B_Kim, Mar 12, 2023.

  1. B_Kim

    B_Kim

    Unity Technologies

    Joined:
    Aug 3, 2022
    Posts:
    1
    Blender export settings
    upload_2023-3-12_17-14-21.png

    Shadergraph
    upload_2023-3-12_17-15-31.png

    Working Case : when object size is withint 2,2,2, world origin is 0,0,0, object pivot is middle (1,1,1)


    Not working when...
    1. the object size exceed 2x2x2, same position with the image above, scale :1


    2. when object origin is on its feet (bottom)


    Expected result :
    Color lerping between top and bottom of the object based on the object's height no matter how big is and when its exported position is like the last picture (origin is its feet where 0,0,0 in my blender scene)


    Hi,

    I'm having an issue with my shader using object position. basically lerping two colours based on object Y axis.

    My expected result is having two colours blendeing between top to bottom of an object no matter how how big or small its size is. and preferably the objects should have pivot at theirs feet (0,0,0)

    I assume the object space in my shadergraph only count 1x1x1 and anything exceeding this area will have the sharp dividing line. wonder if there's any way I can set them as literally object size (scale 1)?

    Any input from you would be very helpful Thanks. Cheers!
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,546
    This is normal behaviour. The position value is relative to the mesh's "pivot" point and are only going to be in the 0-1 range if the pivot is at the feet and the object is export with the top of it only reaching 1 unit high.

    The only way to get the behaviour you're expecting for any arbitrary object is to create a Min and Max property value in your shader graph which you can set on the material, this will be your object bounds' min Y and max Y values to set.

    Then you can use a "remap" function to map the existing position values to 0,1 range using those min/max values.
     
    raaan127 likes this.
  3. raaan127

    raaan127

    Joined:
    Dec 9, 2019
    Posts:
    31
    How can I get object bounds' values in shadergraph?
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,546
    You don't, you get it on the C# side and set the values on some properties you've defined on the graph.
    You can access the bounds from the Renderer component on your object and assign that to the material.
     
    Last edited: Jun 7, 2023
  5. George-Ing

    George-Ing

    Unity Technologies

    Joined:
    Jan 14, 2020
    Posts:
    78
    raaan127 and Invertex like this.
  6. e199

    e199

    Joined:
    Mar 24, 2015
    Posts:
    101