internal static void DoSmoothness(MaterialEditor materialEditor, Material material, MaterialProperty smoothness, MaterialProperty smoothnessMapChannel, string[] smoothnessChannelNames) { EditorGUI.indentLevel += 2; materialEditor.ShaderProperty(smoothness, Styles.smoothnessText); if (smoothnessMapChannel != null) // smoothness channel { var opaque = IsOpaque(material); EditorGUI.indentLevel++; EditorGUI.showMixedValue = smoothnessMapChannel.hasMixedValue; if (opaque) { MaterialEditor.BeginProperty(smoothnessMapChannel); EditorGUI.BeginChangeCheck(); var smoothnessSource = (int)smoothnessMapChannel.floatValue; smoothnessSource = EditorGUILayout.Popup(Styles.smoothnessMapChannelText, smoothnessSource, smoothnessChannelNames); if (EditorGUI.EndChangeCheck()) { smoothnessMapChannel.floatValue = smoothnessSource; } MaterialEditor.EndProperty(); } else { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.Popup(Styles.smoothnessMapChannelText, 0, smoothnessChannelNames); EditorGUI.EndDisabledGroup(); } EditorGUI.showMixedValue = false; EditorGUI.indentLevel--; } EditorGUI.indentLevel -= 2; }
private void DrawDelayedFloatProperty(MaterialProperty prop, GUIContent content) { MaterialEditor.BeginProperty(prop); Rect position = EditorGUILayout.GetControlRect(); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; float newValue = EditorGUI.DelayedFloatField(position, content, prop.floatValue); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { prop.floatValue = newValue; } MaterialEditor.EndProperty(); }
public static void OnGUI(MaterialEditor materialEditor, MaterialProperty diffusionProfileAsset, MaterialProperty diffusionProfileHash, int profileIndex, string displayName = "Diffusion Profile") { MaterialEditor.BeginProperty(diffusionProfileAsset); MaterialEditor.BeginProperty(diffusionProfileHash); // We can't cache these fields because of several edge cases like undo/redo or pressing escape in the object picker string guid = HDUtils.ConvertVector4ToGUID(diffusionProfileAsset.vectorValue); DiffusionProfileSettings diffusionProfile = AssetDatabase.LoadAssetAtPath <DiffusionProfileSettings>(AssetDatabase.GUIDToAssetPath(guid)); // is it okay to do this every frame ? EditorGUI.BeginChangeCheck(); diffusionProfile = (DiffusionProfileSettings)EditorGUILayout.ObjectField(displayName, diffusionProfile, typeof(DiffusionProfileSettings), false); if (EditorGUI.EndChangeCheck()) { Vector4 newGuid = Vector4.zero; float hash = 0; if (diffusionProfile != null) { guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(diffusionProfile)); newGuid = HDUtils.ConvertGUIDToVector4(guid); hash = HDShadowUtils.Asfloat(diffusionProfile.profile.hash); } // encode back GUID and it's hash diffusionProfileAsset.vectorValue = newGuid; diffusionProfileHash.floatValue = hash; // Update external reference. foreach (var target in materialEditor.targets) { MaterialExternalReferences matExternalRefs = MaterialExternalReferences.GetMaterialExternalReferences(target as Material); matExternalRefs.SetDiffusionProfileReference(profileIndex, diffusionProfile); } } MaterialEditor.EndProperty(); MaterialEditor.EndProperty(); DrawDiffusionProfileWarning(diffusionProfile); }
/// <summary> /// Renders the properties in the block. /// </summary> protected override void OnGUIOpen() { materialEditor.PopupShaderProperty(m_AxF_BRDFType, Styles.BRDFTypeText, AxfBrdfTypeNames); // Extract flag: uint flags = (uint)m_Flags.floatValue; ExtractFlags(flags, out bool anisotropy, out bool clearcoat, out bool clearcoatRefraction, out bool useHeightMap, out bool brdfColorDiagonalClamp, out bool honorMinRoughness); switch ((AxfBrdfType)m_AxF_BRDFType.floatValue) { case AxfBrdfType.SVBRDF: { EditorGUILayout.Space(); ++EditorGUI.indentLevel; // Read as compact flags //uint flags = (uint)m_Flags.floatValue; uint BRDFType = (uint)m_SVBRDF_BRDFType.floatValue; uint BRDFVariants = (uint)m_SVBRDF_BRDFVariants.floatValue; SvbrdfDiffuseType diffuseType = (SvbrdfDiffuseType)(BRDFType & 0x1); SvbrdfSpecularType specularType = (SvbrdfSpecularType)((BRDFType >> 1) & 0x7); SvbrdfFresnelVariant fresnelVariant = (SvbrdfFresnelVariant)(BRDFVariants & 0x3); SvbrdfSpecularVariantWard wardVariant = (SvbrdfSpecularVariantWard)((BRDFVariants >> 2) & 0x3); SvbrdfSpecularVariantBlinn blinnVariant = (SvbrdfSpecularVariantBlinn)((BRDFVariants >> 4) & 0x3); // Expand as user-friendly UI EditorGUILayout.LabelField("BRDF Variants", EditorStyles.boldLabel); MaterialEditor.BeginProperty(m_SVBRDF_BRDFType); diffuseType = (SvbrdfDiffuseType)EditorGUILayout.Popup("Diffuse Type", (int)diffuseType, SvbrdfDiffuseTypeNames); specularType = (SvbrdfSpecularType)EditorGUILayout.Popup("Specular Type", (int)specularType, SvbrdfSpecularTypeNames); MaterialEditor.EndProperty(); MaterialEditor.BeginProperty(m_SVBRDF_BRDFVariants); if (specularType == SvbrdfSpecularType.WARD) { fresnelVariant = (SvbrdfFresnelVariant)EditorGUILayout.Popup("Fresnel Variant", (int)fresnelVariant, SvbrdfFresnelVariantNames); wardVariant = (SvbrdfSpecularVariantWard)EditorGUILayout.Popup("Ward Variant", (int)wardVariant, SvbrdfSpecularVariantWardNames); } else if (specularType == SvbrdfSpecularType.BLINN_PHONG) { blinnVariant = (SvbrdfSpecularVariantBlinn)EditorGUILayout.Popup("Blinn Variant", (int)blinnVariant, SvbrdfSpecularVariantBlinnNames); } MaterialEditor.EndProperty(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Parameters and Maps", EditorStyles.boldLabel); // Regular maps DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text); materialEditor.TexturePropertySingleLine(Styles.diffuseColorMapText, m_DiffuseColorMap, m_DiffuseColorMapST); materialEditor.TexturePropertySingleLine(Styles.specularColorMapText, m_SpecularColorMap, m_SpecularColorMapST); materialEditor.TexturePropertySingleLine(Styles.specularLobeMapText, m_SpecularLobeMap, m_SpecularLobeMapST); materialEditor.ShaderProperty(m_SpecularLobeMapScale, Styles.specularLobeMapScaleText); EditorGUILayout.Space(); DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text); materialEditor.TexturePropertySingleLine(Styles.fresnelMapText, m_FresnelMap, m_FresnelMapST); materialEditor.TexturePropertySingleLine(Styles.normalMapText, m_NormalMap, m_NormalMapST); // Alpha materialEditor.TexturePropertySingleLine(Styles.alphaMapText, m_AlphaMap, m_AlphaMapST); // Displacement //TODO: unsupported for now //useHeightMap = EditorGUILayout.Toggle("Enable Displacement Map", useHeightMap); useHeightMap = false; if (useHeightMap) { ++EditorGUI.indentLevel; DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text); materialEditor.TexturePropertySingleLine(Styles.heightMapText, m_HeightMap, m_HeightMapST); materialEditor.ShaderProperty(m_SVBRDF_HeightMapMaxMM, "Max Displacement (mm)"); --EditorGUI.indentLevel; } // Anisotropy MaterialEditor.BeginProperty(m_Flags); anisotropy = EditorGUILayout.Toggle("Is Anisotropic", anisotropy); MaterialEditor.EndProperty(); if (anisotropy) { ++EditorGUI.indentLevel; DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text); materialEditor.TexturePropertySingleLine(Styles.anisoRotationMapText, m_AnisoRotationMap, m_AnisoRotationMapST); --EditorGUI.indentLevel; } // Clearcoat MaterialEditor.BeginProperty(m_Flags); clearcoat = EditorGUILayout.Toggle("Enable Clearcoat", clearcoat); MaterialEditor.EndProperty(); if (clearcoat) { ++EditorGUI.indentLevel; DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text); materialEditor.TexturePropertySingleLine(Styles.clearcoatColorMapText, m_ClearcoatColorMap, m_ClearcoatColorMapST); materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap, m_ClearcoatNormalMapST); MaterialEditor.BeginProperty(m_Flags); clearcoatRefraction = EditorGUILayout.Toggle("Enable Refraction", clearcoatRefraction); MaterialEditor.EndProperty(); // The IOR map is always required for the coat F0, while in the CAR_PAINT model, the IOR // is given by a scalar value. DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text); materialEditor.TexturePropertySingleLine(Styles.clearcoatIORMapText, m_ClearcoatIORMap, m_ClearcoatIORMapST); --EditorGUI.indentLevel; } BRDFType = 0; BRDFType |= (uint)diffuseType; BRDFType |= ((uint)specularType) << 1; BRDFVariants = 0; BRDFVariants |= (uint)fresnelVariant; BRDFVariants |= ((uint)wardVariant) << 2; BRDFVariants |= ((uint)blinnVariant) << 4; m_SVBRDF_BRDFType.floatValue = (float)BRDFType; m_SVBRDF_BRDFVariants.floatValue = (float)BRDFVariants; --EditorGUI.indentLevel; break; } case AxfBrdfType.CAR_PAINT: { EditorGUILayout.Space(); ++EditorGUI.indentLevel; // Expand as user-friendly UI // Regular maps materialEditor.TexturePropertySingleLine(Styles.BRDFColorMapText, m_CarPaint2_BRDFColorMap); materialEditor.ShaderProperty(m_CarPaint2_BRDFColorMapScale, Styles.BRDFColorMapScaleText); MaterialEditor.BeginProperty(m_Flags); brdfColorDiagonalClamp = EditorGUILayout.Toggle("BRDF Color Table Diagonal Clamping", brdfColorDiagonalClamp); MaterialEditor.EndProperty(); if (brdfColorDiagonalClamp) { ++EditorGUI.indentLevel; MaterialEditor.BeginProperty(m_CarPaint2_BRDFColorMapUVScale); m_CarPaint2_BRDFColorMapUVScale.vectorValue = EditorGUILayout.Vector2Field(Styles.BRDFColorMapUVScaleText, m_CarPaint2_BRDFColorMapUVScale.vectorValue); MaterialEditor.EndProperty(); --EditorGUI.indentLevel; } DrawRightJustifiedHeader(Styles.BTFFlakesTilingText.text); materialEditor.TexturePropertySingleLine(Styles.BTFFlakesMapText, m_CarPaint2_BTFFlakeMap, m_CarPaint2_BTFFlakeMapST); //materialEditor.TexturePropertySingleLine(Styles.BTFFlakesMapText, m_CarPaint2_BTFFlakeMap); //m_CarPaint2_BTFFlakeMapST.vectorValue = EditorGUILayout.Vector4Field(Styles.BTFFlakesTilingText, m_CarPaint2_BTFFlakeMapST.vectorValue); //EditorGUILayout.LabelField( "Texture Dimension = " + m_CarPaint_BTFFlakesMap_sRGB.textureDimension ); //EditorGUILayout.LabelField( "Texture Format = " + m_CarPaint_BTFFlakesMap_sRGB.textureValue. ); materialEditor.ShaderProperty(m_CarPaint2_BTFFlakeMapScale, Styles.BTFFlakesMapScaleText); materialEditor.TexturePropertySingleLine(Styles.thetaFI_sliceLUTMapText, m_CarPaint2_FlakeThetaFISliceLUTMap); materialEditor.ShaderProperty(m_CarPaint2_FixedColorThetaHForIndirectLight, Styles.CarPaintFixedColorThetaHForIndirectLightText); materialEditor.ShaderProperty(m_CarPaint2_FixedFlakesThetaHForIndirectLight, Styles.CarPaintFixedFlakesThetaHForIndirectLightText); //m_CarPaint2_FlakeMaxThetaI = FindProperty(m_CarPaint2_FlakeMaxThetaIText); //m_CarPaint2_FlakeNumThetaF = FindProperty(m_CarPaint2_FlakeNumThetaFText); //m_CarPaint2_FlakeNumThetaI = FindProperty(m_CarPaint2_FlakeNumThetaIText); materialEditor.ShaderProperty(m_CarPaint2_CTDiffuse, Styles.CarPaintCTDiffuseText); materialEditor.IntSliderShaderProperty(m_CarPaint2_LobeCount, 0, 3, Styles.CarPaintLobeCountText); materialEditor.Vector3ShaderProperty(m_CarPaint2_CTF0s, Styles.CarPaintCTF0sText); materialEditor.Vector3ShaderProperty(m_CarPaint2_CTCoeffs, Styles.CarPaintCTCoeffsText); materialEditor.Vector3ShaderProperty(m_CarPaint2_CTSpreads, Styles.CarPaintCTSpreadsText); if (useHeightMap) { materialEditor.ShaderProperty(m_SVBRDF_HeightMapMaxMM, "Max Displacement (mm)"); } // Clearcoat MaterialEditor.BeginProperty(m_Flags); clearcoat = EditorGUILayout.Toggle("Enable Clearcoat", clearcoat); MaterialEditor.EndProperty(); if (clearcoat) { ++EditorGUI.indentLevel; //materialEditor.TexturePropertySingleLine( Styles.clearcoatColorMapText, m_ClearcoatColorMap ); DrawRightJustifiedHeader(Styles.clearcoatNormalMapTilingText.text); materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap, m_ClearcoatNormalMapST); //materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap); //m_ClearcoatNormalMapST.vectorValue = EditorGUILayout.Vector4Field(Styles.clearcoatNormalMapTilingText, m_ClearcoatNormalMapST.vectorValue); //materialEditor.TexturePropertySingleLine( Styles.clearcoatIORMapText, m_ClearcoatIORMap ); materialEditor.ShaderProperty(m_CarPaint2_ClearcoatIOR, Styles.CarPaintIORText); MaterialEditor.BeginProperty(m_Flags); clearcoatRefraction = EditorGUILayout.Toggle("Enable Refraction", clearcoatRefraction); MaterialEditor.EndProperty(); --EditorGUI.indentLevel; } --EditorGUI.indentLevel; break; } } // Finally write back flags: flags = GenFlags(anisotropy, clearcoat, clearcoatRefraction, useHeightMap, brdfColorDiagonalClamp, honorMinRoughness); m_Flags.floatValue = (float)flags; }//DrawAxfSurfaceOptionsGUI
internal static void DoEmissiveIntensityGUI(MaterialEditor materialEditor, MaterialProperty emissiveIntensity, MaterialProperty emissiveIntensityUnit) { MaterialEditor.BeginProperty(emissiveIntensity); MaterialEditor.BeginProperty(emissiveIntensityUnit); bool unitIsMixed = emissiveIntensityUnit.hasMixedValue; bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue; float indent = 15 * EditorGUI.indentLevel; const int k_ValueUnitSeparator = 2; const int k_UnitWidth = 100; Rect valueRect = EditorGUILayout.GetControlRect(); valueRect.width += indent - k_ValueUnitSeparator - k_UnitWidth; Rect unitRect = valueRect; unitRect.x += valueRect.width - indent + k_ValueUnitSeparator; unitRect.width = k_UnitWidth + .5f; { EditorGUI.showMixedValue = intensityIsMixed; EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unitIsMixed) { using (new EditorGUI.DisabledScope(true)) materialEditor.ShaderProperty(valueRect, emissiveIntensity, Styles.emissiveIntensityText); } else { if (!intensityIsMixed && unit == EmissiveIntensityUnit.EV100) { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUI.FloatField(valueRect, Styles.emissiveIntensityText, evValue); evValue = Mathf.Clamp(evValue, 0, s_MaxEvValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } else { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(valueRect, emissiveIntensity, Styles.emissiveIntensityText); if (EditorGUI.EndChangeCheck()) { emissiveIntensity.floatValue = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue); } } } EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue; EditorGUI.BeginChangeCheck(); var newUnit = (EmissiveIntensityUnit)EditorGUI.EnumPopup(unitRect, unit); if (EditorGUI.EndChangeCheck()) { emissiveIntensityUnit.floatValue = (float)newUnit; } } EditorGUI.showMixedValue = false; MaterialEditor.EndProperty(); MaterialEditor.EndProperty(); }
/// <summary> /// Renders the properties in the block. /// </summary> protected override void OnGUIOpen() { var material = materials[0]; bool affectAlbedo = material.HasProperty(kAffectAlbedo) && material.GetFloat(kAffectAlbedo) == 1.0f; bool affectNormal = material.HasProperty(kAffectNormal) && material.GetFloat(kAffectNormal) == 1.0f; bool affectMetal = material.HasProperty(kAffectMetal) && material.GetFloat(kAffectMetal) == 1.0f; bool affectSmoothness = material.HasProperty(kAffectSmoothness) && material.GetFloat(kAffectSmoothness) == 1.0f; bool affectAO = material.HasProperty(kAffectAO) && material.GetFloat(kAffectAO) == 1.0f; bool affectEmission = material.HasProperty(kAffectEmission) && material.GetFloat(kAffectEmission) == 1.0f; bool affectMaskmap = affectMetal || affectAO || affectSmoothness; bool perChannelMask = false; HDRenderPipelineAsset hdrp = HDRenderPipeline.currentAsset; if (hdrp != null) { perChannelMask = hdrp.currentPlatformRenderPipelineSettings.decalSettings.perChannelMask; } bool allMaskMap = materials.All(m => m.GetTexture(kMaskMap)); if (affectAlbedo) { materialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap, baseColor); } else { MaterialEditor.BeginProperty(baseColor); Color color = baseColor.colorValue; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = baseColor.hasMixedValue; color.a = EditorGUILayout.Slider(Styles.baseOpacityText, color.a, 0.0f, 1.0f); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { baseColor.colorValue = color; } MaterialEditor.EndProperty(); } using (new EditorGUI.DisabledScope(!affectNormal)) { materialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap); if (materials.All(m => m.GetTexture(kNormalMap))) { EditorGUI.indentLevel++; materialEditor.PopupShaderProperty(normalBlendSrc, Styles.normalOpacityChannelText, allMaskMap ? blendSourceNames : blendSourceNamesNoMap); EditorGUI.indentLevel--; } } using (new EditorGUI.DisabledScope(!affectMaskmap)) { materialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap); EditorGUI.indentLevel++; if (allMaskMap) { if (perChannelMask) { using (new EditorGUI.DisabledScope(!affectMetal)) materialEditor.MinMaxShaderProperty(metallicRemapMin, metallicRemapMax, 0.0f, 1.0f, Styles.metallicRemappingText); using (new EditorGUI.DisabledScope(!affectAO)) materialEditor.MinMaxShaderProperty(AORemapMin, AORemapMax, 0.0f, 1.0f, Styles.aoRemappingText); } using (new EditorGUI.DisabledScope(!affectSmoothness)) materialEditor.MinMaxShaderProperty(smoothnessRemapMin, smoothnessRemapMax, 0.0f, 1.0f, Styles.smoothnessRemappingText); } else { if (perChannelMask) { using (new EditorGUI.DisabledScope(!affectMetal)) materialEditor.ShaderProperty(metallic, Styles.metallicText); using (new EditorGUI.DisabledScope(!affectAO)) materialEditor.ShaderProperty(AO, Styles.aoText); } using (new EditorGUI.DisabledScope(!affectSmoothness)) materialEditor.ShaderProperty(smoothness, Styles.smoothnessText); } materialEditor.PopupShaderProperty(maskBlendSrc, Styles.maskOpacityChannelText, allMaskMap ? blendSourceNames : blendSourceNamesNoMap); EditorGUI.indentLevel--; } bool useBlueScale = (affectMaskmap && maskBlendSrc.floatValue == (float)BlendSource.MaskMapBlue) || (affectNormal && normalBlendSrc.floatValue == (float)BlendSource.MaskMapBlue); using (new EditorGUI.DisabledScope(!useBlueScale)) materialEditor.ShaderProperty(maskMapBlueScale, allMaskMap ? Styles.maskMapBlueScaleText : Styles.opacityBlueScaleText); materialEditor.ShaderProperty(decalBlend, Styles.decalBlendText); using (new EditorGUI.DisabledScope(!affectEmission)) { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissionIntensityText); bool updateEmissiveColor = EditorGUI.EndChangeCheck(); if (useEmissiveIntensity.floatValue == 0.0f) { if (updateEmissiveColor) { emissiveColorHDR.colorValue = emissiveColor.colorValue; } EditorGUI.BeginChangeCheck(); EmissionUIBlock.DoEmissiveTextureProperty(materialEditor, emissiveColorMap, emissiveColorHDR); if (EditorGUI.EndChangeCheck()) { emissiveColor.colorValue = emissiveColorHDR.colorValue; } } else { if (updateEmissiveColor) { EmissionUIBlock.UpdateEmissiveColorLDRAndIntensityFromEmissiveColor(emissiveColorLDR, emissiveIntensity, emissiveColor); } EmissionUIBlock.DoEmissiveTextureProperty(materialEditor, emissiveColorMap, emissiveColorLDR); EmissionUIBlock.DoEmissiveIntensityGUI(materialEditor, emissiveIntensity, emissiveIntensityUnit); } materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText); } }