• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ghart · Sep 27, 2011 at 02:19 AM · textureuv

How does textureScale work?

When I setTextureScale = 0.5, I would expect the texture to be half the size, but in fact, it makes it bigger but less than twice as big. What's the math going on here that I'm not understanding?

Thanks for any tips,

-Greg

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Sep 27, 2011 at 02:23 AM

Those parameters transforms the incoming uv-coordinates of your model.

The math is quite simple:

 u = u * scale.x + offset.x;
 v = v * scale.y + offset.y;

So in a simple case like a texture on a plane you will have 4 uv pairs, one for each corner. If you have a scale of (1.0, 0.5) and an offset of (0.1, 0) that's what happens:

 u  v
 
 0, 0 --> 0.1,  0
 0, 1 --> 0.1,  0.5
 1, 1 --> 1.1,  0.5
 1, 0 --> 1.1,  0

Usually the coordinate 0, 0 represents the lower left corner of the texture. That means the texture is shifted in x-direction 10% to the left and therefore you will see 10% of the repeated texture on the right side. No shift in y-direction but the coordinates are scaled down. The lower edge will stay at 0 but the upper edge of the plane is mapped to 0.5 instead of 1.0 so you will see only the lower half of the texture streched over the plane.

Texture coordinates doesn't change the mesh, just where a triangle is "located" on the texture (in texture-space). If you have unwrapped a model you should know that ;)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ghart · Sep 27, 2011 at 05:03 PM 0
Share

O$$anonymous$$ thanks Bunny83. $$anonymous$$akes sense, setTextureScale is transfor$$anonymous$$g the uv-coordinates, not the texture itself. But when I do this:

 renderer.material.SetTextureScale ("_$$anonymous$$ainTex", Vector2(1,0.2));
 renderer.material.SetTextureOffset ("_$$anonymous$$ainTex", Vector2(0,0.1));

the offset.y appears to be 10% of the newly scaled uv's, not the original uv's on the model. Is there a way to transform the uv's (scale and offset) in one operation, both based on my original model's uv's? Thanks again.

avatar image Bunny83 · Sep 28, 2011 at 12:25 AM 0
Share

I've converted your "answer" into a comment.

I can't verify that. When i scale y down to 0.1 i see only 10% of the texture. If i use an offset of 0.1 it will shift the texture by 100% so nothing of the previous part is visible anymore and i see the the second "stripe" of the texture (so the next 10% of the whole texture). If i want the "new" texture part to be shifted by 10% i have to use 0.01 as offset.

The calculation works exactly like i said ;)

Ohh and i actually tried it now by code just to verify it's really the same: If you view your GameObject in the inspector you can see the $$anonymous$$aterial properties. Usually (at least the diffuse shader) you can see the texture offset and scale properties. You can set them manually in the editor and have a live-preview in the sceneview.

When using SetTextureScale from a script you can see the same values in the inspector.

Also keep in $$anonymous$$d that the vanishing point of the scaling is always the bottom left of the texture (coordinate 0, 0). Scaling around a certain point is a bit tricky and requires some calculations since it will also change the offset.

I guess it would be easier if you could explain what you want to achieve ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Trouble with UV Mapping Blender => Unity 3 1 Answer

Blender UV map texture problem? 1 Answer

Weird "ghost" texture issue with Transparent Texture/Shader 2 Answers

RaycastHit textureCoords return Vector2.zero on iOS only despite proper setup 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges