Search Unity

Main texture not shown up, lwrp (Solved)

Discussion in 'Shaders' started by Valfdor, Apr 17, 2019.

  1. Valfdor

    Valfdor

    Joined:
    Apr 4, 2018
    Posts:
    3
    Good day!

    Using lwrp for about 6 month. Yesterday went from 2018.3.12f1 to 2019.1.0f2, an now have an issue in changing textures on the fly, with script.

    Simple thing. It was)
    Code (CSharp):
    1. rend = GetComponent<MeshRenderer>();
    2. rend.material.maintexture = newTexture;
    This lines of code actually changes the texture (checked with names on maintexture) - but it is not displayed, i can see an old texture all the time.

    If changed through inspector - texture changes. But it seems, that displayed texture and material.maintexture have nothing in common. Because even if we set maintexture (through script) to null - nothing changes.

    If we get to standart hdrp - all is fine.

    Tried getting some info through .material.shaderKeywords - no luck. Only _normalmap and _occlusionmap.

    Feel, like it's something simple, but couldn't find the answer.

    Can anyone give me a hand?
     
  2. Blueknight1758

    Blueknight1758

    Joined:
    Jul 27, 2013
    Posts:
    12
    Unfortunately cannot give you a hand, but am also experiencing this issue
     
  3. Valfdor

    Valfdor

    Joined:
    Apr 4, 2018
    Posts:
    3
    Lets wait together, then. Welcome aboard!)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,160
    https://docs.unity3d.com/ScriptReference/Material-mainTexture.html
    If the shader you're using doesn't use a texture named _MainTex as it's main texture, it won't work. Also, .maintexture appears to considered deprecated by Unity, though I think they keep forgetting to actually make it deprecated so people know to stop using it. It's also entirely possible they outright broke it in 2019 as, like I mentioned, they treat it as if it's deprecated.
     
    Covfefeh likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,160
    This has nothing to do with material properties like textures, colors, etc. Keywords are used to pick different shader variants. Many of Unity's shaders happen to have a keyword to enable or disable the use of normal maps which just happens to use a keyword that looks like it should be the material property name (it's often not!). Also note that the name that appears in the inspector is just a display name and has nothing to do with the internal property name. The easiest way to know what the actual property name is would be to look at the .shader file itself. Alternatively you can use the debug inspector (right click on the inspector tab, select debug) and you can see a list of all the set properties with their actual property names.

    Here's the LWRP's Lit shader:
    https://github.com/Unity-Technologi...nder-pipelines.lightweight/Shaders/Lit.shader
    Note the main texture property is called "_BaseMap", and the normal map is called "_BumpMap", not "_NORMALMAP" like the keyword.
     
    Last edited: Apr 17, 2019
  6. Valfdor

    Valfdor

    Joined:
    Apr 4, 2018
    Posts:
    3
    Thank you for your help, Bgolus! And for expanded explanation as well, didn't know more, than half of that.

    Code (CSharp):
    1. rend.material.SetTexture("_BaseMap", tex);
    - it worked!)
     
    djquedenfeld, tetraxel and blu3wings like this.