Search code examples
unity-game-engineshader-graph

So I made a curve shader in unity shadergraph


I made a curve shader using shadergraph. But it has a flaw. The current version calculates the offset and adds it to object vertex positions. This works well if the objects forward vector is parallel with world's. If not, it doesn't work like it supposed to.

Subshader Subshader

Example: Blocks with different orientation Example: Blocks with different orientation

Result: The second block which its forward not parallel with worlds Result: The second block which its forward not parallel with worlds

What am I missing here? How can I modify the graph so that the rotation of the model doesn't affect the result? Any unity pros?


Solution

  • Okay, after a couple of trial and error I have managed to come up with a solution. I don't totally understand the transormation matrix but changing the inversemodel to model fix the direction of the objects. But if you do that objects with different scales do not allign with each other. So I divided the result with scale^2 and that's it. If anyone finds it useful here is the final graph.

    Shadergraph