World Position Offset Mesh Face Rotation?

world%20position%20offset

In unreal engine i am using world position offset for this effect and i am facing 2 problems one is faces of mesh are stretching and second is i want to rotation each face on its pivot randomly.

You’re gonna have loads of problem with that. In shader, unless you baked some info on your mesh somewhere position are vertex positions. Not faces. And since vertex shader typically execute on a vert per vert basis, they won’t know about the 2 other verts for a given triangle.

Your options are to bake some fake per face pivots on vertex data (like uvs or very color or something) and operate logic on that fake pivot. Basically need to compute a transform matrix, apply said matrix to fake pivot, then use baked vert data to follow newly transformed fake pivot.

Or to bake your animation using some vertex texture animal pipeline.

Otherwise you’ll just hit a wall trying to keep faces together and uniform.

Also a side note, world position offset is in world space, but position in the shader stack are local. So the stretching is likely because you are missing a space conversion.

What Mederic said. You’ll want to bake the centroids to the vertex colors or UV channels.
See GDC 2019 Tech Art Bootcamp Presentations! - Community - Tech-Artists.Org (Ryan Brucks’ presentation) and Pivot Painter Tool 2.0 in Unreal Engine | Unreal Engine 5.0 Documentation
Those links won’t solve your problem specifically, but they’re related so it might shed some light on how to approach this