Accessing the Diffusion Profile thorugh code to Create a Custom ShaderGUI

Hello. Is it possible to create a custom ShaderGUI and, in doing so, redraw the Diffusion Profile slot? Despite my efforts, I’ve been unable to find an answer. I came across a thread that might have touched on a similar question, but it’s outdated now:

Is achieving this actually feasible?

Thank you.

Graphics/Packages/com.unity.render-pipelines.high-definition/Editor/Material/DiffusionProfile/DiffusionProfileMaterialUI.cs at 7edae7be016c2ee753cfaf3821b7b68c96dc3038 · Unity-Technologies/Graphics (github.com)
This is how unity write it. You can just copy paste it to your own code.

1 Like

Hello and thank you. Your tip provided me with the push I needed in the right direction. I am just starting to dive into Graph Shader, so sometimes I really get lost…

So, I will explain the final solution in case somebody else needs it:

First, yes, as a newbie in creating Custom Shader GUIs, I didn’t think to check the HDRP package itself for clues to most of the things I need. Now, it makes total sense.

Secondly, I managed to draw the slot like this:

using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering.HighDefinition;
using System.Linq;

public class CustomShaderGUI : ShaderGUI
{
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        // Find diffusion profile properties by name
        MaterialProperty diffusionProfileAsset = FindProperty("_DiffusionProfileAsset", properties);
        MaterialProperty diffusionProfileHash = FindProperty("_DiffusionProfileHash", properties);

        // Make DiffusionProfileMaterialUI accessible
        DiffusionProfileMaterialUI.OnGUI(materialEditor, diffusionProfileAsset, diffusionProfileHash, 0);
    }
}

So, in the end, it is as easy as borrowing Unity’s class. However, as my second note states, we need to make said class accessible. So, I had to dive into the HDRP package of my project, find the DiffusionProfileMaterialUI.cs, and make the static class public:

public static class DiffusionProfileMaterialUI

In the end, it worked like a charm!