static void SetMaterialKeywords(Material material) { // Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation // (MaterialProperty value might come from renderer material property block) bool isSpecularWorkFlow = (WorkflowMode)material.GetFloat("_WorkflowMode") == WorkflowMode.Specular; bool hasGlossMap = false; if (isSpecularWorkFlow) { hasGlossMap = material.GetTexture("_SpecGlossMap"); } else { hasGlossMap = material.GetTexture("_MetallicGlossMap"); } LightweightShaderHelper.SetKeyword(material, "_SPECULAR_SETUP", isSpecularWorkFlow); LightweightShaderHelper.SetKeyword(material, "_METALLIC_SETUP", !isSpecularWorkFlow); LightweightShaderHelper.SetKeyword(material, "_METALLICSPECGLOSSMAP", hasGlossMap); LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap && isSpecularWorkFlow); LightweightShaderHelper.SetKeyword(material, "_METALLICGLOSSMAP", hasGlossMap && !isSpecularWorkFlow); LightweightShaderHelper.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap")); LightweightShaderHelper.SetKeyword(material, "_SPECULARHIGHLIGHTS_OFF", material.GetFloat("_SpecularHighlights") == 0.0f); LightweightShaderHelper.SetKeyword(material, "_GLOSSYREFLECTIONS_OFF", material.GetFloat("_GlossyReflections") == 0.0f); LightweightShaderHelper.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap")); LightweightShaderHelper.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap")); LightweightShaderHelper.SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap")); // A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect // or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color. // The fixup routine makes sure that the material is in the correct state if/when changes are made to the mode or color. MaterialEditor.FixupEmissiveFlag(material); bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0; LightweightShaderHelper.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled); if (material.HasProperty("_SmoothnessTextureChannel")) { LightweightShaderHelper.SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", GetSmoothnessMapChannel(material) == SmoothnessMapChannel.AlbedoAlpha); } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { Material material = materialEditor.target as Material; m_MaterialEditor = materialEditor; FindMaterialProperties(properties); int modeValue = (int)blendModeProp.floatValue; EditorGUI.BeginChangeCheck(); modeValue = EditorGUILayout.Popup(Styles.renderingModeLabel, modeValue, Styles.blendNames); if (EditorGUI.EndChangeCheck()) { blendModeProp.floatValue = modeValue; } GUIContent mainTexLabel = Styles.mainTexLabels[Math.Min(modeValue, 1)]; m_MaterialEditor.TexturePropertySingleLine(mainTexLabel, mainTexProp, mainColorProp); m_MaterialEditor.TextureScaleOffsetProperty(mainTexProp); if ((UpgradeBlendMode)modeValue == UpgradeBlendMode.Cutout) { m_MaterialEditor.RangeProperty(alphaCutoffProp, Styles.alphaCutoffLabel); } EditorGUILayout.Space(); EditorGUILayout.Space(); materialEditor.RenderQueueField(); LightweightShaderHelper.SetMaterialBlendMode(material); EditorGUILayout.Space(); EditorGUILayout.Space(); }