Compare two meshes / world coordinates

Hi, I want to know if it is possible to compare “IN.worldPos.y” of two mesh.

One simple example, I have a reference mesh.
The “IN.worldPos.y” of this reference mesh should be compare with the “IN.worldPos.y” from an other mesh in a shader
So then I could calculate the difference of the the y coordinates and apply some proprietes if it is positive or negative

The other solution were to get the initial position of each vertex and compare them with the new position of each vertex

Is this one of this stuff possible ?
Thanks

Are you trying to compare the vertex positions of two different meshes, or just one vertex position with its position from the previous frame? If it’s the latter, your best bet is to reproduce the MVP matrix each frame, and feed it to the shader from a script.

Hello Daniel, just stumbled upon this post and was actually wondering what would be the approach to the first situation.
Comparing the difference between 2 meshes’ vertex position (all vertex), the idea is actually to get like a DIFF from two meshes represented by a change in vertex color or something.

Are you working in a shader? Have you tried using things from UnityCG?
In a shader beteween the GGPROGRAM and ENDCG add #include UnityGC.cginc then you can do things like mul(unity_ObjectToWorld, v.vertex); where v is a struct for your mesh vertices (often people call this struct appdata) passed as a param into your vertex shader. unity_ObjectToWorld is a 4x4 matrix that takes vertices in object coords and puts them in world coords.

1 Like

Thanks a bunch for the suggestion filrod_ubi, going to try that out.