Can texture tiling /offset be controlled from an outside value?

Hi!

I’m trying to build a shader that blends 2 textures based on a splat map - actually I already did, but now the splat map is the same for each object that uses the same material - if I change the offset and tiling numbers in one user, they all change.

So is there a away to instead pick numbers for the tiling and offset from the object that uses the material? Or is there another way to vary the numbers without creating separate materials (=waste, misses the whole point)

Thanks!

Anyone?

Found this:

renderer.material.SetTextureOffset(“_MainTex”, new Vector2(offset, 0));

And it works, but what really happens? If I have 2 objects sharing a material, and I change the offset in one of them like this, will it create another material and affect performance?

Don’t use tiling and offset. Use UVs.

Any time you change something with renderer.material, you create instances of the material. When in doubt, use renderer.sharedMaterial.

Thanks!

That’s what I’m trying to avoid - creating extra instances of the material! But what exactly do you mean by using the UVs?

I was trying to vary the texture on instances of the same object - the UVs on those would be identical (like 2 cubes for example)

Here’s a screenie - using the offset idea:

There are 2 unity cubes using -originally- the same material. I used the script to offset the splatmap and changed the color just to make it clear. But the point is, the meshes would be identical anyway.

Won’t work. You need different meshes. It’s annoying, sure, so don’t do it unless you need the performance.

Wannabe, what you are perhaps missing is that meshes that have the same vertex positions and normals can have different UV coordinates. UVs are the per-vertex values that are scaled and biased by a material’s tiling an offset values. Instead of leaving the transformation up to the shader, which will treat identical meshes identically, you should use custom meshes with the UV coordinates that you want. You can modify mesh UVs using the Mesh interface, so instead of making custom models in an editor, perhaps you just want a script that applies custom tiling and offset values directly to mesh data. The cool thing about this approach is that MeshFilter.mesh will instance on first access, just like Renderer.material, so you don’t have to worry about manually copying your meshes.

Thanks, guys!

Hmm, I only need to offset the splat map, so probably altering the UVs won’t work either?

Let me explain more clearly what I’m after - I want to create tileable wall pieces, brick or whatever, and then apply a second normal map to create “unique” damage on the tiles - like cracks etc. For this uniqueness, I would need to offset the splat map that controls the visibility of the second normal map, here’s the shader I made with Strumpy Shader Editor (I’m completely new to shaders, so it might be wrong, but you’ll get the idea)

This is the shader that I used with those cubes. Of course, in the real project, I would have custom meshes instead.

Use the second UV set for the splat map, and modify that using the Mesh class instead.

Thanks,

But isn’t that for lightmaps? Or did I misunderstand you?