Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 SirMacJefferson · Oct 07, 2013 at 06:01 AM · texturematerialtiling

Tiling a material using game units

Hey,

I'm trying to figure out if there's some way to make a material tile a texture using game units instead of tiling it based on the size of the object.

For example, in the image below, there are 2 quads using the same material, but the material doesn't look the same on both of them because the quad on the right is larger than the one on the left:

alt text

So, the tiling settings in the material mean if it's set to 1x1, it'll put the texture across the whole surface once; if it's set to 2x2, it'll put the texture across the whole surface 4 times. If the surface is huge, the texture will be a lot more visible; if the surface is tiny, the texture will be shrunken.

Is there any way to make it tile the texture based on game units? For example, if it was set to 1x1 tiling, then it could tile it 4 times per game unit, so if I had a quad with 4 units of size, it'd tile 4 times, not just once across the whole quad.

Sorry if I've typed up a storm and made this more difficult to understand than it has to be; if I haven't explained enough, please let me know. Thanks for reading this far, and thank you for your time!

material example.png (482.8 kB)
Comment
Add comment · Show 1
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 sethuraj · Oct 07, 2013 at 06:13 AM 0
Share

try normalizing the tiling value to object scaling.I didnt try this but try something like this (UVTiling/Localscale)*FixedScaleVal

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Oct 07, 2013 at 04:35 PM

You can set the texture scale at runtime. I think that is what @sethuraj is suggesting:

 renderer.material.SetTextureScale ("_MainTex", transform.localScale);

Note this line of code assumes that your shader is using _MainTex as the texture (most do). It is also assuming that you are basing your texture on the X and Y of the local scale of the object (true of Quad). Wouldn't work for a Plane for example, you would need instead:

 renderer.material.SetTextureScale ("_MainTex", Vector2(transform.localScale.x, transform.localScale.z));

Note setting the local scale breaks batching, so if you are going to do this for many game object, you might want to look for an alternate solution.

Comment
Add comment · Show 1 · 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 SirMacJefferson · Oct 09, 2013 at 07:01 AM 0
Share

Thanks for the answer. That works great for planes and quads, but what about with a customized shape, like a level? For example, if you had a wall that twists and turns at various locations and you wanted to put a texture across it, how would you apply your code to that situation?

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.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture is Tied to Two Cubes 1 Answer

Real Sized Texture Tiling 2 Answers

Multiple random tiled textures in one material 1 Answer

Tiling material with multiple textures. 1 Answer

Image loaded with LoadImageIntoTexture gets inverted 0 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