Rotation of World position coordinates for masking shader

Node-based Shader Editor

Rotation of World position coordinates for masking shader

Postby Cebalan » Thu Aug 23, 2018 12:57 pm

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.
Attachments
ShaderTears2.jpg
Picture of the shader
ShaderTears2.jpg (191.56 KiB) Viewed 3585 times
ShaderTears.jpg
Hope this helps.
ShaderTears.jpg (27.8 KiB) Viewed 3585 times
Cebalan
 
Posts: 3
Joined: Thu Aug 23, 2018 12:14 pm

Re: Rotation of World position coordinates for masking shade

Postby Amplify_Borba » Thu Aug 23, 2018 2:21 pm

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].
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Rotation of World position coordinates for masking shade

Postby Ricardo Teixeira » Mon Sep 03, 2018 11:12 am

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!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Rotation of World position coordinates for masking shade

Postby Cebalan » Mon Sep 03, 2018 11:44 am

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
Cebalan
 
Posts: 3
Joined: Thu Aug 23, 2018 12:14 pm

Re: Rotation of World position coordinates for masking shade

Postby Ricardo Teixeira » Tue Sep 04, 2018 1:35 pm

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!
Attachments
SampleShader.zip
(3.79 KiB) Downloaded 252 times
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Rotation of World position coordinates for masking shade

Postby Cebalan » Tue Sep 04, 2018 2:08 pm

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 :)
Cebalan
 
Posts: 3
Joined: Thu Aug 23, 2018 12:14 pm

Re: Rotation of World position coordinates for masking shade

Postby Ricardo Teixeira » Tue Sep 04, 2018 2:37 pm

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.
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 14 guests

cron