Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Can't seem to make tiling change through script with HDRP Shaders

Discussion in 'High Definition Render Pipeline' started by Obleynix, Nov 3, 2019.

  1. Obleynix

    Obleynix

    Joined:
    Dec 15, 2016
    Posts:
    3
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. // Tile each material according to the object's scale.
    5. // Author: Lucas A. Mello
    6.  
    7. [ExecuteInEditMode]
    8. public class TileTexture : MonoBehaviour
    9. {
    10.     void Update()
    11.     {
    12.         // Get scales
    13.         float x = transform.localScale.x;
    14.         float y = transform.localScale.y;
    15.         float z = transform.localScale.z;
    16.         float max = x > y ? x : y;
    17.         max = max > z ? max : z;
    18.        
    19.         // Get the mesh
    20.         Mesh theMesh;
    21.         theMesh = this.transform.GetComponent<MeshFilter>().sharedMesh as Mesh;
    22.    
    23.         // Now store a local reference for the UVs
    24.         Vector2[] theUVs = new Vector2[theMesh.uv.Length];
    25.         theUVs = theMesh.uv;
    26.        
    27.         // Vertices order:
    28.         //    2    3    0    1   z+
    29.         //    6    7   10   11   z-
    30.         //   19   17   16   18   x-
    31.         //   23   21   20   22   x+
    32.         //    4    5    8    9   Top
    33.         //   15   13   12   14   Bottom
    34.    
    35.         // set UV co-ordinates
    36.         theUVs[2] = new Vector2(0f, y/max);
    37.         theUVs[3] = new Vector2(x/max, y/max);
    38.         theUVs[0] = new Vector2(0f, 0f);
    39.         theUVs[1] = new Vector2(x/max, 0f);
    40.        
    41.         theUVs[11] = new Vector2(0f, y/max);
    42.         theUVs[10] = new Vector2(x/max, y/max);
    43.         theUVs[7] = new Vector2(0f, 0f);
    44.         theUVs[6] = new Vector2(x/max, 0f);
    45.        
    46.         theUVs[19] = new Vector2(0f, y/max);
    47.         theUVs[17] = new Vector2(z/max, y/max);
    48.         theUVs[16] = new Vector2(0f, 0f);
    49.         theUVs[18] = new Vector2(z/max, 0f);
    50.        
    51.         theUVs[23] = new Vector2(0f, y/max);
    52.         theUVs[21] = new Vector2(z/max, y/max);
    53.         theUVs[20] = new Vector2(0f, 0f);
    54.         theUVs[22] = new Vector2(z/max, 0f);
    55.        
    56.         theUVs[4] = new Vector2(0f, z/max);
    57.         theUVs[5] = new Vector2(x/max, z/max);
    58.         theUVs[8] = new Vector2(0f, 0f);
    59.         theUVs[9] = new Vector2(x/max, 0f);
    60.        
    61.         theUVs[15] = new Vector2(0f, 0f);
    62.         theUVs[13] = new Vector2(0f, 0f);
    63.         theUVs[12] = new Vector2(0f, 0f);
    64.         theUVs[14] = new Vector2(0f, 0f);      
    65.    
    66.         // Assign the mesh its new UVs
    67.         theMesh.uv = theUVs;
    68.        
    69.         GetComponent<Renderer>().sharedMaterial.SetTextureScale("_MainTex", new Vector2(max/2f, max/2f));
    70.     }
    71.    
    72. }
    73.  
    Script above not mine, just changed a little.

    I'm trying to get a auto-tiling like thing to work in my scene, but it does seems to not change the values of tiling when used in hdrp, altought it works in the standard unity. I've searched everywhere but there is no thread talking about it, i've tried lots of things and can't seem to make it work
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,
    Welcome to the club, you probably have to do the same as everyone else at the moment and go check the HDRP source code that is available in the package folder. Many things have changed and old names will not work.

    Try this:
    Code (Pseudocode):
    1. material.SetTextureScale("_BaseColorMap", tiling);
    And you should get access to the tiling, at least if you use the HDRP/Lit material.
     
    Nidhii and Obleynix like this.
  3. SeveQStorm

    SeveQStorm

    Joined:
    May 7, 2013
    Posts:
    7
    @Olmi I've tried that, but it messes up my UV mapping for some reason that I haven't figured out yet.
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @SeveQStorm probably another issue with your model, but that setting does change texture tiling in a material. Got any images to show?
     
  5. AdamSt

    AdamSt

    Joined:
    Jun 2, 2013
    Posts:
    18
    Maybe You meant offset?

    material.SetTextureOffset("_BaseColorMap", material.GetTextureOffset("_BaseColorMap") + new Vector2(offsetXEveryFrame, offsetYEveryFrame));