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 change decal color at runtime? (HDRP)

Discussion in 'Graphics Experimental Previews' started by Necronomicron, Feb 25, 2019.

  1. Necronomicron

    Necronomicron

    Joined:
    Mar 4, 2015
    Posts:
    108
    I tried:
    hole.GetComponent<DecalProjectorComponent>().Mat.SetColor("_BaseColorMap", Random.ColorHSV());

    It does nothing.
     
    Last edited: Feb 26, 2019
  2. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    The "_BaseColorMap" is a texture, so you can't set it to a color value. You should use "_BaseColor".
     
    Necronomicron likes this.
  3. Necronomicron

    Necronomicron

    Joined:
    Mar 4, 2015
    Posts:
    108
    I used
    GetTexturePropertyNames()
    and there was no this name. How could I get other names?

    Also,
    hole.GetComponent<DecalProjectorComponent>().Mat.SetColor("_BaseColor", Random.ColorHSV());
    changes color on all decals, is it possible to change color per instance?
     
  4. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    As you can deduce from the name,
    Code (CSharp):
    1. GetTexturePropertyNames()
    will return you the property names for texture properties only. Not Colors.
    Apparently, there's no way to find the fill list of a material properties by script, but you can either :
    For the second issue, apparently calling
    Code (CSharp):
    1. DecalProjectorComponent.Mat
    will not create a new material instance like it's done on renderers. You'll have to manually create a copy of the material before modifying, and assign it to the projector.

    I'll raise this to the team as it could be expected to behave similarly as renderers.
     
    Necronomicron likes this.
  5. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    197
    Just add per-instance data to decal such : zBias, draw order, color, opacity, theen it'll be most powerfull decal system in the world
     
    Last edited: Mar 3, 2019
    Savoyan and Necronomicron like this.
  6. skilfuldriver

    skilfuldriver

    Joined:
    May 20, 2015
    Posts:
    19
    @Remy_Unity was there any update to this? We are using a decal shader graph for footprints, modifying how they look over time. Instantiating the material allows this but each decal is drawn as a separate mesh and it soon becomes very expensive to render them all. Is there a way to do this and preserve the batch rendering?
     
  7. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    @Remy_Unity any update on this? im using the HDRP Decal system to draw a lot of scifi bullet holes and other things, i want to lower their emission over time before returning them to a pool (like a heat effect), but right now, we cant change Decal materials per instance, it's all or nothing.
     
  8. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    @Mad_Fox : I've submitted a bug report about the material that doesn't get instantiated. I have no ETA on when this could be fixed. In the meantime, you can manually do the instance of the material yourself.

    @skilfuldriver : If you're only fading the decal, instead of using the material, you can use the decal fade factor, and thus, keeping common materials and don't break the batches.
     
  9. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    I want to get the Base Map color of Unity HDRP/Decal shader. Thats the one Unity wrote I need to change the color at runtime.
     
  10. Nstdspace

    Nstdspace

    Joined:
    Feb 6, 2020
    Posts:
    26
    You can check out my video on that topic. I edited the default shader to allow this behaviour. I'm using URP there but it should be the same for HDRP.
     
    MathewHI likes this.
  11. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Hey guys, the issue remains, HDRP Decal Projector will not create a new material instance when tweaking values.

    Any official news about this (almost 4 years later)?
    @Remy_Unity Could at least give us the issue link to vote on it?

    Thanks.
     
  12. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    @Novack It looks like the bug case was wrongly closed : my fault for bad copy/paste a forum post that was not this one, and was talking about decal fade factor :/ . And I didn't mark it public so there is no issue tracker link, sorry.

    I'm starting discussions again internally because I'm not sure we absolutely want this behavior:
    Creating instances of the decal material can have a performance cost, so by making it obvious that you are editing a shared material.
    But currently, if you forget to make an instance and change any property, it will affect the material asset, which is probably worse I guess.

    I will create a new ticket.
     
    Novack likes this.
  13. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Thank you for the update @Remy_Unity. Please keep us posted :)

    I understand the concerning performance implications, though currently is quite bad, because the unnintended effects, but also because is completely inconsistent with how materials work for renderers in general in the engine. So keeping it as it is now, would kinda work against the developer, even if the purpose is to help.

    Some other things to consider are that "sharedMaterial" property is missing and should be added in the case that we get the standard behaviour restored. Also decal.material.color = color receives the change but does nothing: should probably work as a shorthand for decal.material.SetColor("_BaseColor", color).
     
    Last edited: Dec 16, 2022
  14. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    Here is the public issue link : https://issuetracker.unity3d.com/is...instantiating-its-own-material-during-runtime

    I think this is a pre-requisite to fix the issue yes.

    From what I see in the code and the api doc, it should work like this already, this might be a new valid issue to report, I'll investigate.
     
    Novack likes this.