Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 leonalchemist · May 14, 2014 at 02:07 AM · texturematerialtiling

Repeat texture common question

Sooo, really wondering and check tons of pages but couldn't find what i wanted; is there a way to have

a CUBE, with a texture that repeats when scaling instead of streching. That only uses one draw call hence i've seen many people saying i tweak this

 renderer.material.mainTextureScale

but isn't good since it create a new material and extra draw call for every cube; I've seen you can use a tri-planar shader like here: http://www.blog.radiator.debacle.us/2013/02/a-smoother-triplanar-shader-for-unity.html so you can have different material for each side of a cube and only uses one draw call but seem a bit buggy with the position of the texture being off.

So is there a way to fix this problem? basically like what probuilder has by playing around with UVs or shaders, which unfortunately i know nothing of :/

Kind of a big question but i'm clearly not the only one with this issues, plz help us :)

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 robertbu · May 14, 2014 at 03:23 AM 0
Share

Just a note to make sure you understand. $$anonymous$$odifying the material only caused additional draw calls if you have the same material on multiple objects. Also, if all your objects with the same material where the texture scale is set for that material, then all the objects will draw in a single draw call.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · May 14, 2014 at 03:32 AM

I just ran a quick test, and supplying uv coordinates in the mesh that are greater than 1.0 will cause the texture to tile. So the following bit of code, when applied to the built-in cube, will cause the texture to be tiled 5x5 on each side:

 #pragma strict

 function Start() {
 
 var mesh = GetComponent(MeshFilter).mesh;
 var uvs = mesh.uv;
 
     for (var i = 0; i < uvs.Length; i++ ){
         if (uvs[i].x > 0.99) 
             uvs[i].x = 5.0;
         if (uvs[i].y > 0.99)
             uvs[i].y = 5.0;
     }
     
     mesh.uv = uvs;
 }

Note that changing the uv coordinates does not break batching.

Comment
Add comment · Show 9 · 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 leonalchemist · May 14, 2014 at 09:19 PM 0
Share

thanks, that a nice start; though it only really works for one side of the cube, u can only tile the image in the x and y so it's kinda difficult when talking about a 3D object.

I didn't realize that in shader i posted in the link also repeats the texture when scaling the object, but problem is, it seems like the offset of the texture is off; anyone here know a simple fix for that?

avatar image robertbu · May 14, 2014 at 09:26 PM 0
Share

I'm either missing something about your answer, or you are missing something about how uv coordinates work. It does tile all sides of a cube. You can adjust the uv coordinates for any offset and/or tiling. But clearly you are looking for a shader solution. I'd rework and then repost your question looking towards a shader-specific solution.

avatar image leonalchemist · May 14, 2014 at 09:32 PM 0
Share

well yes i know nothing of how UV coding works, but I put in a variable so that i can play around in place of the hard coded tile to 5, and moved everything in the update; but no matter how u go about it the tiling doesnt work properly.

There might be a way to do it without shaders but im not sure how; kinda simple what i want, a texture that tile on a cube no matter which way is scaled. There's no need to repost this question, whether the cube uses a script or a shader does not matter to me, and technically the question would be the same so whats the point?

avatar image robertbu · May 15, 2014 at 01:38 AM 0
Share

The tiling doesn't work properly because this is very simple example...and because I don't have a clear vision of what you mean by properly. I think the modification of the uv will give what you want, but it is up to you to education yourself on how uv coordinates work and therefore how you need to modify the uv array to get the effect you are looking for. You can map any side of the cube to any portion of a texture. You can basically do what renderer.material.mainTextureScale and renderer.material.mainTextureOffset only do it independently on each side of the cube. And you can do it without increasing draw calls.

http://www.rozengain.com/blog/2007/08/26/uv-coordinate-basics/

I suggested a new post if you are primarily looking for a shader solution. There are not a lot of people who answer questions on UA. When you have a somewhat specialized question, you want to draw the person to your question who can give you an answer. Right now someone interested in answering shader questions might not even spot your question.

avatar image leonalchemist · May 15, 2014 at 09:02 PM 0
Share

I'll have a look at the link but looks kinda complicated and i got a feeling there's an easier way; but i don't understand what isn't clear. Scale a cube, texture tiles properly on on side but stretches elsewhere, hence it's not good. I'm just trying to get texture tiling i dont have the time to waste on long problems; i have 500 other issues i have to get to and i've been looking for a solution for the last week so yea im not getting anywhere much :/

Show more comments
avatar image
1

Answer by DevLurkin · Dec 16, 2014 at 05:10 AM

I had a similar need and could't find a complete answer anywhere. I ended up writing my own script that changes the UV map according to the desired scale. You simply attach the script to your Cube's GamObject. Then, anytime you change the scale of your cube you call the reCalcCubeTexture() method. It does the rest.

You should know that because you are customizing the UVs, it creates a mesh instance and the object will no longer use the sharedMesh (it still uses the sharedMaterial). However, I did write in a hack that clears the instance and sets your MeshFilter back to sharedMesh if your cube is ever scaled back to ( 1 , 1 , 1).

It can be found here, and includes a button for your inspector that allows you to change(update) the texture scale in the editor itself. That way you do not have to wait for runtime to see the correct texture.

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 leonalchemist · Dec 16, 2014 at 12:57 PM 0
Share

havent looked at this issue for a while but will check it out later, thx :)

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

22 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 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

Image loaded with LoadImageIntoTexture gets inverted 0 Answers

Error creating a material ? 1 Answer


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