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. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Resolved Position : Object node in vertex not working as expected

Discussion in 'Shader Graph' started by Creta_Park, May 10, 2022.

  1. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    76
    Hello.

    Today I was making a shader to make an element swaying in the wind using Shader Graph (12.1).


    The shader I want to create is a shader that rotates and moves vertices around a specific position.
    The goal is to represent plants moving by the wind.

    After completing the Shader Graph, I placed several to test the overall visual, and a problem happend.


    It was as if the Position node's vertex input was being processed at the origin of the world.

    Even weirder, when I switched to the Shaded Wireframe view to check the state of the vertices, I found that the graphics and meshes were displayed separately.

    So I did some more research and found few points of this issue.

    - If this is a situation where batching is possible at once, a problem happened.
    - There was no issues when I connected the Position node directly to the vertex output.

    Below is the Shader Graph where the problem occurs.

    poolish.png
    * Click to see fullsize

    I found a forum post dealing with this issue, but couldn't find a meaningful solution.
    https://forum.unity.com/threads/sha...ion-node-is-wrong-on-multiple-objects.744917/

    I would like to determine the cause of this problem and fix it.

    Anyone familiar with this?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,840
    The issue is the object position node doesn't work on sprites, because those are batched even when you turn off batching.
     
  3. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    76
    Thank you for reply, I see.
    If so, I'm curious as to why this isn't supported well on sprites...

    Is there should do bypass this if there is no other way?
    (i.e. doing workaround at the fragment side... I haven't checked if this works btw)

    + I've seen some posts suggest using GPU instancing, but I'm not sure this is the right way to do it.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,840
    The object position node is making use of the per mesh local to world transform matrix used for rendering. Batched meshes are combined into a single mesh pretransformed into world space, and that matrix is an identity matrix (it has no rotation or transform and a uniform scale of 1). Sprites are batched by default unless you use a shader that supports sprite instancing, and AFAIK Shader Graph shaders don't support Sprite instancing!
     
    Creta_Park likes this.
  5. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    76
    Oh, got it, thank you so much for the useful information.
    I'll have to look into GPU instancing or something else.
     
  6. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    76


    Tried GPU instancing, it's all works well!

    There are still minor issues, but it looks like I'm going to have to compromise.

    upload_2022-5-12_12-41-32.png

    - Unable to get vertex color passed by SpriteRenderer (I think this can be solved by using MaterialPropertyBlock to color it)

    upload_2022-5-12_12-41-7.png

    - Unable to benefit from optimization of sprite atlas ( I found a relate forum post's reply by @bgolus )

    But I've decided to accept it as it is, but if you have any information that for me or anyone visiting with the same problem should know or take note of, please leave a post here.