Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Materials seem to remember values assigned under another shader, breaking them

Discussion in 'High Definition Render Pipeline' started by dgoyette, Oct 18, 2019.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    Sorry for the vague title, but I'm not sure the best way to describe this.

    I have a material that was using a ShaderGraph shader I made. I then decided I'd switch it over to use the built-in HDRP Lit shader. Upon switching to it, the material doesn't render. When assigned to a plain old cube, the cube doesn't render. No fucsia box, just nothing at all.

    I created a new material and assigned all the same values as I did to the invisible material, and it renders fine. In the inspector, these two materials are identical: all fields have the same values. However, if I look at the text contents of the two materials, they're dramatically different:

    upload_2019-10-18_16-0-44.png

    The "invisible" shader is on the right. It has a lot more stuff, most of which are properties of my old shader.

    Anyway, it's not critical that I "fix" this material. Mostly I'd just like to understand what's going on. It seems that the extra "stuff" in the "invisible" shader is causing the built-in HDRP Lit shader not to render correctly. Does anyone know what would cause this? I attached the two materials in case anyone's curious.

    Can extra "junk" in the material, which isn't used by that shader, cause it to rendering differently? Is there a way to reset a shader to throw away this "junk"?
     

    Attached Files:

  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You can set your inspector to debug mode then you can see all the currently saved property for that material.
    Normally any unused property's should not impact your new shader.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    Good point. I'll try that. As for the ideal goal of unused properties having no impact on the shader, my guess is that the HDRP Lit shader is complicated enough that something just behaves weirdly if a particular property has a value when the developers weren't expecting it would have one. And since inspector logic is independent from how the shader functions, there are probably some weird cases where the shader does something that the inspector isn't representing or expecting.