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

Is it possible to override the built-in 'unity_Lightmap' and 'unity_LightmapST'

Discussion in 'Global Illumination' started by Zhang209, Sep 22, 2017.

  1. Zhang209

    Zhang209

    Joined:
    Sep 13, 2017
    Posts:
    1
    I found that the standard shader is using unity_LightmapST and unity_Lightmap to present baked lightmap info.
    Unlike the normal shader properties(eg:_MainTex) which can be set from script, the above 2 variable is passed by Engine and the script will take no effect to modify them.
    My purpose is to store the lightmap and texture offset per renderer to overide them in standard shader. In that case, I dont need to rely on lighting data asset(it's quite fragile to maintain them) especially working with lightmap in prefab.
    Or I have to create my own shader to do that.
    Can anyone advise?

    Many thanks.
     
  2. Xefier

    Xefier

    Joined:
    Dec 22, 2012
    Posts:
    80
    I'm also wondering about this, looking into it now.
    So far it looks like there is no property that can be set with "unity_Lightmap" in materials. (Via SetProperty).
    Even exposing it as a property in a modified version of standard shader code doesn't seem to work.
     
    Last edited: Feb 1, 2020
  3. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    99
    I don't think you can overwrite them but here's another idea. I have not verified that the following works, but you could try this:
    Let us know how this experiment goes :)
     
  4. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    416
    Shader properties starting with "unity_" can't be overridden. That said, there is no need for that in this case, as you can directly affect the data that is fed into those properties by using the API points that Rasmus mentioned above.

    Please note that none of those properties are serialized in the Editor. They are only serialized when building the player. So in the Editor you'll need to make sure to set them anew every time your scene is loaded.