2
\$\begingroup\$

Ambiguity: What exactly is the difference between Tiling the material and Offset of material?

Need to do:

I need the material to be repeated n times on the object where I need to set the value of n via script.How do I do it?

It seems to happen through Tiling(tried via inspector) but again what is difference between mainTextureOffset and setTextureOffset?

Tried:

Following is the line of code that I tried to repeat the texture n number of times on an object(repeat across the width of object), but it does nothing significant that I can see.

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

What exactly is the difference between Tiling the material and Offset of material?

Those parameters set by the inspector are used inside the shader to scale the texture coordinates. A uniform float4 in the shader with the name of the texture and _ST suffix is populated with those values. For example considered the main texture:

float2 scaled_uv = tex.uv * _MainTex_ST.xy + _MainTex_ST.zw;

Let's say the offset basically translate the texture in the uv space meanwhile the scale, scales it.

mainTextureOffset: set the texture offset of the main texture (texture binded to the name _MainTex inside a shader)

SetTextureOffset let you specify the texture name. SetTexureOffset(_MainTex, offset);is equivalent to use the facility mainTextureOffset.

An alternative is setting directly the uniform vector. The used convention for built-in shaders is using the suffix _ST to the texture name. So you can also use SetVector:

material.SetVector("_MainTex_ST", scaleAndOffset);

EDIT

For repeat the texture you have to modify the scale not the offset. If you set for example a scale of 2 along an uv axis you will obtain to repeat the texture twice along it.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks you,So, I guess offset should do the repeating of texture n times? \$\endgroup\$
    – systemdebt
    Commented Aug 23, 2014 at 0:22
1
\$\begingroup\$

Documentation on the website which also happens to be the first search result for the term SetTextureOffset or mainTextureOffset seems to sum up the issue nicely.

Material.SetTextureOffset

function SetTextureOffset (propertyName : String, offset : Vector2) : void

Description

Sets the placement offset of texture propertyName.

Common texture names used by Unity's builtin shaders:

  • "_MainTex" is the main diffuse texture. This can also be accessed via mainTextureOffset property.
  • "_BumpMap" is the normal map.
  • "_Cube" is the reflection cubemap.

Material.mainTextureOffset

var mainTextureOffset: Vector2;

Description

The texture offset of the main texture.

The same as using GetTextureOffset or SetTextureOffset with "_MainTex" name

A material has a main texture, which is the one you see. Additionally, it can have other textures, such as a bump or cube map which affect how the object's appearance is calculated. mainTextureOffset only affects the material's main texture. SetTextureOffset lets you specify the name of the texture to offset, so SetTextureOffset("_MainTex", .05) would be eqivalent to mainTextureOffset = .05;

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .