11using System ;
2- using System . Collections . Generic ;
32using UnityEngine ;
43using UnityEngine . Rendering . HighDefinition ;
54using System . Linq ;
6- using UnityEngine . Rendering ;
75
86// Include material common properties names
97using static UnityEngine . Rendering . HighDefinition . HDMaterialProperties ;
10- // We share the name of the properties in the UI to avoid duplication
11- using static UnityEditor . Rendering . HighDefinition . DecalSurfaceOptionsUIBlock . Styles ;
128
139namespace UnityEditor . Rendering . HighDefinition
1410{
@@ -224,13 +220,7 @@ void DrawDecalGUI()
224220 if ( materials . All ( m => m . GetTexture ( kNormalMap ) ) )
225221 {
226222 EditorGUI . indentLevel ++ ;
227-
228- EditorGUI . BeginChangeCheck ( ) ;
229- var normalBlendSrcValue = ( int ) normalBlendSrc . floatValue ;
230- normalBlendSrcValue = EditorGUILayout . Popup ( Styles . normalOpacityChannelText , normalBlendSrcValue , allMaskMap ? blendSourceNames : blendSourceNamesNoMap ) ;
231- if ( EditorGUI . EndChangeCheck ( ) )
232- normalBlendSrc . floatValue = normalBlendSrcValue ;
233-
223+ PopupShaderProperty ( normalBlendSrc , Styles . normalOpacityChannelText , allMaskMap ? blendSourceNames : blendSourceNamesNoMap ) ;
234224 EditorGUI . indentLevel -- ;
235225 }
236226
@@ -240,36 +230,11 @@ void DrawDecalGUI()
240230 {
241231 if ( perChannelMask )
242232 {
243- float MetalRemapMinValue = metallicRemapMin . floatValue ;
244- float MetalRemapMaxValue = metallicRemapMax . floatValue ;
245- EditorGUI . BeginChangeCheck ( ) ;
246- EditorGUILayout . MinMaxSlider ( Styles . metallicRemappingText , ref MetalRemapMinValue , ref MetalRemapMaxValue , 0.0f , 1.0f ) ;
247- if ( EditorGUI . EndChangeCheck ( ) )
248- {
249- metallicRemapMin . floatValue = MetalRemapMinValue ;
250- metallicRemapMax . floatValue = MetalRemapMaxValue ;
251- }
252-
253- float AORemapMinValue = AORemapMin . floatValue ;
254- float AORemapMaxValue = AORemapMax . floatValue ;
255- EditorGUI . BeginChangeCheck ( ) ;
256- EditorGUILayout . MinMaxSlider ( Styles . aoRemappingText , ref AORemapMinValue , ref AORemapMaxValue , 0.0f , 1.0f ) ;
257- if ( EditorGUI . EndChangeCheck ( ) )
258- {
259- AORemapMin . floatValue = AORemapMinValue ;
260- AORemapMax . floatValue = AORemapMaxValue ;
261- }
233+ MinMaxShaderProperty ( metallicRemapMin , metallicRemapMax , 0.0f , 1.0f , Styles . metallicRemappingText ) ;
234+ MinMaxShaderProperty ( AORemapMin , AORemapMax , 0.0f , 1.0f , Styles . aoRemappingText ) ;
262235 }
263236
264- float smoothnessRemapMinValue = smoothnessRemapMin . floatValue ;
265- float smoothnessRemapMaxValue = smoothnessRemapMax . floatValue ;
266- EditorGUI . BeginChangeCheck ( ) ;
267- EditorGUILayout . MinMaxSlider ( Styles . smoothnessRemappingText , ref smoothnessRemapMinValue , ref smoothnessRemapMaxValue , 0.0f , 1.0f ) ;
268- if ( EditorGUI . EndChangeCheck ( ) )
269- {
270- smoothnessRemapMin . floatValue = smoothnessRemapMinValue ;
271- smoothnessRemapMax . floatValue = smoothnessRemapMaxValue ;
272- }
237+ MinMaxShaderProperty ( smoothnessRemapMin , smoothnessRemapMax , 0.0f , 1.0f , Styles . smoothnessRemappingText ) ;
273238 }
274239 else
275240 {
@@ -281,66 +246,34 @@ void DrawDecalGUI()
281246 materialEditor . ShaderProperty ( smoothness , Styles . smoothnessText ) ;
282247 }
283248
284- EditorGUI . BeginChangeCheck ( ) ;
285- var maskBlendSrcValue = ( int ) maskBlendSrc . floatValue ;
286- maskBlendSrcValue = EditorGUILayout . Popup ( Styles . normalOpacityChannelText , maskBlendSrcValue , allMaskMap ? blendSourceNames : blendSourceNamesNoMap ) ;
287- if ( EditorGUI . EndChangeCheck ( ) )
288- maskBlendSrc . floatValue = maskBlendSrcValue ;
249+ PopupShaderProperty ( maskBlendSrc , Styles . normalOpacityChannelText , allMaskMap ? blendSourceNames : blendSourceNamesNoMap ) ;
289250
290251 EditorGUI . indentLevel -- ;
291252
292253 materialEditor . ShaderProperty ( maskMapBlueScale , allMaskMap ? Styles . maskMapBlueScaleText : Styles . opacityBlueScaleText ) ;
293-
294-
295254 materialEditor . ShaderProperty ( decalBlend , Styles . decalBlendText ) ;
296- //if (affectEmission.floatValue == 1.0f) // Always show emissive part
297- using ( var scope = new EditorGUI . ChangeCheckScope ( ) )
298- {
299- materialEditor . ShaderProperty ( useEmissiveIntensity , Styles . useEmissionIntensityText ) ;
300255
301- if ( useEmissiveIntensity . floatValue == 1.0f )
302- {
303- materialEditor . TexturePropertySingleLine ( Styles . emissionMapText , emissiveColorMap , emissiveColorLDR ) ;
304- using ( new EditorGUILayout . HorizontalScope ( ) )
305- {
306- EmissiveIntensityUnit unit = ( EmissiveIntensityUnit ) emissiveIntensityUnit . floatValue ;
307-
308- if ( unit == EmissiveIntensityUnit . Nits )
309- materialEditor . ShaderProperty ( emissiveIntensity , Styles . emissiveIntensityText ) ;
310- else
311- {
312- float evValue = LightUtils . ConvertLuminanceToEv ( emissiveIntensity . floatValue ) ;
313- evValue = EditorGUILayout . FloatField ( Styles . emissiveIntensityText , evValue ) ;
314- emissiveIntensity . floatValue = LightUtils . ConvertEvToLuminance ( evValue ) ;
315- }
316- emissiveIntensityUnit . floatValue = ( float ) ( EmissiveIntensityUnit ) EditorGUILayout . EnumPopup ( unit ) ;
317- }
318- }
319- else
320- {
321- materialEditor . TexturePropertySingleLine ( Styles . emissionMapText , emissiveColorMap , emissiveColorHDR ) ;
322- }
323-
324- materialEditor . ShaderProperty ( emissiveExposureWeight , Styles . emissiveExposureWeightText ) ;
256+ EditorGUI . BeginChangeCheck ( ) ;
257+ materialEditor . ShaderProperty ( useEmissiveIntensity , Styles . useEmissionIntensityText ) ;
258+ bool updateEmissiveColor = EditorGUI . EndChangeCheck ( ) ;
325259
326- // If anything change, update the emission value
327- if ( scope . changed )
328- {
329- if ( useEmissiveIntensity . floatValue == 1.0f )
330- {
331- materialEditor . serializedObject . ApplyModifiedProperties ( ) ;
332- foreach ( Material target in materials )
333- {
334- target . UpdateEmissiveColorFromIntensityAndEmissiveColorLDR ( ) ;
335- }
336- materialEditor . serializedObject . Update ( ) ;
337- }
338- else
339- {
340- emissiveColor . colorValue = emissiveColorHDR . colorValue ;
341- }
342- }
260+ if ( useEmissiveIntensity . floatValue == 0.0f )
261+ {
262+ EditorGUI . BeginChangeCheck ( ) ;
263+ materialEditor . TexturePropertySingleLine ( Styles . emissionMapText , emissiveColorMap , emissiveColorHDR ) ;
264+ if ( EditorGUI . EndChangeCheck ( ) || updateEmissiveColor )
265+ emissiveColor . colorValue = emissiveColorHDR . colorValue ;
266+ }
267+ else
268+ {
269+ EditorGUI . BeginChangeCheck ( ) ;
270+ materialEditor . TexturePropertySingleLine ( Styles . emissionMapText , emissiveColorMap , emissiveColorLDR ) ;
271+ EmissionUIBlock . DoEmissiveIntensityGUI ( materialEditor , emissiveIntensity , emissiveIntensityUnit ) ;
272+ if ( EditorGUI . EndChangeCheck ( ) || updateEmissiveColor )
273+ EmissionUIBlock . UpdateEmissiveColorFromIntensityAndEmissiveColorLDR ( materialEditor , materials ) ;
343274 }
275+
276+ materialEditor . ShaderProperty ( emissiveExposureWeight , Styles . emissiveExposureWeightText ) ;
344277 }
345278 }
346279}
0 commit comments