Scaling a Shader to Fit the Object's Size it is Applied to

I have a noise shader. The problem is that it does not scale with the size of the object.
Thus small objects look as if they have one color and big objects look like grain.

How can I scale the shader to achieve a similar look for objects of any size?

You can find the source code here: flolu/threejs-noise-scaling
To start the scene just run npm install and then npm start

Hi!
I think it’s from this SO answer:

If so, then, as an option, you can get the size of an object in world coordinates and use it for calculation of scaling, that you pass in a uniform to shaders:

изображение

PS It’s just an option/idea, not the ultimate solution.

2 Likes

Hm interesting. But look what happens when I add a really big cube:

Do you have any other ideas?

Remove that if condition if (sizeMin < 1) scaling.setScalar(1 / sizeMax); and put scaling.setScalar(1 / sizeMin); instead.

Perfect, I think that’s it! Thank you!