Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Texture stretched when object is scaled

Discussion in 'General Graphics' started by i3artyy2222, Sep 16, 2015.

  1. i3artyy2222

    i3artyy2222

    Joined:
    Aug 18, 2013
    Posts:
    274
    Hi there, i have problem while making my game [basically im nearly done with all the scripting and now moving to texturing] . And here it is first problem
    Why when i try to scale an object for example a cube the texture stretches on top [or if i make Y axis bigger than X then it stretches on sides] but why does it stretches ? I looked on google for about 2 hours now or even more and the 'closest i want result' i would was a shader 'triplanar texture shader' or something like the effect was as i wanted but it was just plain texture no bumped diffuse.
    Any idea how to make normal texture like not to be stretched ? Did you saw any videos/tutorials/posts/threads or something that might help :?
    Please guys cuz these stretched textures doesnt look really good and there is not enough about it on the internet .


    Thanks for helping!
     

    Attached Files:

    • exam.PNG
      exam.PNG
      File size:
      352.8 KB
      Views:
      1,852
  2. i3artyy2222

    i3artyy2222

    Joined:
    Aug 18, 2013
    Posts:
    274
    Anyone :? i looked up to 5th page of google about 'unity texture stretched problem' and didnt found solution
     
  3. MattGen

    MattGen

    Joined:
    May 12, 2015
    Posts:
    63
    Select concerned textures in the project tab. In the inspector tab appeared import settings where you can fin "Wrap mode", try switching "repeat" instead of "clamp".

    [edit] (wtf was I saying ? oh it was 4 am ok lol)
     
    Last edited: Sep 17, 2015
  4. i3artyy2222

    i3artyy2222

    Joined:
    Aug 18, 2013
    Posts:
    274
    I did all of the textures are set at 'repeat' and still the same thing :/
     
  5. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    of course it's going to stretch, when you scale an object you don't scale it's uv coordinates with it. You'll have to either change the tilling settings of the material or make your UV according to the size of the object.
     
    MattGen likes this.
  6. i3artyy2222

    i3artyy2222

    Joined:
    Aug 18, 2013
    Posts:
    274
    If i just change tiling settings it either work on sides on box or top and bottom of box
     
    ThatCodingKid likes this.
  7. Haxel0rd

    Haxel0rd

    Joined:
    May 20, 2021
    Posts:
    49
    I have the same Prolem and expected an inbuilt solution from unity.

    Tiling is not a solution, as it requires to dupe the material with different tiling settings per oibject,
    or it requires to change tiling via code. This results in an workaround case again, because unity
    was too lazy to implement the functionality thread OP asked about (which is something they should
    have thought about right from the beginning).

    Expected solution: add function to make Texture scale independent ob underlying game object.

    It's 2022, if anyone knows a solution pls add this here, otherwise i expect unity devs to pick this up.

    Regards.
     
  8. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    I think your best option is to manually edit the UVs of the model.
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,280
    would triplanar shaders be suitable for your case?
     
    arkano22 likes this.
  10. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,847
    Making texture scale independent of object transform scale doesn't make any sense whatsoever in the general case, so Unity devs won't pick this up I'm afraid.

    How would you do this on literally any object other than a cube, where the UV coordinates do not align with the transform's local axis?

    Your best bet is to use a triplanar projection shader for this, as mgear suggested. This will calculate UV coordinates for your object on the fly, protecting a texture from all 3 spatial axis onto your mesh. This way you can perform the projection in world space, ignoring the object's scale.

    Or if you're modeling level geometry directly inside Unity, use an in-engine modeling tool such as ProBuilder. It will automatically calculate UV coordinates for flat surfaces so that texture projection is independent of the world-space size of the object. See: https://docs.unity3d.com/Packages/com.unity.probuilder@4.2/manual/workflow-uvs.html
     
    Last edited: Aug 24, 2022
  11. GamerMcGee

    GamerMcGee

    Joined:
    Nov 18, 2023
    Posts:
    1
    Same Here, But this time I IMPORTED the Materials
     
  12. IllTemperedTunas

    IllTemperedTunas

    Joined:
    Aug 31, 2012
    Posts:
    776
    Triplanar is going to give you odd texturing if the object rotates or if it's not perpendicular to world axes in the scene.

    You COULD create 3 unique shaders/materials and assign them to the parallel planes of the cube top/bottom, left/right, forward/back. Or if you want to get tricky, add a switch system to a singular shader that swaps UV's based on a property input. You could get away with one shader, but you'd still need 3 unique materials. You COULD create unique UVs end get away with 1 shader and one material, but I think that's starting to get a bit wonky and you'd have to start doing odd maskings and complex shader setups.

    Anyway, using 3 shaders you would then adjust the object scale inputs for scale: x/y, z/x, y/z

    Went ahead and threw something bare bones really quick:





    This works for 2 sides of the cube, you'd need to swap the object scaling axes around for the other sets of 2 sides X,Y,Z scales, or as the shader logic goes, (R), (B) and (G). You may also need to play with the UV rotations and flippings of the cube to get optimal results.

    I just had an idea... you could maybe do object normals, and not world normals for masking and be able to really pull off an all in one shader and material, but this is all you're getting out me as I gotta save some energy for my own stuff, good luck!
     
    Last edited: Nov 19, 2023