Skip to content

Commit b59e354

Browse files
alelievrFrancescoC-unityanisunitysebastienlagardeIonutNedelcuUnity
authored
Expose diffusion profile in ShaderGraph (#1869)
* Factorised the blackboard properties code * Started to add diffusion profile material property drawer * Experimenting with material property drawers * Cleanup code and use SRP asset types instead of render pipeline types * Cleanup * Skip biquadratic reconstruction when doing filtering * changelog * Cleanup * Use int instead of float (was doing experiment with multiple options) * Added diffusion profile shader property drawer * Mis missing docs * Moving function to internal and adding doc for missing param in planar reflection function * Cleanup code * Halving the perf impact of film grain and sRGB dithering in Final pass (#1782) * Optimize ALU of grain and dithering * changelog * Fix when res is smaller than grain texture Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * New DXR HDRP test for testing SNorm16 vertex format support in ray tracing shaders (#1651) * Added new DXR test (6000_VertexFormats) for testing a few vertex attribute formats. * Deleted unused material * Perform the first mip of the depth pyramid alongside the downsample of depth buffer for low res transparents (#1800) * Skip redundant mip0 of depth pyramid * changelog * Fix register on ps * Reuse minDepth * Make sure in rendergraph the copy of the depth buffer happens. * Wrong naming Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fix for text of shadow splits being truncated at the bottom (#1822) * Add some more margin * Changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fix property field drawing in custom pass volume (#1824) Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Force probe to render again if first time was during async shader compilation (#1847) Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Refresh environment library field in Lookdev (#1849) * Refresh the library field too * Add the refresh on Repaint * Changelog * Guard for null * Revert "Add the refresh on Repaint" This reverts commit 072c8e5. Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fix matcap preferences serialization issue (#2013) * Fix serialization issue * Changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Added a way to check the normals through the material views. (#1895) * Added a way to check the normals through the material views. * Adding the information in the documentation Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * [10.x.x] AxF UI improvements (#1902) * AxF UI - Remove possibility to select main BRDF as BTF since it is unsupported (could be handy to show it if it was imported as such, but for now we safely ignore since importer doesn't produce a material with that mode selected) Also prevent compilation error even if selected. * AxF UI - Add a bit of tooltips (even if for some fields engine editor bug doesn't show them), group advanced surface inputs into their own foldable UI block, make clearer the tiling/offset vector meaning. * AxF UI - Remove UI parts that were moved into the main mapping section. * AxF - Update the documentation to reflect UI changes. * AxF new UI - Add missing file * Close popup window when focus is lost (case 1258571) (#1907) Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Default contact shadow LIGHT quality setting set to true on High (#1911) * Have contact shadow on high quality. * changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fix double addition to sorted list (#1916) * Added the possibility to replace or overwrite already existing local package when installing a new one. (#1921) * When trying to install the local configuration package, if another one is already present the user is now asked whether they want to keep it or not. * Update changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fixed an exception thrown when closing the lookdev because there is no active SRP anymore. (#1925) * Fixed an exception thrown when closing the lookdev because there is no active SRP anymore. * Update changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fixed UI alignment of framesettings (#1929) Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fixed an issue where entering playmode would close the LookDev window. (#1937) * Fixed an exception thrown when closing the lookdev because there is no active SRP anymore. * Update changelog * Fixed an issue where entering playmode would close the LookDev window. * Update changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Added Simple mode to Earth Preset for PBR Sky (#1866) * Added Simple Earth Mode to PBR Sky * Update doc * update doc Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fix hair shader compilation issue with Debug Display mode (#2023) * Fix compilation issue with debug mode and hair * Update CHANGELOG.md * Improve MSAA color resolve when very different samples are merged together (#1839) * Improve MSAA color resolve. * Changelog * Revert unwanted changes This reverts commit a55a905. * Update refs * Linux refs * update linux and mac reference screenshots Co-authored-by: Sebastien Lagarde <sebastien@unity3d.com> * Revert "Fix hair shader compilation issue with Debug Display mode (#2023)" This reverts commit 16989c6. * Screen Space Ambient Occlusion for Shadow Matte (#1901) * Added the export of normals during the prepass for shadow matte for proper SSAO calculation. * change log * update reference screenshots Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fixed Cutoff not working properly with ray tracing shaders default and SG (case 1261292). (#1923) * Fixed Cutoff not working properly with ray tracing shaders default and SG (case 1261292). * Update LitData.hlsl * Update AxFData.hlsl Co-authored-by: sebastienlagarde <sebastien@unity3d.com> * Fix hair shader compilation issue with Debug Display mode (#2034) * Fix compilation issue with debug mode and hair * Update CHANGELOG.md * Update Deferred.compute * Update LightLoop.hlsl * add missing meta * Added BlackboardInputInfo attribute to order and rename shader inputs * changed int priority to float * Don't show shader input that don't have the BlackboardInputInfo attribute Co-authored-by: FrancescoC-Unity <francescoc@unity3d.com> Co-authored-by: Anis <anis@unity3d.com> Co-authored-by: sebastienlagarde <sebastien@unity3d.com> Co-authored-by: FrancescoC-unity <43168857+FrancescoC-unity@users.noreply.github.com> Co-authored-by: IonutNedelcuUnity <43206223+IonutNedelcuUnity@users.noreply.github.com> Co-authored-by: Adrien de Tocqueville <adrien.tocqueville@unity3d.com> Co-authored-by: anisunity <42026998+anisunity@users.noreply.github.com> Co-authored-by: slunity <37302815+slunity@users.noreply.github.com> Co-authored-by: fredericv-unity3d <55485372+fredericv-unity3d@users.noreply.github.com> Co-authored-by: JulienIgnace-Unity <julien@unity3d.com>
1 parent c43a568 commit b59e354

30 files changed

+310
-19
lines changed

com.unity.render-pipelines.high-definition/Editor/Material/DiffusionProfile/DiffusionProfileMaterialUI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public static bool IsSupported(MaterialEditor materialEditor)
1818
});
1919
}
2020

