Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How to access Lit shader properties through code ?

Discussion in 'Graphics Experimental Previews' started by BlackRock404, Feb 6, 2019.

  1. BlackRock404

    BlackRock404

    Joined:
    Jan 29, 2018
    Posts:
    2
    Currently i'm using HDRP in my project, so i have a question. How can i access Lit shader properties through code ? Or where i can see names of variables in this shader ?

    I tried to walk through Lit shader code and checkout properties names, but i didn't find any useful for my problem.

    I need to access for example Base Map property in Surface Inputs through code (and other properties too).
     
  2. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    HDRP is still under heavy development and all the code is still in flux. Even if you find some code that works right now chances are it will stop working very soon. That's why there aren't really any tutorials/etc for HDRP code yet. Really, the safest shader method right now is to use Shader Graph.

    But... you can find the source code for all the SRP/Shader Graph stuff here. The particular variable you highlight in your screenshot is called _BaseColorMap for the texture part and _BaseColor for the color part. Where those variables are used depends on the rendering path you have selected and which features you have enabled in the shader.

    Once the code stabilizes it will be easier to point to specific bits of code to show what does what. I'm looking forward to that myself. :)
     
  3. Chaiker

    Chaiker

    Joined:
    Apr 14, 2014
    Posts:
    63
    Enable debug in inspector and you can see textures names.
     
    laurienash and anomal3 like this.
  4. anomal3

    anomal3

    Joined:
    Mar 11, 2017
    Posts:
    14
    Maybe someone will come in handy for HDPR 7.3.1

    Code (CSharp):
    1.  
    2. List<string> NameMat = new List<string>();
    3. var meshRenderer = GetComponent<MeshRenderer>();
    4.  
    5. if(meshRenderer.materials.Length > 1)
    6.         {
    7.             foreach (var n in meshRenderer.materials)
    8.             {
    9.                 NameMat.Add(n.GetTexture("_BaseColorMap").name);
    10.             }
    11.         }
    12.