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

I have a question,How to work about Tiling and offset in texture?

Discussion in 'Universal Render Pipeline' started by Yostar-Gligame, May 6, 2020.

  1. Yostar-Gligame

    Yostar-Gligame

    Joined:
    Jul 15, 2019
    Posts:
    8
    in my custom shader, about texture2D of the tiling and the offset haven't efficiency.
    this is my code:
    Code (CSharp):
    1.  texture2D SPColorTex;
    2. SamplerState sampler_Trilinear_ClampSPColorTex;
    3. SAMPLE_TEXTURE2D(SPColorTex, sampler_Trilinear_ClampSPColorTex, input.uv).xyz
    I wanna dispose of the problem.
    Thanks all!
     
  2. peterbay

    peterbay

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    100
    You can use the TRANSFORM_TEX macro to transform the coordinates according to the texture's tiling and offset. In your case, it would look like this:
    Code (CSharp):
    1. SAMPLE_TEXTURE2D(SPColorTex, sampler_Trilinear_ClampSPColorTex, TRANSFORM_TEX(input.uv, SPColorTex)).xyz
     
  3. Yostar-Gligame

    Yostar-Gligame

    Joined:
    Jul 15, 2019
    Posts:
    8
    it works. Thank you!
     
    peterbay likes this.