Page 1 of 1

Rotation of World position coordinates for masking shader

PostPosted: Thu Aug 23, 2018 12:57 pm
by Cebalan
Heya!

I've currently been spending too much time on this, so I seriously need some help.

What I'm doing is using the distance between the vector 4 origin point (0.0.0.0) and world position surface data X and Z axis, to either render or not render pixels.

However, I want to be able to rotate the object on its Y axis, and retain its cut-off shape relative to the rotation.

What happens now the square remains anchored to X and Z actions of world space, and I simply can't get that to rotate with it accordingly.
Also, I can't use Vertex Position instead of World position node, as this shader will be used by several objects that need to be masked to the same shape, with the same border and etc.

Hope this explains better:
Image

Here is the visual composer of the shader:
Image

Edit: Can't seem to attach the shader, but if you need more info, lemme know. I'm pretty new to programming and shaders in general, so I apologize for all the reduntant nodes and loops probably in there.

Re: Rotation of World position coordinates for masking shade

PostPosted: Thu Aug 23, 2018 2:21 pm
by Amplify_Borba
Hello, thank you for getting in touch and for your support!

Could you please send us your shader, since its setup is somewhat complex and we'd like to replicate the issue you're having using in the exact same conditions?

You might have to zip your shader file in order to share it in this forum, but alternatively you can also send it through [email protected].

Re: Rotation of World position coordinates for masking shade

PostPosted: Mon Sep 03, 2018 11:12 am
by Ricardo Teixeira
Cebalan wrote:Heya!

I've currently been spending too much time on this, so I seriously need some help.

What I'm doing is using the distance between the vector 4 origin point (0.0.0.0) and world position surface data X and Z axis, to either render or not render pixels.

However, I want to be able to rotate the object on its Y axis, and retain its cut-off shape relative to the rotation.

What happens now the square remains anchored to X and Z actions of world space, and I simply can't get that to rotate with it accordingly.
Also, I can't use Vertex Position instead of World position node, as this shader will be used by several objects that need to be masked to the same shape, with the same border and etc.

Hope this explains better:
Image

Here is the visual composer of the shader:
Image

Edit: Can't seem to attach the shader, but if you need more info, lemme know. I'm pretty new to programming and shaders in general, so I apologize for all the reduntant nodes and loops probably in there.



Hello there,

Apologies for the delay, Amplify_Borba is going to be away for a weeks or so.

I should point out that this forum is aimed mostly at editor support, for general development questions I recommend posting in the public Unity forum, the chances of getting some general feedback there are much higher.

I'm having some difficulty understanding what the issue is exactly, could you please elaborate on what you mean about what you cant to "Cutoff"?

Thanks!

Re: Rotation of World position coordinates for masking shade

PostPosted: Mon Sep 03, 2018 11:44 am
by Cebalan
Thanks for getting back to me!

Thanks for the tip, if we can't work it out here, I'll make sure I repost in the public unity forum.

The issue i'm currently having is dat I want to cut out a square in a set of large objects. Everything outside a set distance should not render (and thus is cut-off).
This way we end up with a floating square in empty space. All objects entering the square (wearing the shader) will be rendered at the exact same cut-off line.

I want to be able to rotate the square, but because I use World Position, the square doesn't rotate. I can rotate the content, but not the shape in which it is cut off.
Did you find the shader I sent Borba?

Currently I calculate distance between an origin point vector 4, and the world space position vector 4.
If the x or Z vallue is greater then a set distance (a float property,) i've made sure it will only render empty space, If I would use XYZ i'd get a circle, but I've split the X and the Z values to get a square.
But those X and Z values are always in line with world space X and Z, and thus can't be rotated.
For that, I need to recalculate those values for a rotation on Y axis, but can't get that to work. I've seen formulas using Sin and the like, but I can't get it to work. Probably because I am in way over my head and I'm missing something very obvious.

I hope its somewhat clearer now?

If this is something you can't help me with, let me know. But if you can point me in the right direction, you'd be helping me out a-lot.

-Matt

Re: Rotation of World position coordinates for masking shade

PostPosted: Tue Sep 04, 2018 1:35 pm
by Ricardo Teixeira
Cebalan wrote:Thanks for getting back to me!

Thanks for the tip, if we can't work it out here, I'll make sure I repost in the public unity forum.

The issue i'm currently having is dat I want to cut out a square in a set of large objects. Everything outside a set distance should not render (and thus is cut-off).
This way we end up with a floating square in empty space. All objects entering the square (wearing the shader) will be rendered at the exact same cut-off line.

I want to be able to rotate the square, but because I use World Position, the square doesn't rotate. I can rotate the content, but not the shape in which it is cut off.
Did you find the shader I sent Borba?

Currently I calculate distance between an origin point vector 4, and the world space position vector 4.
If the x or Z vallue is greater then a set distance (a float property,) i've made sure it will only render empty space, If I would use XYZ i'd get a circle, but I've split the X and the Z values to get a square.
But those X and Z values are always in line with world space X and Z, and thus can't be rotated.
For that, I need to recalculate those values for a rotation on Y axis, but can't get that to work. I've seen formulas using Sin and the like, but I can't get it to work. Probably because I am in way over my head and I'm missing something very obvious.

I hope its somewhat clearer now?

If this is something you can't help me with, let me know. But if you can point me in the right direction, you'd be helping me out a-lot.

-Matt



No problem!

Have you had a chance to check the Rotate Around Axis and BoxMask(Shader Function, source included) nodes?

I attached the Rotate About Axis sample to this reply along with an example of how to do it manually.

Hope it helps!

Re: Rotation of World position coordinates for masking shade

PostPosted: Tue Sep 04, 2018 2:08 pm
by Cebalan
Hero!

I couldn't get the Rotate about Axis to work, because I didn't understand I needed to feed the rotational axis this way to the node (a vector 4 with the rotating axis at '1'). With your example I managed to get the rotation working. So now I can rotate the entire shader.

I'm now heading into looking if the Boxmask node replaces my entire blood-sweat-and-tears-wrought shader....

Thanks :)

Re: Rotation of World position coordinates for masking shade

PostPosted: Tue Sep 04, 2018 2:37 pm
by Ricardo Teixeira
Cebalan wrote:Hero!

I couldn't get the Rotate about Axis to work, because I didn't understand I needed to feed the rotational axis this way to the node (a vector 4 with the rotating axis at '1'). With your example I managed to get the rotation working. So now I can rotate the entire shader.

I'm now heading into looking if the Boxmask node replaces my entire blood-sweat-and-tears-wrought shader....

Thanks :)


Good luck, hope it helps!

Double-click a shader function, such as the Box Mask, to open it in the editor. Be sure that you also compile the shader using the SF if you alter it.