2 using System.Collections.Generic;
4 using UnityEngine.Experimental.Rendering.HDPipeline;
5 using UnityEngine.Rendering;
7 // Include material common properties names
8 using static UnityEngine.Experimental.Rendering.HDPipeline.HDMaterialProperties;
10 namespace UnityEditor.Experimental.Rendering.HDPipeline
12 // This block is shared for Lit and Layered surface inputs + tesselation variants
13 public class LitSurfaceInputsUIBlock : MaterialUIBlock
20 LayerOptions = 1 << 2,
23 All = ~0 ^ SubHeader // By default we don't want a sub-header
28 public const string header = "Surface Inputs";
30 public static GUIContent colorText = new GUIContent("Color", " Albedo (RGB) and Transparency (A).");
32 public static GUIContent baseColorText = new GUIContent("Base Map", "Specifies the base color (RGB) and opacity (A) of the Material.");
34 public static GUIContent metallicText = new GUIContent("Metallic", "Controls the scale factor for the Material's metallic effect.");
35 public static GUIContent smoothnessText = new GUIContent("Smoothness", "Controls the scale factor for the Material's smoothness.");
36 public static GUIContent smoothnessRemappingText = new GUIContent("Smoothness Remapping", "Controls a remap for the smoothness channel in the Mask Map.");
37 public static GUIContent aoRemappingText = new GUIContent("Ambient Occlusion Remapping", "Controls a remap for the ambient occlusion channel in the Mask Map.");
38 public static GUIContent maskMapSText = new GUIContent("Mask Map", "Specifies the Mask Map for this Material - Metallic (R), Ambient occlusion (G), Detail mask (B), Smoothness (A).");
39 public static GUIContent maskMapSpecularText = new GUIContent("Mask Map", "Specifies the Mask Map for this Material - Ambient occlusion (G), Detail mask (B), Smoothness (A).");
41 public static GUIContent normalMapSpaceText = new GUIContent("Normal Map Space", "");
42 public static GUIContent normalMapText = new GUIContent("Normal Map", "Specifies the Normal Map for this Material (BC7/BC5/DXT5(nm)) and controls its strength.");
43 public static GUIContent normalMapOSText = new GUIContent("Normal Map OS", "Specifies the object space Normal Map (BC7/DXT1/RGB).");
44 public static GUIContent bentNormalMapText = new GUIContent("Bent normal map", "Specifies the cosine weighted Bent Normal Map (BC7/BC5/DXT5(nm)) for this Material. Use only with indirect diffuse lighting (Lightmaps and Light Probes).");
45 public static GUIContent bentNormalMapOSText = new GUIContent("Bent normal map OS", "Specifies the object space Bent Normal Map (BC7/DXT1/RGB) for this Material. Use only with indirect diffuse lighting (Lightmaps and Light Probes).");
48 public static GUIContent heightMapText = new GUIContent("Height Map", "Specifies the Height Map (R) for this Material.\nFor floating point textures, set the Min, Max, and base values to 0, 1, and 0 respectively.");
49 public static GUIContent heightMapCenterText = new GUIContent("Base", "Controls the base of the Height Map (between 0 and 1).");
50 public static GUIContent heightMapMinText = new GUIContent("Min", "Sets the minimum value in the Height Map (in centimeters).");
51 public static GUIContent heightMapMaxText = new GUIContent("Max", "Sets the maximum value in the Height Map (in centimeters).");
52 public static GUIContent heightMapAmplitudeText = new GUIContent("Amplitude", "Sets the amplitude of the Height Map (in centimeters).");
53 public static GUIContent heightMapOffsetText = new GUIContent("Offset", "Sets the offset HDRP applies to the Height Map (in centimeters).");
54 public static GUIContent heightMapParametrization = new GUIContent("Parametrization", "Specifies the parametrization method for the Height Map.");
56 public static GUIContent normalMapSpaceWarning = new GUIContent("HDRP does not support object space normals with triplanar mapping.");
57 public static GUIContent tangentMapText = new GUIContent("Tangent Map", "Specifies the Tangent Map (BC7/BC5/DXT5(nm)) for this Material.");
58 public static GUIContent tangentMapOSText = new GUIContent("Tangent Map OS", "Specifies the object space Tangent Map (BC7/DXT1/RGB) for this Material.");
59 public static GUIContent anisotropyText = new GUIContent("Anisotropy", "Controls the scale factor for anisotropy.");
60 public static GUIContent anisotropyMapText = new GUIContent("Anisotropy Map", "Specifies the Anisotropy Map(R) for this Material.");
62 public static GUIContent UVBaseMappingText = new GUIContent("Base UV mapping", "");
63 public static GUIContent texWorldScaleText = new GUIContent("World scale", "Sets the tiling factor HDRP applies to Planar/Trilinear mapping.");
66 public static GUIContent energyConservingSpecularColorText = new GUIContent("Energy Conserving Specular Color", "When enabled, HDRP simulates energy conservation when using Specular Color mode. This results in high Specular Color values producing lower Diffuse Color values.");
67 public static GUIContent specularColorText = new GUIContent("Specular Color", "Specifies the Specular color (RGB) of this Material.");
70 public static GUIContent diffusionProfileText = new GUIContent("Diffusion Profile", "Specifies the Diffusion Profie HDRP uses to determine the behavior of the subsurface scattering/transmission effect.");
71 public static GUIContent subsurfaceMaskText = new GUIContent("Subsurface Mask", "Controls the overall strength of the subsurface scattering effect.");
72 public static GUIContent subsurfaceMaskMapText = new GUIContent("Subsurface Mask Map", "Specifies the Subsurface mask map (R) for this Material - This map controls the strength of the subsurface scattering effect.");
73 public static GUIContent thicknessText = new GUIContent("Thickness", "Controls the strength of the Thickness Map, low values allow some light to transmit through the object.");
74 public static GUIContent thicknessMapText = new GUIContent("Thickness Map", "Specifies the Thickness Map (R) for this Material - This map describes the thickness of the object. When subsurface scattering is enabled, low values allow some light to transmit through the object.");
75 public static GUIContent thicknessRemapText = new GUIContent("Thickness Remap", "Controls a remap for the Thickness Map from [0, 1] to the specified range.");
78 public static GUIContent iridescenceMaskText = new GUIContent("Iridescence Mask", "Specifies the Iridescence Mask (R) for this Material - This map controls the intensity of the iridescence.");
79 public static GUIContent iridescenceThicknessText = new GUIContent("Iridescence Layer Thickness");
80 public static GUIContent iridescenceThicknessMapText = new GUIContent("Iridescence Layer Thickness map", "Specifies the Iridescence Layer Thickness map (R) for this Material.");
81 public static GUIContent iridescenceThicknessRemapText = new GUIContent("Iridescence Layer Thickness remap");
84 public static GUIContent coatMaskText = new GUIContent("Coat Mask", "Attenuate the coating effect.");
87 public static readonly GUIContent layerTexWorldScaleText = EditorGUIUtility.TrTextContent("World Scale", "Sets the tiling factor of the Planar/Trilinear mapping.");
88 public static readonly GUIContent UVBlendMaskText = EditorGUIUtility.TrTextContent("BlendMask UV Mapping", "Specifies the UV Mapping mode of the layer.");
89 public static readonly GUIContent layerMapMaskText = EditorGUIUtility.TrTextContent("Layer Mask", "Specifies the Layer Mask for this Material");
90 public static readonly GUIContent vertexColorModeText = EditorGUIUtility.TrTextContent("Vertex Color Mode", "Specifies the method HDRP uses to color vertices.\nMultiply: Multiplies vertex color with the mask.\nAdditive: Remaps vertex color values between [-1, 1] and adds them to the mask (neutral value is 0.5 vertex color).");
91 public static readonly GUIContent layerCountText = EditorGUIUtility.TrTextContent("Layer Count", "Controls the number of layers for this Material.");
92 public static readonly GUIContent objectScaleAffectTileText = EditorGUIUtility.TrTextContent("Lock layers 0123 tiling with object Scale", "When enabled, tiling of each layer is affected by the Transform's Scale.");
93 public static readonly GUIContent objectScaleAffectTileText2 = EditorGUIUtility.TrTextContent("Lock layers 123 tiling with object Scale", "When enabled, tiling of each influenced layer (except the main layer) is affected by the Transform's Scale.");
94 public static readonly GUIContent useHeightBasedBlendText = EditorGUIUtility.TrTextContent("Use Height Based Blend", "When enabled, HDRP blends the layer with the underlying layer based on the height.");
95 public static readonly GUIContent useMainLayerInfluenceModeText = EditorGUIUtility.TrTextContent("Main Layer Influence", "Switches between regular layers mode and base/layers mode.");
96 public static readonly GUIContent heightTransition = EditorGUIUtility.TrTextContent("Height Transition", "Sets the size, in world units, of the smooth transition between layers.");
99 MaterialProperty[] UVBase = new MaterialProperty[kMaxLayerCount];
100 const string kUVBase = "_UVBase";
101 MaterialProperty[] TexWorldScale = new MaterialProperty[kMaxLayerCount];
102 const string kTexWorldScale = "_TexWorldScale";
103 MaterialProperty[] InvTilingScale = new MaterialProperty[kMaxLayerCount];
104 const string kInvTilingScale = "_InvTilingScale";
105 MaterialProperty[] UVMappingMask = new MaterialProperty[kMaxLayerCount];
106 const string kUVMappingMask = "_UVMappingMask";
108 MaterialProperty[] baseColor = new MaterialProperty[kMaxLayerCount];
109 const string kBaseColor = "_BaseColor";
110 MaterialProperty[] baseColorMap = new MaterialProperty[kMaxLayerCount];
111 const string kBaseColorMap = "_BaseColorMap";
112 MaterialProperty[] metallic = new MaterialProperty[kMaxLayerCount];
113 const string kMetallic = "_Metallic";
114 MaterialProperty[] smoothness = new MaterialProperty[kMaxLayerCount];
115 const string kSmoothness = "_Smoothness";
116 MaterialProperty[] smoothnessRemapMin = new MaterialProperty[kMaxLayerCount];
117 const string kSmoothnessRemapMin = "_SmoothnessRemapMin";
118 MaterialProperty[] smoothnessRemapMax = new MaterialProperty[kMaxLayerCount];
119 const string kSmoothnessRemapMax = "_SmoothnessRemapMax";
120 MaterialProperty[] aoRemapMin = new MaterialProperty[kMaxLayerCount];
121 const string kAORemapMin = "_AORemapMin";
122 MaterialProperty[] aoRemapMax = new MaterialProperty[kMaxLayerCount];
123 const string kAORemapMax = "_AORemapMax";
124 MaterialProperty[] maskMap = new MaterialProperty[kMaxLayerCount];
125 const string kMaskMap = "_MaskMap";
126 MaterialProperty[] normalScale = new MaterialProperty[kMaxLayerCount];
127 const string kNormalScale = "_NormalScale";
128 MaterialProperty[] normalMap = new MaterialProperty[kMaxLayerCount];
129 const string kNormalMap = "_NormalMap";
130 MaterialProperty[] normalMapOS = new MaterialProperty[kMaxLayerCount];
131 const string kNormalMapOS = "_NormalMapOS";
132 MaterialProperty[] bentNormalMap = new MaterialProperty[kMaxLayerCount];
133 const string kBentNormalMap = "_BentNormalMap";
134 MaterialProperty[] bentNormalMapOS = new MaterialProperty[kMaxLayerCount];
135 const string kBentNormalMapOS = "_BentNormalMapOS";
136 MaterialProperty[] normalMapSpace = new MaterialProperty[kMaxLayerCount];
137 const string kNormalMapSpace = "_NormalMapSpace";
139 MaterialProperty[] heightMap = new MaterialProperty[kMaxLayerCount];
140 const string kHeightMap = "_HeightMap";
141 MaterialProperty[] heightAmplitude = new MaterialProperty[kMaxLayerCount];
142 const string kHeightAmplitude = "_HeightAmplitude";
143 MaterialProperty[] heightCenter = new MaterialProperty[kMaxLayerCount];
144 const string kHeightCenter = "_HeightCenter";
145 MaterialProperty[] heightPoMAmplitude = new MaterialProperty[kMaxLayerCount];
146 const string kHeightPoMAmplitude = "_HeightPoMAmplitude";
147 MaterialProperty[] heightTessCenter = new MaterialProperty[kMaxLayerCount];
148 const string kHeightTessCenter = "_HeightTessCenter";
149 MaterialProperty[] heightTessAmplitude = new MaterialProperty[kMaxLayerCount];
150 const string kHeightTessAmplitude = "_HeightTessAmplitude";
151 MaterialProperty[] heightMin = new MaterialProperty[kMaxLayerCount];
152 const string kHeightMin = "_HeightMin";
153 MaterialProperty[] heightMax = new MaterialProperty[kMaxLayerCount];
154 const string kHeightMax = "_HeightMax";
155 MaterialProperty[] heightOffset = new MaterialProperty[kMaxLayerCount];
156 const string kHeightOffset = "_HeightOffset";
157 MaterialProperty[] heightParametrization = new MaterialProperty[kMaxLayerCount];
158 const string kHeightParametrization = "_HeightMapParametrization";
160 MaterialProperty displacementMode = null;
161 const string kDisplacementMode = "_DisplacementMode";
163 MaterialProperty tangentMap = null;
164 const string kTangentMap = "_TangentMap";
165 MaterialProperty tangentMapOS = null;
166 const string kTangentMapOS = "_TangentMapOS";
167 MaterialProperty anisotropy = null;
168 const string kAnisotropy = "_Anisotropy";
169 MaterialProperty anisotropyMap = null;
170 const string kAnisotropyMap = "_AnisotropyMap";
172 MaterialProperty energyConservingSpecularColor = null;
173 const string kEnergyConservingSpecularColor = "_EnergyConservingSpecularColor";
174 MaterialProperty specularColor = null;
175 const string kSpecularColor = "_SpecularColor";
176 MaterialProperty specularColorMap = null;
177 const string kSpecularColorMap = "_SpecularColorMap";
179 MaterialProperty[] diffusionProfileHash = new MaterialProperty[kMaxLayerCount];
180 const string kDiffusionProfileHash = "_DiffusionProfileHash";
181 MaterialProperty[] diffusionProfileAsset = new MaterialProperty[kMaxLayerCount];
182 const string kDiffusionProfileAsset = "_DiffusionProfileAsset";
183 MaterialProperty[] subsurfaceMask = new MaterialProperty[kMaxLayerCount];
184 const string kSubsurfaceMask = "_SubsurfaceMask";
185 MaterialProperty[] subsurfaceMaskMap = new MaterialProperty[kMaxLayerCount];
186 const string kSubsurfaceMaskMap = "_SubsurfaceMaskMap";
187 MaterialProperty[] thickness = new MaterialProperty[kMaxLayerCount];
188 const string kThickness = "_Thickness";
189 MaterialProperty[] thicknessMap = new MaterialProperty[kMaxLayerCount];
190 const string kThicknessMap = "_ThicknessMap";
191 MaterialProperty[] thicknessRemap = new MaterialProperty[kMaxLayerCount];
192 const string kThicknessRemap = "_ThicknessRemap";
194 MaterialProperty iridescenceMask = null;
195 const string kIridescenceMask = "_IridescenceMask";
196 MaterialProperty iridescenceMaskMap = null;
197 const string kIridescenceMaskMap = "_IridescenceMaskMap";
198 MaterialProperty iridescenceThickness = null;
199 const string kIridescenceThickness = "_IridescenceThickness";
200 MaterialProperty iridescenceThicknessMap = null;
201 const string kIridescenceThicknessMap = "_IridescenceThicknessMap";
202 MaterialProperty iridescenceThicknessRemap = null;
203 const string kIridescenceThicknessRemap = "_IridescenceThicknessRemap";
206 MaterialProperty materialID = null;
207 MaterialProperty transmissionEnable = null;
208 const string kTransmissionEnable = "_TransmissionEnable";
211 MaterialProperty coatMask = null;
212 const string kCoatMask = "_CoatMask";
213 MaterialProperty coatMaskMap = null;
214 const string kCoatMaskMap = "_CoatMaskMap";
217 MaterialProperty layerCount = null;
218 const string kLayerCount = "_LayerCount";
219 MaterialProperty layerMaskMap = null;
220 const string kLayerMaskMap = "_LayerMaskMap";
221 MaterialProperty layerInfluenceMaskMap = null;
222 const string kLayerInfluenceMaskMap = "_LayerInfluenceMaskMap";
223 MaterialProperty vertexColorMode = null;
224 const string kVertexColorMode = "_VertexColorMode";
225 MaterialProperty objectScaleAffectTile = null;
226 const string kObjectScaleAffectTile = "_ObjectScaleAffectTile";
227 MaterialProperty UVBlendMask = null;
228 const string kUVBlendMask = "_UVBlendMask";
229 MaterialProperty UVMappingMaskBlendMask = null;
230 const string kUVMappingMaskBlendMask = "_UVMappingMaskBlendMask";
231 MaterialProperty texWorldScaleBlendMask = null;
232 const string kTexWorldScaleBlendMask = "_TexWorldScaleBlendMask";
233 MaterialProperty useMainLayerInfluence = null;
234 const string kkUseMainLayerInfluence = "_UseMainLayerInfluence";
235 MaterialProperty useHeightBasedBlend = null;
236 const string kUseHeightBasedBlend = "_UseHeightBasedBlend";
239 MaterialProperty heightTransition = null;
240 const string kHeightTransition = "_HeightTransition";
242 Expandable m_ExpandableBit;
246 bool m_UseHeightBasedBlend;
249 bool isLayeredLit => m_LayerCount > 1;
251 public LitSurfaceInputsUIBlock(Expandable expandableBit, int layerCount = 1, int layerIndex = 0, Features features = Features.All, Color dotColor = default(Color))
253 m_ExpandableBit = expandableBit;
254 m_Features = features;
255 m_LayerCount = layerCount;
256 m_LayerIndex = layerIndex;
257 m_DotColor = dotColor;
260 public override void LoadMaterialProperties()
262 UVBase = FindPropertyLayered(kUVBase, m_LayerCount, true);
263 TexWorldScale = FindPropertyLayered(kTexWorldScale, m_LayerCount);
264 InvTilingScale = FindPropertyLayered(kInvTilingScale, m_LayerCount);
265 UVMappingMask = FindPropertyLayered(kUVMappingMask, m_LayerCount);
267 baseColor = FindPropertyLayered(kBaseColor, m_LayerCount);
268 baseColorMap = FindPropertyLayered(kBaseColorMap, m_LayerCount);
269 metallic = FindPropertyLayered(kMetallic, m_LayerCount);
270 smoothness = FindPropertyLayered(kSmoothness, m_LayerCount);
271 smoothnessRemapMin = FindPropertyLayered(kSmoothnessRemapMin, m_LayerCount);
272 smoothnessRemapMax = FindPropertyLayered(kSmoothnessRemapMax, m_LayerCount);
273 aoRemapMin = FindPropertyLayered(kAORemapMin, m_LayerCount);
274 aoRemapMax = FindPropertyLayered(kAORemapMax, m_LayerCount);
275 maskMap = FindPropertyLayered(kMaskMap, m_LayerCount);
276 normalMap = FindPropertyLayered(kNormalMap, m_LayerCount);
277 normalMapOS = FindPropertyLayered(kNormalMapOS, m_LayerCount);
278 normalScale = FindPropertyLayered(kNormalScale, m_LayerCount);
279 bentNormalMap = FindPropertyLayered(kBentNormalMap, m_LayerCount);
280 bentNormalMapOS = FindPropertyLayered(kBentNormalMapOS, m_LayerCount);
281 normalMapSpace = FindPropertyLayered(kNormalMapSpace, m_LayerCount);
284 heightMap = FindPropertyLayered(kHeightMap, m_LayerCount);
285 heightAmplitude = FindPropertyLayered(kHeightAmplitude, m_LayerCount);
286 heightCenter = FindPropertyLayered(kHeightCenter, m_LayerCount);
287 heightPoMAmplitude = FindPropertyLayered(kHeightPoMAmplitude, m_LayerCount);
288 heightMin = FindPropertyLayered(kHeightMin, m_LayerCount);
289 heightMax = FindPropertyLayered(kHeightMax, m_LayerCount);
290 heightTessCenter = FindPropertyLayered(kHeightTessCenter, m_LayerCount);
291 heightTessAmplitude = FindPropertyLayered(kHeightTessAmplitude, m_LayerCount);
292 heightOffset = FindPropertyLayered(kHeightOffset, m_LayerCount);
293 heightParametrization = FindPropertyLayered(kHeightParametrization, m_LayerCount);
296 energyConservingSpecularColor = FindProperty(kEnergyConservingSpecularColor);
297 specularColor = FindProperty(kSpecularColor);
298 specularColorMap = FindProperty(kSpecularColorMap);
301 tangentMap = FindProperty(kTangentMap);
302 tangentMapOS = FindProperty(kTangentMapOS);
303 anisotropy = FindProperty(kAnisotropy);
304 anisotropyMap = FindProperty(kAnisotropyMap);
307 iridescenceMask = FindProperty(kIridescenceMask);
308 iridescenceMaskMap = FindProperty(kIridescenceMaskMap);
309 iridescenceThickness = FindProperty(kIridescenceThickness);
310 iridescenceThicknessMap = FindProperty(kIridescenceThicknessMap);
311 iridescenceThicknessRemap = FindProperty(kIridescenceThicknessRemap);
314 diffusionProfileHash = FindPropertyLayered(kDiffusionProfileHash, m_LayerCount);
315 diffusionProfileAsset = FindPropertyLayered(kDiffusionProfileAsset, m_LayerCount);
316 subsurfaceMask = FindPropertyLayered(kSubsurfaceMask, m_LayerCount);
317 subsurfaceMaskMap = FindPropertyLayered(kSubsurfaceMaskMap, m_LayerCount);
318 thickness = FindPropertyLayered(kThickness, m_LayerCount);
319 thicknessMap = FindPropertyLayered(kThicknessMap, m_LayerCount);
320 thicknessRemap = FindPropertyLayered(kThicknessRemap, m_LayerCount);
323 coatMask = FindProperty(kCoatMask);
324 coatMaskMap = FindProperty(kCoatMaskMap);
326 displacementMode = FindProperty(kDisplacementMode);
328 materialID = FindProperty(kMaterialID);
329 transmissionEnable = FindProperty(kTransmissionEnable);
332 layerCount = FindProperty(kLayerCount);
333 layerMaskMap = FindProperty(kLayerMaskMap);
334 layerInfluenceMaskMap = FindProperty(kLayerInfluenceMaskMap);
335 vertexColorMode = FindProperty(kVertexColorMode);
336 objectScaleAffectTile = FindProperty(kObjectScaleAffectTile);
337 UVBlendMask = FindProperty(kUVBlendMask);
338 UVMappingMaskBlendMask = FindProperty(kUVMappingMaskBlendMask);
339 texWorldScaleBlendMask = FindProperty(kTexWorldScaleBlendMask);
340 useMainLayerInfluence = FindProperty(kkUseMainLayerInfluence);
341 useHeightBasedBlend = FindProperty(kUseHeightBasedBlend);
344 heightTransition = FindProperty(kHeightTransition);
347 public override void OnGUI()
349 bool subHeader = (m_Features & Features.SubHeader) != 0;
351 using (var header = new MaterialHeaderScope(Styles.header, (uint)m_ExpandableBit, materialEditor, subHeader: subHeader, colorDot: m_DotColor))
355 if ((m_Features & Features.Standard) != 0)
356 DrawSurfaceInputsGUI();
357 if ((m_Features & Features.LayerOptions) != 0)
358 DrawLayerOptionsGUI();
363 void DrawSurfaceInputsGUI()
365 UVBaseMapping uvBaseMapping = (UVBaseMapping)UVBase[m_LayerIndex].floatValue;
368 materialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap[m_LayerIndex], baseColor[m_LayerIndex]);
370 // TODO: does not work with multi-selection
371 MaterialId materialIdValue = materials[0].GetMaterialId();
373 if (materialIdValue == MaterialId.LitStandard ||
374 materialIdValue == MaterialId.LitAniso ||
375 materialIdValue == MaterialId.LitIridescence)
377 materialEditor.ShaderProperty(metallic[m_LayerIndex], Styles.metallicText);
380 if (maskMap[m_LayerIndex].textureValue == null)
382 materialEditor.ShaderProperty(smoothness[m_LayerIndex], Styles.smoothnessText);
386 float remapMin = smoothnessRemapMin[m_LayerIndex].floatValue;
387 float remapMax = smoothnessRemapMax[m_LayerIndex].floatValue;
388 EditorGUI.BeginChangeCheck();
389 EditorGUILayout.MinMaxSlider(Styles.smoothnessRemappingText, ref remapMin, ref remapMax, 0.0f, 1.0f);
390 if (EditorGUI.EndChangeCheck())
392 smoothnessRemapMin[m_LayerIndex].floatValue = remapMin;
393 smoothnessRemapMax[m_LayerIndex].floatValue = remapMax;
396 float aoMin = aoRemapMin[m_LayerIndex].floatValue;
397 float aoMax = aoRemapMax[m_LayerIndex].floatValue;
398 EditorGUI.BeginChangeCheck();
399 EditorGUILayout.MinMaxSlider(Styles.aoRemappingText, ref aoMin, ref aoMax, 0.0f, 1.0f);
400 if (EditorGUI.EndChangeCheck())
402 aoRemapMin[m_LayerIndex].floatValue = aoMin;
403 aoRemapMax[m_LayerIndex].floatValue = aoMax;
407 materialEditor.TexturePropertySingleLine((materialIdValue == MaterialId.LitSpecular) ? Styles.maskMapSpecularText : Styles.maskMapSText, maskMap[m_LayerIndex]);
409 materialEditor.ShaderProperty(normalMapSpace[m_LayerIndex], Styles.normalMapSpaceText);
411 // Triplanar only work with tangent space normal
412 if ((NormalMapSpace)normalMapSpace[m_LayerIndex].floatValue == NormalMapSpace.ObjectSpace && ((UVBaseMapping)UVBase[m_LayerIndex].floatValue == UVBaseMapping.Triplanar))
414 EditorGUILayout.HelpBox(Styles.normalMapSpaceWarning.text, MessageType.Error);
417 // We have two different property for object space and tangent space normal map to allow
418 // 1. to go back and forth
419 // 2. to avoid the warning that ask to fix the object normal map texture (normalOS are just linear RGB texture
420 if ((NormalMapSpace)normalMapSpace[m_LayerIndex].floatValue == NormalMapSpace.TangentSpace)
422 materialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap[m_LayerIndex], normalScale[m_LayerIndex]);
423 materialEditor.TexturePropertySingleLine(Styles.bentNormalMapText, bentNormalMap[m_LayerIndex]);
427 // No scaling in object space
428 materialEditor.TexturePropertySingleLine(Styles.normalMapOSText, normalMapOS[m_LayerIndex]);
429 materialEditor.TexturePropertySingleLine(Styles.bentNormalMapOSText, bentNormalMapOS[m_LayerIndex]);
432 DisplacementMode displaceMode = (DisplacementMode)displacementMode.floatValue;
433 if (displaceMode != DisplacementMode.None || (m_Features & Features.HeightMap) != 0)
435 EditorGUI.BeginChangeCheck();
436 materialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap[m_LayerIndex]);
437 if (!heightMap[m_LayerIndex].hasMixedValue && heightMap[m_LayerIndex].textureValue != null && !displacementMode.hasMixedValue)
439 EditorGUI.indentLevel++;
440 if (displaceMode == DisplacementMode.Pixel)
442 materialEditor.ShaderProperty(heightPoMAmplitude[m_LayerIndex], Styles.heightMapAmplitudeText);
446 materialEditor.ShaderProperty(heightParametrization[m_LayerIndex], Styles.heightMapParametrization);
447 if (!heightParametrization[m_LayerIndex].hasMixedValue)
449 HeightmapParametrization parametrization = (HeightmapParametrization)heightParametrization[m_LayerIndex].floatValue;
450 if (parametrization == HeightmapParametrization.MinMax)
452 EditorGUI.BeginChangeCheck();
453 materialEditor.ShaderProperty(heightMin[m_LayerIndex], Styles.heightMapMinText);
454 if (EditorGUI.EndChangeCheck())
455 heightMin[m_LayerIndex].floatValue = Mathf.Min(heightMin[m_LayerIndex].floatValue, heightMax[m_LayerIndex].floatValue);
456 EditorGUI.BeginChangeCheck();
457 materialEditor.ShaderProperty(heightMax[m_LayerIndex], Styles.heightMapMaxText);
458 if (EditorGUI.EndChangeCheck())
459 heightMax[m_LayerIndex].floatValue = Mathf.Max(heightMin[m_LayerIndex].floatValue, heightMax[m_LayerIndex].floatValue);
463 EditorGUI.BeginChangeCheck();
464 materialEditor.ShaderProperty(heightTessAmplitude[m_LayerIndex], Styles.heightMapAmplitudeText);
465 if (EditorGUI.EndChangeCheck())
466 heightTessAmplitude[m_LayerIndex].floatValue = Mathf.Max(0f, heightTessAmplitude[m_LayerIndex].floatValue);
467 materialEditor.ShaderProperty(heightTessCenter[m_LayerIndex], Styles.heightMapCenterText);
470 materialEditor.ShaderProperty(heightOffset[m_LayerIndex], Styles.heightMapOffsetText);
473 EditorGUI.indentLevel--;
476 // UI only updates intermediate values, this will update the values actually used by the shader.
477 if (EditorGUI.EndChangeCheck())
479 // Fetch the surface option block which contains the function to update the displacement datas
480 var surfaceOptionUIBlock = FetchUIBlockInCurrentList< SurfaceOptionUIBlock >();
481 surfaceOptionUIBlock.UpdateDisplacement(m_LayerIndex);
485 switch (materialIdValue)
487 case MaterialId.LitSSS:
488 case MaterialId.LitTranslucent:
489 ShaderSSSAndTransmissionInputGUI();
491 case MaterialId.LitStandard:
495 // Following mode are not supported by layered lit and will not be call by it
496 // as the MaterialId enum don't define it
497 case MaterialId.LitAniso:
498 ShaderAnisoInputGUI();
500 case MaterialId.LitSpecular:
501 ShaderSpecularColorInputGUI();
503 case MaterialId.LitIridescence:
504 ShaderIridescenceInputGUI();
508 Debug.Assert(false, "Encountered an unsupported MaterialID.");
514 ShaderClearCoatInputGUI();
517 EditorGUILayout.Space();
519 EditorGUI.BeginChangeCheck();
520 materialEditor.ShaderProperty(UVBase[m_LayerIndex], Styles.UVBaseMappingText);
521 uvBaseMapping = (UVBaseMapping)UVBase[m_LayerIndex].floatValue;
523 X = (uvBaseMapping == UVBaseMapping.UV0) ? 1.0f : 0.0f;
524 Y = (uvBaseMapping == UVBaseMapping.UV1) ? 1.0f : 0.0f;
525 Z = (uvBaseMapping == UVBaseMapping.UV2) ? 1.0f : 0.0f;
526 W = (uvBaseMapping == UVBaseMapping.UV3) ? 1.0f : 0.0f;
528 UVMappingMask[m_LayerIndex].colorValue = new Color(X, Y, Z, W);
530 if ((uvBaseMapping == UVBaseMapping.Planar) || (uvBaseMapping == UVBaseMapping.Triplanar))
532 materialEditor.ShaderProperty(TexWorldScale[m_LayerIndex], Styles.texWorldScaleText);
534 materialEditor.TextureScaleOffsetProperty(baseColorMap[m_LayerIndex]);
535 if (EditorGUI.EndChangeCheck())
538 InvTilingScale[m_LayerIndex].floatValue = 2.0f / (Mathf.Abs(baseColorMap[m_LayerIndex].textureScaleAndOffset.x) + Mathf.Abs(baseColorMap[m_LayerIndex].textureScaleAndOffset.y));
539 if ((uvBaseMapping == UVBaseMapping.Planar) || (uvBaseMapping == UVBaseMapping.Triplanar))
541 InvTilingScale[m_LayerIndex].floatValue = InvTilingScale[m_LayerIndex].floatValue / TexWorldScale[m_LayerIndex].floatValue;
546 void ShaderSSSAndTransmissionInputGUI()
548 var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
550 if (hdPipeline == null)
553 using (var scope = new EditorGUI.ChangeCheckScope())
555 using (new EditorGUILayout.HorizontalScope())
557 // We can't cache these fields because of several edge cases like undo/redo or pressing escape in the object picker
558 string guid = HDUtils.ConvertVector4ToGUID(diffusionProfileAsset[m_LayerIndex].vectorValue);
559 DiffusionProfileSettings diffusionProfile = AssetDatabase.LoadAssetAtPath<DiffusionProfileSettings>(AssetDatabase.GUIDToAssetPath(guid));
561 // is it okay to do this every frame ?
562 using (var changeScope = new EditorGUI.ChangeCheckScope())
564 diffusionProfile = (DiffusionProfileSettings)EditorGUILayout.ObjectField(Styles.diffusionProfileText, diffusionProfile, typeof(DiffusionProfileSettings), false);
565 if (changeScope.changed)
567 Vector4 newGuid = Vector4.zero;
570 if (diffusionProfile != null)
572 guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(diffusionProfile));
573 newGuid = HDUtils.ConvertGUIDToVector4(guid);
574 hash = HDShadowUtils.Asfloat(diffusionProfile.profile.hash);
577 // encode back GUID and it's hash
578 diffusionProfileAsset[m_LayerIndex].vectorValue = newGuid;
579 diffusionProfileHash[m_LayerIndex].floatValue = hash;
585 // TODO: does not work with multi-selection
586 if ((int)materialID.floatValue == (int)MaterialId.LitSSS && materials[0].GetSurfaceType() != SurfaceType.Transparent)
588 materialEditor.ShaderProperty(subsurfaceMask[m_LayerIndex], Styles.subsurfaceMaskText);
589 materialEditor.TexturePropertySingleLine(Styles.subsurfaceMaskMapText, subsurfaceMaskMap[m_LayerIndex]);
592 if ((int)materialID.floatValue == (int)MaterialId.LitTranslucent ||
593 ((int)materialID.floatValue == (int)MaterialId.LitSSS && transmissionEnable.floatValue > 0.0f))
595 materialEditor.TexturePropertySingleLine(Styles.thicknessMapText, thicknessMap[m_LayerIndex]);
596 if (thicknessMap[m_LayerIndex].textureValue != null)
598 // Display the remap of texture values.
599 Vector2 remap = thicknessRemap[m_LayerIndex].vectorValue;
600 EditorGUI.BeginChangeCheck();
601 EditorGUILayout.MinMaxSlider(Styles.thicknessRemapText, ref remap.x, ref remap.y, 0.0f, 1.0f);
602 if (EditorGUI.EndChangeCheck())
604 thicknessRemap[m_LayerIndex].vectorValue = remap;
609 // Allow the user to set the constant value of thickness if no thickness map is provided.
610 materialEditor.ShaderProperty(thickness[m_LayerIndex], Styles.thicknessText);
615 void ShaderAnisoInputGUI()
617 if ((NormalMapSpace)normalMapSpace[0].floatValue == NormalMapSpace.TangentSpace)
619 materialEditor.TexturePropertySingleLine(Styles.tangentMapText, tangentMap);
623 materialEditor.TexturePropertySingleLine(Styles.tangentMapOSText, tangentMapOS);
625 materialEditor.ShaderProperty(anisotropy, Styles.anisotropyText);
626 materialEditor.TexturePropertySingleLine(Styles.anisotropyMapText, anisotropyMap);
629 void ShaderSpecularColorInputGUI()
631 materialEditor.TexturePropertySingleLine(Styles.specularColorText, specularColorMap, specularColor);
632 EditorGUI.indentLevel++;
633 materialEditor.ShaderProperty(energyConservingSpecularColor, Styles.energyConservingSpecularColorText);
634 EditorGUI.indentLevel--;
637 void ShaderIridescenceInputGUI()
639 materialEditor.TexturePropertySingleLine(Styles.iridescenceMaskText, iridescenceMaskMap, iridescenceMask);
641 if (iridescenceThicknessMap.textureValue != null)
643 materialEditor.TexturePropertySingleLine(Styles.iridescenceThicknessMapText, iridescenceThicknessMap);
644 // Display the remap of texture values.
645 Vector2 remap = iridescenceThicknessRemap.vectorValue;
646 EditorGUI.BeginChangeCheck();
647 EditorGUILayout.MinMaxSlider(Styles.iridescenceThicknessRemapText, ref remap.x, ref remap.y, 0.0f, 1.0f);
648 if (EditorGUI.EndChangeCheck())
650 iridescenceThicknessRemap.vectorValue = remap;
655 // Allow the user to set the constant value of thickness if no thickness map is provided.
656 materialEditor.TexturePropertySingleLine(Styles.iridescenceThicknessMapText, iridescenceThicknessMap, iridescenceThickness);
660 void ShaderClearCoatInputGUI()
662 materialEditor.TexturePropertySingleLine(Styles.coatMaskText, coatMaskMap, coatMask);
665 void DrawLayerOptionsGUI()
667 EditorGUI.showMixedValue = layerCount.hasMixedValue;
668 EditorGUI.BeginChangeCheck();
669 int newLayerCount = EditorGUILayout.IntSlider(Styles.layerCountText, (int)layerCount.floatValue, 2, 4);
670 if (EditorGUI.EndChangeCheck())
672 Material material = materialEditor.target as Material;
673 Undo.RecordObject(material, "Change layer count");
674 // Technically not needed (i think), TODO: check
675 // numLayer = newLayerCount;
676 layerCount.floatValue = (float)newLayerCount;
679 materialEditor.TexturePropertySingleLine(Styles.layerMapMaskText, layerMaskMap);
681 EditorGUI.indentLevel++;
682 materialEditor.ShaderProperty(UVBlendMask, Styles.UVBlendMaskText);
683 UVBaseMapping uvBlendMask = (UVBaseMapping)UVBlendMask.floatValue;
686 X = (uvBlendMask == UVBaseMapping.UV0) ? 1.0f : 0.0f;
687 Y = (uvBlendMask == UVBaseMapping.UV1) ? 1.0f : 0.0f;
688 Z = (uvBlendMask == UVBaseMapping.UV2) ? 1.0f : 0.0f;
689 W = (uvBlendMask == UVBaseMapping.UV3) ? 1.0f : 0.0f;
691 UVMappingMaskBlendMask.colorValue = new Color(X, Y, Z, W);
693 if (((UVBaseMapping)UVBlendMask.floatValue == UVBaseMapping.Planar) ||
694 ((UVBaseMapping)UVBlendMask.floatValue == UVBaseMapping.Triplanar))
696 materialEditor.ShaderProperty(texWorldScaleBlendMask, Styles.layerTexWorldScaleText);
698 materialEditor.TextureScaleOffsetProperty(layerMaskMap);
699 EditorGUI.indentLevel--;
701 materialEditor.ShaderProperty(vertexColorMode, Styles.vertexColorModeText);
703 EditorGUI.BeginChangeCheck();
704 EditorGUI.showMixedValue = useMainLayerInfluence.hasMixedValue;
705 bool mainLayerModeInfluenceEnable = EditorGUILayout.Toggle(Styles.useMainLayerInfluenceModeText, useMainLayerInfluence.floatValue > 0.0f);
706 if (EditorGUI.EndChangeCheck())
708 useMainLayerInfluence.floatValue = mainLayerModeInfluenceEnable ? 1.0f : 0.0f;
711 EditorGUI.BeginChangeCheck();
712 EditorGUI.showMixedValue = useHeightBasedBlend.hasMixedValue;
713 m_UseHeightBasedBlend = EditorGUILayout.Toggle(Styles.useHeightBasedBlendText, useHeightBasedBlend.floatValue > 0.0f);
714 if (EditorGUI.EndChangeCheck())
716 useHeightBasedBlend.floatValue = m_UseHeightBasedBlend ? 1.0f : 0.0f;
719 if (m_UseHeightBasedBlend)
721 EditorGUI.indentLevel++;
722 materialEditor.ShaderProperty(heightTransition, Styles.heightTransition);
723 EditorGUI.indentLevel--;
726 materialEditor.ShaderProperty(objectScaleAffectTile, mainLayerModeInfluenceEnable ? Styles.objectScaleAffectTileText2 : Styles.objectScaleAffectTileText);