Search Unity

How to apply texture imported at runtime for the skybox panoramic shader?

Discussion in 'General Graphics' started by tomekkie2, Nov 20, 2018.

  1. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    longitudinal.png
    My problem is the single longitudinal line appearing on the skybox.
    The way to fix this in Unity Editor is to disable Generate Mip Maps option in the texture import setting.

    But how to fix it on the texture imported at runtime?

    I have tried to set
    Texture2D.requestedMipmapLevel = 0;
    , but that did not work for me.
     
  2. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    I have managed to fix this.
    I am importing this texture using www class, as www. texture.
    Then I create a new texture with no mipmaps and copy pixels to it.
    Code (CSharp):
    1.         Texture2D skyTexture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.RGB24, false);
    2.  
    3.         Color[] cols = www.texture.GetPixels(0, 0, www.texture.width, www.texture.height);
    4.         skyTexture.SetPixels(cols);
    5.  
    6.         skyTexture.Apply();
     
  3. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    In Unity 2019.1, this also works (I'm loading the texture from a local file, so I'm not doing anything with WWW):

    Code (CSharp):
    1. Texture2D texture = new Texture2D(2, 2, TextureFormat.RGB24, false);
    2.  
    3. try {
    4.     if (File.Exists(path)) {
    5.         byte[] fileData = File.ReadAllBytes(path);
    6.         texture.LoadImage(fileData);
    7.     } else {
    8.         Debug.LogError($"There is no file at: '{path}'");
    9.     }
    10. } catch (Exception exc) {
    11.     Debug.LogException(exc);
    12. }
    13.  
    See also: https://answers.unity.com/questions...-that.html?childToView=1664162#answer-1664162
     
    Last edited: Sep 9, 2019