In Unity we created a shader graph that changes the offset of the texture according to the scale of the object. The purpose of the shader is to implement, for example, “a puzzle in which a treasure map is divided into multiple panels and then arrang panels to solve the puzzle”. The conditions for shaders are as follows:
If prepare a parameter to control the offset of the texture in the shader, it can changes the display position of the texture for each object, but in that case, multiple materials are required. Also, if the UV map of the object is offset, only one material is required, but in that case, as many objects as there are matrices are required.
So we tried to create a shader, but we didn’t know how to change the behavior of the shader with the same object and material.
Shader parameters can be changed from the script, but in that case the material will be changed for each object.
Finaly, we searched and found the “Object” node in the graph.
This node can capture the position and scale of the target object as parameters. The object position changes depending on the sort, so the position parameter cannot be used.
The other parameter, scale, changes the appearance of the panel when it is changed significantly, so make a small scale difference (1.00 to 1.15 times each panel if divided into 4×4) in the depth (Z direction), and we use this parameter for the shader.
The shader convert the scale to the texture offset, when scale = 1.00 then the offset is (0.0, 0.0), when scale = 1.03 then offset = (0.75, 0.0), when scale = 1.12 then offset = (0.0, 0.75), and so on.
The example belowapplies this shader. (not a treasure map)
In the figure, 25 objects of 5×5 are lined up, but only four mask objects (prefabs) of “circle”, “square”, “rhombus”, and “hexagon” shape type are used, and the same material is applied to each. The mask objects look the same at first glance, but its Z-direction scale is changed by 1.00 to 1.24 times from the lower left to the upper right, showing different offset positions of the same texture.
We think there are the way to pass different parameters (by UV value) for each object, like the particle system, but that quest will come later.