21-
public static void OnGUI(MaterialEditor materialEditor, MaterialProperty diffusionProfileAsset, MaterialProperty diffusionProfileHash, int profileIndex)
21+
public static void OnGUI(MaterialEditor materialEditor, MaterialProperty diffusionProfileAsset, MaterialProperty diffusionProfileHash, int profileIndex, string displayName = "Diffusion Profile")
2222
{
2323
// We can't cache these fields because of several edge cases like undo/redo or pressing escape in the object picker
2424
string guid = HDUtils.ConvertVector4ToGUID(diffusionProfileAsset.vectorValue);
2525
DiffusionProfileSettings diffusionProfile = AssetDatabase.LoadAssetAtPath<DiffusionProfileSettings>(AssetDatabase.GUIDToAssetPath(guid));
2626

2727
// is it okay to do this every frame ?
2828
EditorGUI.BeginChangeCheck();
29-
diffusionProfile = (DiffusionProfileSettings)EditorGUILayout.ObjectField("Diffusion Profile", diffusionProfile, typeof(DiffusionProfileSettings), false);
29+
diffusionProfile = (DiffusionProfileSettings)EditorGUILayout.ObjectField(displayName, diffusionProfile, typeof(DiffusionProfileSettings), false);
3030
if (EditorGUI.EndChangeCheck())
3131
{
3232
Vector4 newGuid = Vector4.zero;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System;
4+
5+
namespace UnityEditor.Rendering.HighDefinition
6+
{
7+
public class DiffusionProfileDrawer : MaterialPropertyDrawer
8+
{
9+
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) => 0;
10+
11+
public override void OnGUI (Rect position, MaterialProperty prop, String label, MaterialEditor editor)
12+
{
13+
// Find properties
14+
var assetProperty = MaterialEditor.GetMaterialProperty(editor.targets, prop.name + "_Asset");
15+
DiffusionProfileMaterialUI.OnGUI(editor, assetProperty, prop, 0, prop.displayName);
16+
}
17+
}
18+
}

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DiffusionProfileMaterialPropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Reflection;
3+
using UnityEditor.ShaderGraph.Drawing;
4+
using UnityEditor.UIElements;
5+
using UnityEngine;
6+
using UnityEngine.UIElements;
7+
using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers;
8+
using UnityEngine.Rendering.HighDefinition;
9+
using UnityEditor.ShaderGraph.Drawing.Inspector;
10+
11+
namespace UnityEditor.Rendering.HighDefinition
12+
{
13+
[SGPropertyDrawer(typeof(DiffusionProfileSettings))]
14+
class DiffusionProfilePropertyDrawer : IPropertyDrawer
15+
{
16+
internal delegate void ValueChangedCallback(DiffusionProfileSettings newValue);
17+
18+
internal VisualElement CreateGUI(
19+
ValueChangedCallback valueChangedCallback,
20+
DiffusionProfileSettings fieldToDraw,
21+
string labelName,
22+
out VisualElement propertyColorField,
23+
int indentLevel = 0)
24+
{
25+
var objectField = new ObjectField { value = fieldToDraw, objectType = typeof(DiffusionProfileSettings)};
26+
27+
if (valueChangedCallback != null)
28+
{
29+
objectField.RegisterValueChangedCallback(evt => { valueChangedCallback((DiffusionProfileSettings) evt.newValue); });
30+
}
31+
32+
propertyColorField = objectField;
33+
34+
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
35+
defaultRow.Add(propertyColorField);
36+
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
37+
return defaultRow;
38+
}
39+
40+
public Action inspectorUpdateDelegate { get; set; }
41+
42+
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
43+
{
44+
return this.CreateGUI(
45+
// Use the setter from the provided property as the callback
46+
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] {newValue}),
47+
(DiffusionProfileSettings) propertyInfo.GetValue(actualObject),
48+
attribute.labelName,
49+
out var propertyVisualElement);
50+
}
51+
}
52+
}

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DiffusionProfilePropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEditor.Graphing;
4+
using UnityEngine;
5+
using UnityEditor.ShaderGraph.Drawing;
6+
using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers;
7+
using UnityEditor.ShaderGraph.Internal;
8+
using UnityEngine.Rendering.HighDefinition;
9+
using UnityEditor.ShaderGraph;
10+
using System.Globalization;
11+
using static UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers.ShaderInputPropertyDrawer;
12+
13+
namespace UnityEditor.Rendering.HighDefinition
14+
{
15+
[Serializable]
16+
[BlackboardInputInfo(55)]
17+
class DiffusionProfileShaderProperty : AbstractShaderProperty<LazyLoadReference<DiffusionProfileSettings>>, IShaderPropertyDrawer
18+
{
19+
internal DiffusionProfileShaderProperty()
20+
{
21+
displayName = "Diffusion Profile";
22+
}
23+
24+
internal override bool isBatchable => true;
25+
internal override bool isExposable => true;
26+
internal override bool isRenamable => true;
27+
internal override bool isGpuInstanceable => true;
28+
29+
public override PropertyType propertyType => PropertyType.Vector1;
30+
31+
string assetReferenceName => $"{referenceName}_Asset";
32+
33+
internal override string GetPropertyBlockString()
34+
{
35+
uint hash = 0;
36+
Vector4 asset = Vector4.zero;
37+
38+
if (value.isSet)
39+
{
40+
hash = value.asset.profile.hash;
41+
asset = HDUtils.ConvertGUIDToVector4(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value.asset)));
42+
}
43+
44+
/// <summary>Float to string convertion function without any loss of precision</summary>
45+
string f2s(float f) => System.Convert.ToDouble(f).ToString("0." + new string('#', 339));
46+
47+
return
48+
$@"[DiffusionProfile]{referenceName}(""{displayName}"", Float) = {f2s(HDShadowUtils.Asfloat(hash))}
49+
[HideInInspector]{assetReferenceName}(""{displayName}"", Vector) = ({f2s(asset.x)}, {f2s(asset.y)}, {f2s(asset.z)}, {f2s(asset.w)})";
50+
}
51+
52+
public override string GetDefaultReferenceName() => $"DiffusionProfile_{objectId}";
53+
54+
internal override string GetPropertyDeclarationString(string delimiter = ";") => $@"float {referenceName}{delimiter}";
55+
56+
internal override AbstractMaterialNode ToConcreteNode()
57+
{
58+
var node = new DiffusionProfileNode();
59+
node.diffusionProfile = value.asset;
60+
return node;
61+
}
62+
63+
internal override PreviewProperty GetPreviewMaterialProperty()
64+
{
65+
return new PreviewProperty(propertyType)
66+
{
67+
name = referenceName,
68+
floatValue = value.isSet ? HDShadowUtils.Asfloat(value.asset.profile.hash) : 0
69+
};
70+
}
71+
72+
internal override ShaderInput Copy()
73+
{
74+
return new DiffusionProfileShaderProperty()
75+
{
76+
displayName = displayName,
77+
hidden = hidden,
78+
value = value,
79+
precision = precision,
80+
gpuInstanced = gpuInstanced,
81+
};
82+
}
83+
84+
void IShaderPropertyDrawer.HandlePropertyField(PropertySheet propertySheet, PreChangeValueCallback preChangeValueCallback, PostChangeValueCallback postChangeValueCallback)
85+
{
86+
var diffusionProfileDrawer = new DiffusionProfilePropertyDrawer();
87+
88+
propertySheet.Add(diffusionProfileDrawer.CreateGUI(
89+
newValue => {
90+
preChangeValueCallback("Changed Diffusion Profile");
91+
value = newValue;
92+
postChangeValueCallback(true);
93+
},
94+
value.asset,
95+
"Diffusion Profile",
96+
out var _));
97+
}
98+
}
99+
}

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DiffusionProfileShaderProperty.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Nodes/DiffusionProfileNode.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
using System;
88
using System.Linq;
99
using UnityEngine.Rendering;
10+
using UnityEditor.ShaderGraph.Internal;
1011

