Trouble getting local scale

Node-based Shader Editor

Trouble getting local scale

Postby HarryLight » Thu Aug 02, 2018 8:36 am

Hey,

I'm trying to make a tiling material for a cube by tiling the texture with its scale.
It works well but as soon as the objects transform is rotated the object scale changes.

Is there a way to convert Object scale to local scale?
Or get the local scale in any way?

Thanks
HarryLight
 
Posts: 3
Joined: Thu Aug 02, 2018 8:21 am

Re: Trouble getting local scale

Postby Amplify_Borba » Thu Aug 02, 2018 10:35 am

Hello Harry, thank you for getting in touch and for your support!

Regarding this situation, due to a limitation of Unity's transform and scale, the best possible solution would be to pass the values manually to the shader via scripting in order to accurately calculate the UVs.

As an alternate solution, you may use the TileShader sample that I'm sharing below, which includes a Parent Object Scale function that gets the Object Scale values from the world to object matrix, which are dependent on the relative size and rotations of the object's parent.

TileShaderSample.zip
(15.26 KiB) Downloaded 176 times


Simply use a Break to Components node and use its X and Z outputs in place of the Object Scale node.

Please let me know if this helps, thanks!
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: Trouble getting local scale

Postby HarryLight » Fri Aug 03, 2018 1:51 am

Hey Borba,

Thanks for the quick reply.
I got it all working after updating to the latest version (from your website not the asset store)
That parent object scale function was exactly what I needed.
Image

for those interested in achieving a similar result here is the shader
Image
HarryLight
 
Posts: 3
Joined: Thu Aug 02, 2018 8:21 am

Re: Trouble getting local scale

Postby HarryLight » Fri Aug 03, 2018 6:18 am

I've run it to a bit of a hitch with the system.

It works great until there is more than 1 on screen at once(batched)
Inversing at least one of the objects X,Y or Z scale fixes all of them
A work around for now is to inverse the scale on one axis for all the objects
It always works in the scene view but this error only shows up in game view.
Here is a quick gif:
https://imgur.com/kBIjKKb
HarryLight
 
Posts: 3
Joined: Thu Aug 02, 2018 8:21 am

Re: Trouble getting local scale

Postby Amplify_Borba » Fri Aug 03, 2018 11:39 am

I'm not entirely sure if this is an expected drawback of this solution, since it's not as optimal as passing the values manually. Could you share a simple sample with the issue present so that we may investigate it, as I can't seem to replicate it on my side?
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


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests

cron