Skip to content

Commit b833d56

Browse files
YohannVaastUnityEvergreen
authored andcommitted
SpeedTree 9 - Add dependency on extracted materials & Fix remapping of materials
Big conversation here: https://unity.slack.com/archives/C05C7C93RL4/p1701979272164239 Big description here: https://jira.unity3d.com/browse/UUM-57578?filter=-1 `ISSUE 1` This is a fix for SpeedTree9 assets only. That's the best solution I found, considering the limitation of the Preview system. Basically, with this PR, we now have a dependency on the extracted materials (so outside the Prefab). With it, if the user deletes an extracted Material (non-reversible operation), it re-triggers the preview generation (thanks to the function `GenerateAssetData` in `PreviewImporter.cpp`). Also, instead of having a pink Mesh in the scene (since there's no more material attached to the Mesh), the importer is regenerating the materials as embedded automatically, so the user doesn't have to `Reset` the asset or manually press `Apply & Generate Materials). Pretty convenient. `ISSUE 2` Also, there was issues with the remapping options. Basically, the entry materials were duplicated and sometimes the remapping wasn't working (material was set to null after hitting `apply`). Adding the variable `defaultName` avoid those issues, by always keeping the initial material name (e.g `RulesExampleMat`) on the left of the entry, and having the real material name and instance (e.g MyMatyellow) in the object field. Here's the final results in action (sorry for the poor gif quality, had to compress a lot the gif): ![FixRemapping_Compress](https://media.github.cds.internal.unity3d.com/user/1911/files/18807273-5e18-4434-a77c-901c18150e34) `ISSUE 3` When textures were moved somewhere else in the project (i.e not next to the assets), it was breaking the material references to them. Now it's not the case anymore, we are checking for them if they are not next to the asset. ![MoveTexturesST9](https://media.github.cds.internal.unity3d.com/user/1911/files/620a6c39-8ea5-4a03-a2b5-7493da2228a1)
1 parent 8104c04 commit b833d56

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Packages/com.unity.render-pipelines.high-definition/Editor/Material/Nature/HDSpeedTree9MaterialUpgrader.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private static class HDProperties
1818
internal static readonly int CullModeID = Shader.PropertyToID("_CullMode");
1919
internal static readonly int CullModeForwardID = Shader.PropertyToID("_CullModeForward");
2020
internal static readonly int DiffusionProfileAssetID = Shader.PropertyToID("_Diffusion_Profile_Asset");
21-
internal static readonly int DiffusionProfileID = Shader.PropertyToID("_DiffusionProfile");
21+
internal static readonly int DiffusionProfileID = Shader.PropertyToID("_Diffusion_Profile");
2222

2323
internal static readonly string WindShared = "_WIND_SHARED";
2424
internal static readonly string WindBranch2 = "_WIND_BRANCH2";
@@ -78,11 +78,14 @@ private static void SetupHDPropertiesOnImport(Material mat)
7878

7979
private static void SetDefaultDiffusionProfileIfNecessary(Material mat)
8080
{
81-
if (!mat.HasVector(HDProperties.DiffusionProfileAssetID) || !mat.HasFloat(HDProperties.DiffusionProfileID))
81+
bool hasDiffusionProfile = mat.HasVector(HDProperties.DiffusionProfileAssetID);
82+
bool hasDiffusionProfileID = mat.HasFloat(HDProperties.DiffusionProfileID);
83+
84+
if (!hasDiffusionProfile || !hasDiffusionProfileID)
8285
return;
8386

84-
var profAsset = mat.GetVector(HDProperties.DiffusionProfileAssetID);
85-
var profHash = mat.GetFloat(HDProperties.DiffusionProfileID);
87+
Vector4 profAsset = mat.GetVector(HDProperties.DiffusionProfileAssetID);
88+
float profHash = mat.GetFloat(HDProperties.DiffusionProfileID);
8689

8790
// User already set values from the inspector.
8891
if (profAsset != null && profAsset != Vector4.zero && profHash != 0)

0 commit comments

Comments
 (0)