Page 1 of 1

Trouble getting local scale

PostPosted: Thu Aug 02, 2018 8:36 am
by HarryLight
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

Re: Trouble getting local scale

PostPosted: Thu Aug 02, 2018 10:35 am
by Amplify_Borba
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 273 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!

Re: Trouble getting local scale

PostPosted: Fri Aug 03, 2018 1:51 am
by HarryLight
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

Re: Trouble getting local scale

PostPosted: Fri Aug 03, 2018 6:18 am
by HarryLight
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

Re: Trouble getting local scale

PostPosted: Fri Aug 03, 2018 11:39 am
by Amplify_Borba
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?