Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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:
    106
    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:
    342
    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:
    106
    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:
    342
    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:
    195
    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
    Necronomicron likes 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:
    342
    @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.
     
unityunity