Why does my Vertex Animation shader produce different results in Scene and Game view?

Hi!

I’ve been making a game lately, and now I’ve written a simple vertex animation shader which displaces vertices on some vegetation I have, based on some values.

So far, it’s been going OK, but I have some issues when viewing the game side by side with Scene & Game. They produce different results for some reason, and I can’t figure it out. Game and Scene cameras are both set to Isometric.

Here’s how it looks right now:
GIF Link

On the right (Scene) you can see how the vegetation is supposed to look.

Here’s the code bit that is relevant:

// Distance from vertex to model origin.
fixed localDistance = distance(v.vertex.xyz, fixed3(0,0,0));

// Some displacement values.
fixed s = sin(_Time.y * _WindY + v.vertex.x);
fixed c = cos(_Time.y * _WindY + v.vertex.z);

// Add the values to the Y of the vertex.
v.vertex.y += _Shakiness * s * c * localDistance * 0.2;
o.vertex = UnityObjectToClipPos(v.vertex);

(Then we pass the vertex on to the fragment, and so on...)

2 Answers

2

My guess is that your models are being dynamically batched, which will adjust their coordinates as seen by the vertex shader into worldspace in the game view.
Try adding the

"DisableBatching" = "true"

tag to the top of your shader.

This was the correct answer, thank you so much!

Had same issue! TYTY!

How should i format it? StartCoroutine(timeDisabled); ? I haven't really used this, so i'm not sure/

My guess is a problem with time/framerate and somehow that is different in edit mode. Have you tried fixedTime? How / where are you updating the time info?

That's not how this works unfortunately, _Time is a built-in shader variable. There's no script involved at all.

Put a Debug.Log() in your OnCollisionEnter2D() function to see if it is called. But i think it is, because you say that you get stuck, and movementDisabled is never set back to false. Wrap StartCoroutine() around your call to timeDisabled, else it will never pass the yield command.