#To reply to this myself - you have to jump through some hoops!
1 messages ยท Page 1 of 1 (latest)
The takeaway is you can read existing '_DiffusionProfileHash' and '_DiffusionProfileAsset' variables but you have to do a binary cast to and from an int to ensure vital bits aren't lost in truncation.
I think we never tried ourselves to change the diffusion profile at runtime on a material.
I would just recommand to swap the material to an other one :/
Not an option for what I'm doing, it's middleware tools creating materials and running in editor. But hey, it works ๐
Hum, if it's in editor, it might be easier then, let me dig a bit in the code ....
So, have a look at this class : https://github.com/Unity-Technologies/Graphics/blob/c4c73735aa165617a850b5ddd15f13c01352da56/com.unity.render-pipelines.high-definition/Editor/Material/DiffusionProfile/DiffusionProfileMaterialUI.cs
It uses these functions to convert the asset guid to a vector4 : https//https://github.com/Unity-Technologies/Graphics/blob/c4c73735aa165617a850b5ddd15f13c01352da56/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs#L915
And the hash as a float https://github.com/Unity-Technologies/Graphics/blob/c4c73735aa165617a850b5ddd15f13c01352da56/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowUtils.cs#L11
(I didn't look into how the hash is generated, but it shouldn't be needed if you're just loading the asset)
The functions are internal, but you should be able to write public accessors to them using assembly reference
Thanks, that's a great help - I'd already done a lot of similar stuff on the GUID front but that's going to be a lot more reliable ๐
Hey, IDK on what version of HDRP you are working on, but if the verty latest HDRP 14 (unity 2022.2) there is a public easy api to set diffusion profiles on materials : https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@14.0/api/UnityEngine.Rendering.HighDefinition.HDMaterial.html#UnityEngine_Rendering_HighDefinition_HDMaterial_SetDiffusionProfile_UnityEngine_Material_UnityEngine_Rendering_HighDefinition_DiffusionProfileSettings_