Position : Object node in vertex not working as expected

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.


* Click to see fullsize

I found a forum post dealing with this issue, but couldn’t find a meaningful solution.

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

Anyone familiar with this?

The issue is the object position node doesn’t work on sprites, because those are batched even when you turn off batching.

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.

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!

Oh, got it, thank you so much for the useful information.
I’ll have to look into GPU instancing or something else.

Tried GPU instancing, it’s all works well!

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

8121338--1052609--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)

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.

I’m encountering the same problem here. I’m trying to color sprites using their scale and position but it doesn’t work if I use GPU instancing. But if I use GPU instancing I then can’t use the vertex color (but for some reason I can still use the alpha of the vertex color, I’m confused)

Has anyone figured out a solution to get the best of both worlds?