Search Unity

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

Question SetTextureOffset of a normal map texture

Discussion in 'General Graphics' started by robertolodongo, Nov 30, 2023.

  1. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    How do it set the offset of a normal map texture in the material, it seems that i can only do it with the _MainTex and that affects all the textures in the material.

    material.SetTextureOffset("_MainTex", new Vector2(.5, .5));

    But if i replace "_MainTex" with "_BumpMap" still moves all textures instead of just the normal one.

    Is there a way to do this? That is, setting the textures offsets of the normal map and the main texture independently of each other from code?
     
    Last edited: Nov 30, 2023
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,956
    Hi!
    Please report a bug, we'll take a look.
    Thanks!
     
  3. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    Just in case i didn't express what i want correctly.

    here is the code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class NewBehaviourScript : MonoBehaviour
    {

    // Start is called before the first frame update
    void Start()


    {
    Material material = gameObject.GetComponent<MeshRenderer>().material;

    material.SetTextureOffset("_BumpMap", new Vector2(.5f, .5f));
    }


    }
    This doesn't do anything, but when i change "_BumpMap" for "_MainTex" it moves every texture which i think is correct(?)

    But what i want is to move only the normal map texture, and the others to be in place while the normal map moves, and/or move the different textures of the material with different offsets, is this possible? or u can only move all the textures by the same offset?
    Thanks
     
  4. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    759
    So it seems you can't set the normal map offset separately from the main texture but you could set your normal map to be the detail normal map and then set the offset of that.
    Code (CSharp):
    1.       material.SetTextureOffset("_DetailAlbedoMap", new Vector2(.5f, .5f));
     
    warthos3399 likes this.
  5. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    That works thank you!