Hi, I tried to mask a part of an object but I have some trouble
What I am doing is a mask based on the world position that update his local position I guess
When I translate on other axis than 0 it works but when translating on other axis AND then rotating, it’s a mess…
I recorded a video with notes that show what happen with the shader I did
If you can help me or suggest other method to mask the object, I would greatly appreciate

https://puu.sh/xqbpH/9c658da2f7.mp4

https://puu.sh/xqaL6/1759feda6e.png

The wip I am working on that can’t end without the shader

2 Likes

The math you have is calculating a plane rotated and scaled to object space, but offset in (scaled) world space. Basically the offset is assumed to be a plane offset from world space 0,0,0. This is due to a curiosity of how Shader Forge’s transform node works. If it actually transformed from world to local space “correctly” moving the object around would have no effect as the plane’s offset would also be in local space.

Basically, your shader works close to how you want mostly by luck and getting it to work all the way is going to require you to do it correctly.

To solve you need to adjust the offset depending on the world position you want the plane to be. To do that you need to set the plane’s offset via script. If you’re doing that I would suggest getting rid of the whole transforming from world to local space and just pass in a world space plane to do the clipping on.

The other alternative is to “fix” the world to local transform so that your mask plane is correctly in local space. Then as you move the blades forward counter animate the plane’s offset. The “fix” is to subtract the object position from the world position before doing the transform from world to local. Once you do that you’ll notice that moving the sword around no longer has any effect. Note that batching can totally break the effect when done this way, or even your original method. Passing a world space plane with a script is the only way to prevent this without disabling batching.

1 Like

Sadly I can’t script, I will wait a friend for this method haha.

That’s what I did in the first place but since I was looking for something working automatically without animating the mask I didn’t use this.
But I guess I have no choice, I will do this and add the local object position to the mask offset value so as the blade move on, the mask will change his offset according to this.

Thank you for your help @bgolus !