1112
namespace UnityEditor.Rendering.HighDefinition
1213
{
1314
[SRPFilter(typeof(HDRenderPipeline))]
1415
[Title("Input", "High Definition Render Pipeline", "Diffusion Profile")]
1516
[FormerName("UnityEditor.Experimental.Rendering.HDPipeline.DiffusionProfileNode")]
1617
[FormerName("UnityEditor.ShaderGraph.DiffusionProfileNode")]
17-
class DiffusionProfileNode : AbstractMaterialNode, IGeneratesBodyCode
18+
class DiffusionProfileNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
1819
{
1920
public DiffusionProfileNode()
2021
{
@@ -110,5 +111,15 @@ public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMo
110111
// Note: we don't use the auto precision here because we need a 32 bit to store this value
111112
sb.AppendLine(string.Format("float {0} = asfloat(uint({1}));", GetVariableNameForSlot(0), hash));
112113
}
114+
115+
public AbstractShaderProperty AsShaderProperty()
116+
{
117+
var prop = new DiffusionProfileShaderProperty { value = diffusionProfile };
118+
if (diffusionProfile != null)
119+
prop.displayName = diffusionProfile.name;
120+
return prop;
121+
}
122+
123+
public int outputSlotId => kOutputSlotId;
113124
}
114125
}

com.unity.shadergraph/Editor/Data/Graphs/BooleanShaderProperty.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace UnityEditor.ShaderGraph.Internal
88
{
99
[Serializable]
1010
[FormerName("UnityEditor.ShaderGraph.BooleanShaderProperty")]
11+
[BlackboardInputInfo(20)]
1112
public sealed class BooleanShaderProperty : AbstractShaderProperty<bool>
1213
{
1314
internal BooleanShaderProperty()

com.unity.shadergraph/Editor/Data/Graphs/ColorShaderProperty.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace UnityEditor.ShaderGraph.Internal
77
{
88
[Serializable]
99
[FormerName("UnityEditor.ShaderGraph.ColorShaderProperty")]
10+
[BlackboardInputInfo(10)]
1011
public sealed class ColorShaderProperty : AbstractShaderProperty<Color>
1112
{
1213
internal ColorShaderProperty()

0 commit comments

Comments
 (0)