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.

Feature Request HDRP Decal Projector Material Property Block

Discussion in 'High Definition Render Pipeline' started by gregcodercw, Nov 9, 2021.

  1. gregcodercw

    gregcodercw

    Joined:
    Dec 5, 2017
    Posts:
    15
    Hello,

    I request that the Material Property Block in the DecalSystem.DecalSet can get provided via HDRP Decal Projector.

    Current Problem:
    Can't have variations of a decal based on the same material. Every time a slightly different decal variation is need the material needs to be cloned.

    Solution:
    Giving DecalProjector a MaterialPropertyBlock property and have it replace the default MaterialPropertyBlock in DecalSystem.DecalSet when not null.

    I'm sure this is not a new request. Is there context as to why this hasn't been implemented already?
     
  2. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    602
    Hey, yes, it's a known pain for decal projector materials and sadly the current method to deal with that issue is the one mentioned in the documentation (i.e cloning the material).

    I'll ask around to see if a better solution (along what you suggested) is on the roadmap.
     
    Ruchir likes this.
  3. StickyTommie

    StickyTommie

    Joined:
    Oct 23, 2019
    Posts:
    13
  4. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    602
    Indeed, I got confirmation that it's tracked on our side.
    it's just not a big priority for now.
     
  5. THECAKEISALIE93

    THECAKEISALIE93

    Joined:
    Sep 16, 2013
    Posts:
    29
    I apologize for resurrecting this thread. How would you go about accessing this cloned material? Where would it be stored and how could you utilize it?

    **EDIT**
    I did figure out how it can be utilized. Although does this temporary material clone get stored anywhere or does it get removed/deleted once the gameobject is removed from the scene?


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Rendering.HighDefinition;
    public class Bullethole_Glow : MonoBehaviour
    {
    public DecalProjector _DecalProjectorComponent;
    public bool isGlowing;
    public float glowTime;
    public float minGlowTime;
    public float maxGlowTime;
    public float _GlowIntensity;
    public float Duration = 1;
    // Start is called before the first frame update
    void Start()
    {
    _DecalProjectorComponent = gameObject.GetComponent<DecalProjector>();
    //Create new material instance for the decal projector
    _DecalProjectorComponent.material = new Material(_DecalProjectorComponent.material);
    }
    // Update is called once per frame
    void Update()
    {
    GlowEffectFade();
    }
    private void GlowEffectFade()
    {
    glowTime = Mathf.Clamp(minGlowTime, 0, maxGlowTime);
    _DecalProjectorComponent.material.SetFloat("_GlowIntensity", _GlowIntensity);
    if (glowTime < _GlowIntensity)
    {
    isGlowing = true;
    glowTime += Time.deltaTime / Duration;
    if (isGlowing!)
    {
    if (_GlowIntensity > 0)
    {
    _GlowIntensity -= glowTime;
    }
    }
    }
    else
    {
    isGlowing = false;
    _GlowIntensity = 0;
    }
    }
    }
     
    Last edited: Aug 2, 2022
  6. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    574
    @THECAKEISALIE93

    The clone material is created at runtime and stored on ram.
    If you delete the decal and an remove all pointers to this materials from your scripts, it should be automatically deleted by the garbage collector.
    Else, you can delete it manually using the
    Destroy( object );
    method.
     
    chap-unity likes this.
  7. THECAKEISALIE93

    THECAKEISALIE93

    Joined:
    Sep 16, 2013
    Posts:
    29
    @Remy_Unity

    So the Destroy method will in fact be the quickest, surefire method in your opinion? My decals all get deleted via the Destroy method after an amount of time, that is also adjustable.
     
  8. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    574
    Using Destroy on the decal object might not delete the material immediately and leave it to the garbage collector, to be sure you can Destroy the material clone first, than the decal.