OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.render-pipelines.high-definition@6.9.0-preview / Editor / Material / UIBlocks / LitSurfaceInputsUIBlock.cs
1 using System;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.Experimental.Rendering.HDPipeline;
5 using UnityEngine.Rendering;
6
7 // Include material common properties names
8 using static UnityEngine.Experimental.Rendering.HDPipeline.HDMaterialProperties;
9
10 namespace UnityEditor.Experimental.Rendering.HDPipeline
11 {
12     // This block is shared for Lit and Layered surface inputs + tesselation variants
13     public class LitSurfaceInputsUIBlock : MaterialUIBlock
14     {
15         public enum Features
16         {
17             None            = 0,
18             CoatMask        = 1 << 0,
19             HeightMap       = 1 << 1,
20             LayerOptions    = 1 << 2,
21             SubHeader       = 1 << 3,
22             Standard        = 1 << 4,
23             All             = ~0 ^ SubHeader // By default we don't want a sub-header
24         }
25
26         public class Styles
27         {
28             public const string header = "Surface Inputs";
29
30             public static GUIContent colorText = new GUIContent("Color", " Albedo (RGB) and Transparency (A).");
31
32             public static GUIContent baseColorText = new GUIContent("Base Map", "Specifies the base color (RGB) and opacity (A) of the Material.");
33
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).");
40
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).");
46
47             // Height
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.");
55
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.");
61
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.");
64
65             // Specular color
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.");
68
69             // Subsurface
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.");
76
77             // Iridescence
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");
82             
83             // Clear Coat
84             public static GUIContent coatMaskText = new GUIContent("Coat Mask", "Attenuate the coating effect.");
85
86             // Layer Options
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.");
97         }
98
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";
107
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";
138
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";
159
160         MaterialProperty displacementMode = null;
161         const string kDisplacementMode = "_DisplacementMode";
162
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";
171
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";
178
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";
193
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";
204
205         // Material ID
206         MaterialProperty materialID  = null;
207         MaterialProperty transmissionEnable = null;
208         const string kTransmissionEnable = "_TransmissionEnable";
209
210         // Coat mask
211         MaterialProperty coatMask = null;
212         const string kCoatMask = "_CoatMask";
213         MaterialProperty coatMaskMap = null;
214         const string kCoatMaskMap = "_CoatMaskMap";
215
216         // Layer options
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";
237
238         // Height blend
239         MaterialProperty heightTransition = null;
240         const string kHeightTransition = "_HeightTransition";
241
242         Expandable  m_ExpandableBit;
243         Features    m_Features;
244         int         m_LayerCount;
245         int         m_LayerIndex;
246         bool        m_UseHeightBasedBlend;
247         Color       m_DotColor;
248
249         bool        isLayeredLit => m_LayerCount > 1;
250
251         public LitSurfaceInputsUIBlock(Expandable expandableBit, int layerCount = 1, int layerIndex = 0, Features features = Features.All, Color dotColor = default(Color))
252         {
253             m_ExpandableBit = expandableBit;
254             m_Features = features;
255             m_LayerCount = layerCount;
256             m_LayerIndex = layerIndex;
257             m_DotColor = dotColor;
258         }
259
260         public override void LoadMaterialProperties()
261         {
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);
266
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);
282
283             // Height
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);
294
295             // Specular Color
296             energyConservingSpecularColor = FindProperty(kEnergyConservingSpecularColor);
297             specularColor = FindProperty(kSpecularColor);
298             specularColorMap = FindProperty(kSpecularColorMap);
299
300             // Anisotropy
301             tangentMap = FindProperty(kTangentMap);
302             tangentMapOS = FindProperty(kTangentMapOS);
303             anisotropy = FindProperty(kAnisotropy);
304             anisotropyMap = FindProperty(kAnisotropyMap);
305
306             // Iridescence
307             iridescenceMask = FindProperty(kIridescenceMask);
308             iridescenceMaskMap = FindProperty(kIridescenceMaskMap);
309             iridescenceThickness = FindProperty(kIridescenceThickness);
310             iridescenceThicknessMap = FindProperty(kIridescenceThicknessMap);
311             iridescenceThicknessRemap = FindProperty(kIridescenceThicknessRemap);
312
313             // Sub surface
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);
321             
322             // clear coat
323             coatMask = FindProperty(kCoatMask);
324             coatMaskMap = FindProperty(kCoatMaskMap);
325
326             displacementMode = FindProperty(kDisplacementMode);
327
328             materialID = FindProperty(kMaterialID);
329             transmissionEnable = FindProperty(kTransmissionEnable);
330
331             // Layer options
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);
342
343             // Height blend
344             heightTransition = FindProperty(kHeightTransition);
345         }
346
347         public override void OnGUI()
348         {
349             bool subHeader = (m_Features & Features.SubHeader) != 0;
350
351             using (var header = new MaterialHeaderScope(Styles.header, (uint)m_ExpandableBit, materialEditor, subHeader: subHeader, colorDot: m_DotColor))
352             {
353                 if (header.expanded)
354                 {
355                     if ((m_Features & Features.Standard) != 0)
356                         DrawSurfaceInputsGUI();
357                     if ((m_Features & Features.LayerOptions) != 0)
358                         DrawLayerOptionsGUI();
359                 }
360             }
361         }
362
363         void DrawSurfaceInputsGUI()
364         {
365             UVBaseMapping uvBaseMapping = (UVBaseMapping)UVBase[m_LayerIndex].floatValue;
366             float X, Y, Z, W;
367
368             materialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap[m_LayerIndex], baseColor[m_LayerIndex]);
369
370             // TODO: does not work with multi-selection
371             MaterialId materialIdValue = materials[0].GetMaterialId();
372
373             if (materialIdValue == MaterialId.LitStandard ||
374                 materialIdValue == MaterialId.LitAniso ||
375                 materialIdValue == MaterialId.LitIridescence)
376             {
377                 materialEditor.ShaderProperty(metallic[m_LayerIndex], Styles.metallicText);
378             }
379
380             if (maskMap[m_LayerIndex].textureValue == null)
381             {
382                 materialEditor.ShaderProperty(smoothness[m_LayerIndex], Styles.smoothnessText);
383             }
384             else
385             {
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())
391                 {
392                     smoothnessRemapMin[m_LayerIndex].floatValue = remapMin;
393                     smoothnessRemapMax[m_LayerIndex].floatValue = remapMax;
394                 }
395
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())
401                 {
402                     aoRemapMin[m_LayerIndex].floatValue = aoMin;
403                     aoRemapMax[m_LayerIndex].floatValue = aoMax;
404                 }
405             }
406
407             materialEditor.TexturePropertySingleLine((materialIdValue == MaterialId.LitSpecular) ? Styles.maskMapSpecularText : Styles.maskMapSText, maskMap[m_LayerIndex]);
408
409             materialEditor.ShaderProperty(normalMapSpace[m_LayerIndex], Styles.normalMapSpaceText);
410
411             // Triplanar only work with tangent space normal
412             if ((NormalMapSpace)normalMapSpace[m_LayerIndex].floatValue == NormalMapSpace.ObjectSpace && ((UVBaseMapping)UVBase[m_LayerIndex].floatValue == UVBaseMapping.Triplanar))
413             {
414                 EditorGUILayout.HelpBox(Styles.normalMapSpaceWarning.text, MessageType.Error);
415             }
416
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)
421             {
422                 materialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap[m_LayerIndex], normalScale[m_LayerIndex]);
423                 materialEditor.TexturePropertySingleLine(Styles.bentNormalMapText, bentNormalMap[m_LayerIndex]);
424             }
425             else
426             {
427                 // No scaling in object space
428                 materialEditor.TexturePropertySingleLine(Styles.normalMapOSText, normalMapOS[m_LayerIndex]);
429                 materialEditor.TexturePropertySingleLine(Styles.bentNormalMapOSText, bentNormalMapOS[m_LayerIndex]);
430             }
431
432             DisplacementMode displaceMode = (DisplacementMode)displacementMode.floatValue;
433             if (displaceMode != DisplacementMode.None || (m_Features & Features.HeightMap) != 0)
434             {
435                 EditorGUI.BeginChangeCheck();
436                 materialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap[m_LayerIndex]);
437                 if (!heightMap[m_LayerIndex].hasMixedValue && heightMap[m_LayerIndex].textureValue != null && !displacementMode.hasMixedValue)
438                 {
439                     EditorGUI.indentLevel++;
440                     if (displaceMode == DisplacementMode.Pixel)
441                     {
442                         materialEditor.ShaderProperty(heightPoMAmplitude[m_LayerIndex], Styles.heightMapAmplitudeText);
443                     }
444                     else
445                     {
446                         materialEditor.ShaderProperty(heightParametrization[m_LayerIndex], Styles.heightMapParametrization);
447                         if (!heightParametrization[m_LayerIndex].hasMixedValue)
448                         {
449                             HeightmapParametrization parametrization = (HeightmapParametrization)heightParametrization[m_LayerIndex].floatValue;
450                             if (parametrization == HeightmapParametrization.MinMax)
451                             {
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);
460                             }
461                             else
462                             {
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);
468                             }
469
470                             materialEditor.ShaderProperty(heightOffset[m_LayerIndex], Styles.heightMapOffsetText);
471                         }
472                     }
473                     EditorGUI.indentLevel--;
474                 }
475
476                 // UI only updates intermediate values, this will update the values actually used by the shader.
477                 if (EditorGUI.EndChangeCheck())
478                 {
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);
482                 }
483             }
484
485             switch (materialIdValue)
486             {
487                 case MaterialId.LitSSS:
488                 case MaterialId.LitTranslucent:
489                     ShaderSSSAndTransmissionInputGUI();
490                     break;
491                 case MaterialId.LitStandard:
492                     // Nothing
493                     break;
494
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();
499                     break;
500                 case MaterialId.LitSpecular:
501                     ShaderSpecularColorInputGUI();
502                     break;
503                 case MaterialId.LitIridescence:
504                     ShaderIridescenceInputGUI();
505                     break;
506
507                 default:
508                     Debug.Assert(false, "Encountered an unsupported MaterialID.");
509                     break;
510             }
511
512             if (!isLayeredLit)
513             {
514                 ShaderClearCoatInputGUI();
515             }
516
517             EditorGUILayout.Space();
518
519             EditorGUI.BeginChangeCheck();
520             materialEditor.ShaderProperty(UVBase[m_LayerIndex], Styles.UVBaseMappingText);
521             uvBaseMapping = (UVBaseMapping)UVBase[m_LayerIndex].floatValue;
522
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;
527
528             UVMappingMask[m_LayerIndex].colorValue = new Color(X, Y, Z, W);
529
530             if ((uvBaseMapping == UVBaseMapping.Planar) || (uvBaseMapping == UVBaseMapping.Triplanar))
531             {
532                 materialEditor.ShaderProperty(TexWorldScale[m_LayerIndex], Styles.texWorldScaleText);
533             }
534             materialEditor.TextureScaleOffsetProperty(baseColorMap[m_LayerIndex]);
535             if (EditorGUI.EndChangeCheck())
536             {
537                 // Precompute.
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))
540                 {
541                     InvTilingScale[m_LayerIndex].floatValue = InvTilingScale[m_LayerIndex].floatValue / TexWorldScale[m_LayerIndex].floatValue;
542                 }
543             }
544         }
545
546         void ShaderSSSAndTransmissionInputGUI()
547         {
548             var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
549
550             if (hdPipeline == null)
551                 return;
552
553             using (var scope = new EditorGUI.ChangeCheckScope())
554             {
555                 using (new EditorGUILayout.HorizontalScope())
556                 {
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));
560
561                     // is it okay to do this every frame ?
562                     using (var changeScope = new EditorGUI.ChangeCheckScope())
563                     {
564                         diffusionProfile = (DiffusionProfileSettings)EditorGUILayout.ObjectField(Styles.diffusionProfileText, diffusionProfile, typeof(DiffusionProfileSettings), false);
565                         if (changeScope.changed)
566                         {
567                             Vector4 newGuid = Vector4.zero;
568                             float    hash = 0;
569
570                             if (diffusionProfile != null)
571                             {
572                                 guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(diffusionProfile));
573                                 newGuid = HDUtils.ConvertGUIDToVector4(guid);
574                                 hash = HDShadowUtils.Asfloat(diffusionProfile.profile.hash);
575                             }
576
577                             // encode back GUID and it's hash
578                             diffusionProfileAsset[m_LayerIndex].vectorValue = newGuid;
579                             diffusionProfileHash[m_LayerIndex].floatValue = hash;
580                         }
581                     }
582                 }
583             }
584
585             // TODO: does not work with multi-selection
586             if ((int)materialID.floatValue == (int)MaterialId.LitSSS && materials[0].GetSurfaceType() != SurfaceType.Transparent)
587             {
588                 materialEditor.ShaderProperty(subsurfaceMask[m_LayerIndex], Styles.subsurfaceMaskText);
589                 materialEditor.TexturePropertySingleLine(Styles.subsurfaceMaskMapText, subsurfaceMaskMap[m_LayerIndex]);
590             }
591
592             if ((int)materialID.floatValue == (int)MaterialId.LitTranslucent ||
593                 ((int)materialID.floatValue == (int)MaterialId.LitSSS && transmissionEnable.floatValue > 0.0f))
594             {
595                 materialEditor.TexturePropertySingleLine(Styles.thicknessMapText, thicknessMap[m_LayerIndex]);
596                 if (thicknessMap[m_LayerIndex].textureValue != null)
597                 {
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())
603                     {
604                         thicknessRemap[m_LayerIndex].vectorValue = remap;
605                     }
606                 }
607                 else
608                 {
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);
611                 }
612             }
613         }
614
615         void ShaderAnisoInputGUI()
616         {
617             if ((NormalMapSpace)normalMapSpace[0].floatValue == NormalMapSpace.TangentSpace)
618             {
619                 materialEditor.TexturePropertySingleLine(Styles.tangentMapText, tangentMap);
620             }
621             else
622             {
623                 materialEditor.TexturePropertySingleLine(Styles.tangentMapOSText, tangentMapOS);
624             }
625             materialEditor.ShaderProperty(anisotropy, Styles.anisotropyText);
626             materialEditor.TexturePropertySingleLine(Styles.anisotropyMapText, anisotropyMap);
627         }
628
629         void ShaderSpecularColorInputGUI()
630         {
631             materialEditor.TexturePropertySingleLine(Styles.specularColorText, specularColorMap, specularColor);
632             EditorGUI.indentLevel++;
633             materialEditor.ShaderProperty(energyConservingSpecularColor, Styles.energyConservingSpecularColorText);
634             EditorGUI.indentLevel--;
635         }
636
637         void ShaderIridescenceInputGUI()
638         {
639             materialEditor.TexturePropertySingleLine(Styles.iridescenceMaskText, iridescenceMaskMap, iridescenceMask);
640
641             if (iridescenceThicknessMap.textureValue != null)
642             {
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())
649                 {
650                     iridescenceThicknessRemap.vectorValue = remap;
651                 }
652             }
653             else
654             {
655                 // Allow the user to set the constant value of thickness if no thickness map is provided.
656                 materialEditor.TexturePropertySingleLine(Styles.iridescenceThicknessMapText, iridescenceThicknessMap, iridescenceThickness);
657             }
658         }
659
660         void ShaderClearCoatInputGUI()
661         {
662             materialEditor.TexturePropertySingleLine(Styles.coatMaskText, coatMaskMap, coatMask);
663         }
664
665         void DrawLayerOptionsGUI()
666         {
667             EditorGUI.showMixedValue = layerCount.hasMixedValue;
668             EditorGUI.BeginChangeCheck();
669             int newLayerCount = EditorGUILayout.IntSlider(Styles.layerCountText, (int)layerCount.floatValue, 2, 4);
670             if (EditorGUI.EndChangeCheck())
671             {
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;
677             }
678
679             materialEditor.TexturePropertySingleLine(Styles.layerMapMaskText, layerMaskMap);
680
681             EditorGUI.indentLevel++;
682             materialEditor.ShaderProperty(UVBlendMask, Styles.UVBlendMaskText);
683             UVBaseMapping uvBlendMask = (UVBaseMapping)UVBlendMask.floatValue;
684
685             float X, Y, Z, W;
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;
690
691             UVMappingMaskBlendMask.colorValue = new Color(X, Y, Z, W);
692
693             if (((UVBaseMapping)UVBlendMask.floatValue == UVBaseMapping.Planar) ||
694                 ((UVBaseMapping)UVBlendMask.floatValue == UVBaseMapping.Triplanar))
695             {
696                 materialEditor.ShaderProperty(texWorldScaleBlendMask, Styles.layerTexWorldScaleText);
697             }
698             materialEditor.TextureScaleOffsetProperty(layerMaskMap);
699             EditorGUI.indentLevel--;
700
701             materialEditor.ShaderProperty(vertexColorMode, Styles.vertexColorModeText);
702
703             EditorGUI.BeginChangeCheck();
704             EditorGUI.showMixedValue = useMainLayerInfluence.hasMixedValue;
705             bool mainLayerModeInfluenceEnable = EditorGUILayout.Toggle(Styles.useMainLayerInfluenceModeText, useMainLayerInfluence.floatValue > 0.0f);
706             if (EditorGUI.EndChangeCheck())
707             {
708                 useMainLayerInfluence.floatValue = mainLayerModeInfluenceEnable ? 1.0f : 0.0f;
709             }
710
711             EditorGUI.BeginChangeCheck();
712             EditorGUI.showMixedValue = useHeightBasedBlend.hasMixedValue;
713             m_UseHeightBasedBlend = EditorGUILayout.Toggle(Styles.useHeightBasedBlendText, useHeightBasedBlend.floatValue > 0.0f);
714             if (EditorGUI.EndChangeCheck())
715             {
716                 useHeightBasedBlend.floatValue = m_UseHeightBasedBlend ? 1.0f : 0.0f;
717             }
718
719             if (m_UseHeightBasedBlend)
720             {
721                 EditorGUI.indentLevel++;
722                 materialEditor.ShaderProperty(heightTransition, Styles.heightTransition);
723                 EditorGUI.indentLevel--;
724             }
725
726             materialEditor.ShaderProperty(objectScaleAffectTile, mainLayerModeInfluenceEnable ? Styles.objectScaleAffectTileText2 : Styles.objectScaleAffectTileText);
727         }
728     }
729 }