- Home /
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...)
Answer by tanoshimi · Mar 15, 2017 at 06:56 AM
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.
Answer by Socapex · Mar 15, 2017 at 04:56 AM
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.
Your answer
Follow this Question
Related Questions
Is this the best way to access the Megafiers Morph Channels Dynamically 1 Answer
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Combine Vertex / Fragment and Surface Shader 0 Answers
Clarification on static batching a shader-animated mesh 1 Answer