简体   繁体   中英

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

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...)

Your models are dynamically batched in the Game view. But in Scene view, it doesn't happen.

Dynamic batching: for small enough Meshes, this transforms their vertices on the CPU, groups many similar vertices together, and draws them all in one go. Because it works by transforming all GameObject vertices into world space on the CPU, it is only an advantage if that work is smaller than doing a draw call.

You can add a DisableBatching to your SubShader to disable dynamic batching.

Some shaders (mostly ones that do object-space vertex deformations ) do not work when Draw Call Batching is used – that's because batching transforms all geometry into world space, so “object space” is lost.

DisableBatching tag can be used to incidate that. There are three possible values: “True” (always disables batching for this shader), “False” (does not disable batching; this is default) and “LODFading” (disable batching when LOD fading is active; mostly used on trees).

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM