Search Unity

GPU instancing forcing World space! Bug, feature, or me being dumb?

Discussion in 'Editor & General Support' started by VenandiVatis, Jan 18, 2020.

  1. VenandiVatis

    VenandiVatis

    Joined:
    Dec 5, 2016
    Posts:
    17
    I don't know if this is a bug, a feature, or just me not understanding what the heck I'm doing.
    When GPU instancing is disabled (default for materials), the shader graph position node always uses world space if two objects share the same material. Or at least, that is what it looks like.

    I am using the lightweight render pipeline and having simple shader to lerp the colour in the object (fade from green to blue from top to bottom). Simple, not an issue.
    upload_2020-1-18_10-22-50.png

    As you can see, I am using the position node in object space; I drop a cylinder, into my scene, set the material and all works fine.
    I duplicate the material, drop a new cylinder, assign it the (new) duplicated material. All is good; both objects fade the colour inside each one object space.
    And now comes the problem. If I assign the SAME material to BOTH cylinders, their object space becomes world space. It is not even their combine space, but the world space.
    If I activate GPU instancing on the material, everything goes back to normal and works as (I) expected.

    This how I expect the shader to work (and it does with GPU instancing on)
    upload_2020-1-18_10-26-8.png
    (each object is fading the colour from its top to bottom)

    Now, if I JUST turn off the GPU Instancing, this is the result:
    upload_2020-1-18_10-27-4.png
    You can see that each object is lerping the colour based on their world position (or at least view position).

    If I change the materials of the left two objects, the third one (rightmost) will be the only one using that material, and it will then revert to using object space without the need to change the GPU instancing.
    upload_2020-1-18_10-33-52.png
    You can now see that the rightmost object fades from green to blue in its object space, while the left ones are still using world space.

    Is this how it is supposed to work?

    V