private static void SetMaterialKeywords(Material material, StandardShaderGUI.WorkflowMode workflowMode) { StandardShaderGUI.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap") || material.GetTexture("_DetailNormalMap")); if (workflowMode == StandardShaderGUI.WorkflowMode.Specular) { StandardShaderGUI.SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap")); } else { if (workflowMode == StandardShaderGUI.WorkflowMode.Metallic) { StandardShaderGUI.SetKeyword(material, "_METALLICGLOSSMAP", material.GetTexture("_MetallicGlossMap")); } } StandardShaderGUI.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap")); StandardShaderGUI.SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap")); bool flag = StandardShaderGUI.ShouldEmissionBeEnabled(material.GetColor("_EmissionColor")); StandardShaderGUI.SetKeyword(material, "_EMISSION", flag); MaterialGlobalIlluminationFlags materialGlobalIlluminationFlags = material.globalIlluminationFlags; if ((materialGlobalIlluminationFlags & (MaterialGlobalIlluminationFlags.RealtimeEmissive | MaterialGlobalIlluminationFlags.BakedEmissive)) != MaterialGlobalIlluminationFlags.None) { materialGlobalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; if (!flag) { materialGlobalIlluminationFlags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; } material.globalIlluminationFlags = materialGlobalIlluminationFlags; } }
private static void SetMaterialKeywords(Material material, StandardShaderGUI.WorkflowMode workflowMode) { StandardShaderGUI.SetKeyword(material, "_NORMALMAP", (bool)((UnityEngine.Object)material.GetTexture("_BumpMap")) || (bool)((UnityEngine.Object)material.GetTexture("_DetailNormalMap"))); if (workflowMode == StandardShaderGUI.WorkflowMode.Specular) { StandardShaderGUI.SetKeyword(material, "_SPECGLOSSMAP", (bool)((UnityEngine.Object)material.GetTexture("_SpecGlossMap"))); } else if (workflowMode == StandardShaderGUI.WorkflowMode.Metallic) { StandardShaderGUI.SetKeyword(material, "_METALLICGLOSSMAP", (bool)((UnityEngine.Object)material.GetTexture("_MetallicGlossMap"))); } StandardShaderGUI.SetKeyword(material, "_PARALLAXMAP", (bool)((UnityEngine.Object)material.GetTexture("_ParallaxMap"))); StandardShaderGUI.SetKeyword(material, "_DETAIL_MULX2", (bool)((UnityEngine.Object)material.GetTexture("_DetailAlbedoMap")) || (bool)((UnityEngine.Object)material.GetTexture("_DetailNormalMap"))); bool state = StandardShaderGUI.ShouldEmissionBeEnabled(material.GetColor("_EmissionColor")); StandardShaderGUI.SetKeyword(material, "_EMISSION", state); MaterialGlobalIlluminationFlags illuminationFlags1 = material.globalIlluminationFlags; if ((illuminationFlags1 & (MaterialGlobalIlluminationFlags.RealtimeEmissive | MaterialGlobalIlluminationFlags.BakedEmissive)) == MaterialGlobalIlluminationFlags.None) { return; } MaterialGlobalIlluminationFlags illuminationFlags2 = illuminationFlags1 & ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; if (!state) { illuminationFlags2 |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; } material.globalIlluminationFlags = illuminationFlags2; }
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { base.AssignNewShaderToMaterial(material, oldShader, newShader); if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/")) { return; } StandardShaderGUI.BlendMode blendMode = StandardShaderGUI.BlendMode.Opaque; if (oldShader.name.Contains("/Transparent/Cutout/")) { blendMode = StandardShaderGUI.BlendMode.Cutout; } else { if (oldShader.name.Contains("/Transparent/")) { blendMode = StandardShaderGUI.BlendMode.Fade; } } material.SetFloat("_Mode", (float)blendMode); this.DetermineWorkflow(ShaderUtil.GetMaterialProperties(new Material[] { material })); StandardShaderGUI.MaterialChanged(material, this.m_WorkflowMode); }
private static void SetMaterialKeywords(Material material, StandardShaderGUI.WorkflowMode workflowMode) { StandardShaderGUI.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap") || material.GetTexture("_DetailNormalMap")); if (workflowMode == StandardShaderGUI.WorkflowMode.Specular) { StandardShaderGUI.SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap")); } else if (workflowMode == StandardShaderGUI.WorkflowMode.Metallic) { StandardShaderGUI.SetKeyword(material, "_METALLICGLOSSMAP", material.GetTexture("_MetallicGlossMap")); } StandardShaderGUI.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap")); StandardShaderGUI.SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap")); bool flag = StandardShaderGUI.ShouldEmissionBeEnabled(material, material.GetColor("_EmissionColor")); StandardShaderGUI.SetKeyword(material, "_EMISSION", flag); if (material.HasProperty("_SmoothnessTextureChannel")) { StandardShaderGUI.SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", StandardShaderGUI.GetSmoothnessMapChannel(material) == StandardShaderGUI.SmoothnessMapChannel.AlbedoAlpha); } MaterialGlobalIlluminationFlags materialGlobalIlluminationFlags = material.globalIlluminationFlags; if ((materialGlobalIlluminationFlags & (MaterialGlobalIlluminationFlags.RealtimeEmissive | MaterialGlobalIlluminationFlags.BakedEmissive)) != MaterialGlobalIlluminationFlags.None) { materialGlobalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; if (!flag) { materialGlobalIlluminationFlags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; } material.globalIlluminationFlags = materialGlobalIlluminationFlags; } }
public void ShaderPropertiesGUI(Material material) { EditorGUIUtility.labelWidth = 0.0f; EditorGUI.BeginChangeCheck(); this.BlendModePopup(); GUILayout.Label(StandardShaderGUI.Styles.primaryMapsText, EditorStyles.boldLabel, new GUILayoutOption[0]); this.DoAlbedoArea(material); this.DoSpecularMetallicArea(); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.normalMapText, this.bumpMap, !((UnityEngine.Object) this.bumpMap.textureValue != (UnityEngine.Object)null) ? (MaterialProperty)null : this.bumpScale); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.heightMapText, this.heightMap, !((UnityEngine.Object) this.heightMap.textureValue != (UnityEngine.Object)null) ? (MaterialProperty)null : this.heigtMapScale); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.occlusionText, this.occlusionMap, !((UnityEngine.Object) this.occlusionMap.textureValue != (UnityEngine.Object)null) ? (MaterialProperty)null : this.occlusionStrength); this.DoEmissionArea(material); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.detailMaskText, this.detailMask); EditorGUI.BeginChangeCheck(); this.m_MaterialEditor.TextureScaleOffsetProperty(this.albedoMap); if (EditorGUI.EndChangeCheck()) { this.emissionMap.textureScaleAndOffset = this.albedoMap.textureScaleAndOffset; } EditorGUILayout.Space(); GUILayout.Label(StandardShaderGUI.Styles.secondaryMapsText, EditorStyles.boldLabel, new GUILayoutOption[0]); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.detailAlbedoText, this.detailAlbedoMap); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.detailNormalMapText, this.detailNormalMap, this.detailNormalMapScale); this.m_MaterialEditor.TextureScaleOffsetProperty(this.detailAlbedoMap); this.m_MaterialEditor.ShaderProperty(this.uvSetSecondary, StandardShaderGUI.Styles.uvSetLabel.text); if (!EditorGUI.EndChangeCheck()) { return; } foreach (Material target in this.blendMode.targets) { StandardShaderGUI.MaterialChanged(target, this.m_WorkflowMode); } }
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { if (material.HasProperty("_Emission")) { material.SetColor("_EmissionColor", material.GetColor("_Emission")); } base.AssignNewShaderToMaterial(material, oldShader, newShader); if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/")) { StandardShaderGUI.SetupMaterialWithBlendMode(material, (StandardShaderGUI.BlendMode)material.GetFloat("_Mode")); } else { StandardShaderGUI.BlendMode blendMode = StandardShaderGUI.BlendMode.Opaque; if (oldShader.name.Contains("/Transparent/Cutout/")) { blendMode = StandardShaderGUI.BlendMode.Cutout; } else if (oldShader.name.Contains("/Transparent/")) { blendMode = StandardShaderGUI.BlendMode.Fade; } material.SetFloat("_Mode", (float)blendMode); this.DetermineWorkflow(MaterialEditor.GetMaterialProperties(new Material[] { material })); StandardShaderGUI.MaterialChanged(material, this.m_WorkflowMode); } }
private static void MaterialChanged(Material material, StandardShaderGUI.WorkflowMode workflowMode) { if (material.GetFloat("_EmissionScaleUI") < 0f) { material.SetFloat("_EmissionScaleUI", 0f); } Color color = StandardShaderGUI.EvalFinalEmissionColor(material); material.SetColor("_EmissionColor", color); StandardShaderGUI.SetupMaterialWithBlendMode(material, (StandardShaderGUI.BlendMode)material.GetFloat("_Mode")); StandardShaderGUI.SetMaterialKeywords(material, workflowMode); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { this.FindProperties(props); this.m_MaterialEditor = materialEditor; Material target = materialEditor.target as Material; if (this.m_FirstTimeApply) { StandardShaderGUI.SetMaterialKeywords(target, this.m_WorkflowMode); this.m_FirstTimeApply = false; } this.ShaderPropertiesGUI(target); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { this.FindProperties(props); this.m_MaterialEditor = materialEditor; Material material = materialEditor.target as Material; if (this.m_FirstTimeApply) { StandardShaderGUI.MaterialChanged(material, this.m_WorkflowMode); this.m_FirstTimeApply = false; } this.ShaderPropertiesGUI(material); }
public void ShaderPropertiesGUI(Material material) { EditorGUIUtility.labelWidth = 0f; EditorGUI.BeginChangeCheck(); this.BlendModePopup(); GUILayout.Label(StandardShaderGUI.Styles.primaryMapsText, EditorStyles.boldLabel, new GUILayoutOption[0]); this.DoAlbedoArea(material); this.DoSpecularMetallicArea(); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.normalMapText, this.bumpMap, (!(this.bumpMap.textureValue != null)) ? null : this.bumpScale); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.heightMapText, this.heightMap, (!(this.heightMap.textureValue != null)) ? null : this.heigtMapScale); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.occlusionText, this.occlusionMap, (!(this.occlusionMap.textureValue != null)) ? null : this.occlusionStrength); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.detailMaskText, this.detailMask); this.DoEmissionArea(material); EditorGUI.BeginChangeCheck(); this.m_MaterialEditor.TextureScaleOffsetProperty(this.albedoMap); if (EditorGUI.EndChangeCheck()) { this.emissionMap.textureScaleAndOffset = this.albedoMap.textureScaleAndOffset; } EditorGUILayout.Space(); GUILayout.Label(StandardShaderGUI.Styles.secondaryMapsText, EditorStyles.boldLabel, new GUILayoutOption[0]); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.detailAlbedoText, this.detailAlbedoMap); this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.detailNormalMapText, this.detailNormalMap, this.detailNormalMapScale); this.m_MaterialEditor.TextureScaleOffsetProperty(this.detailAlbedoMap); this.m_MaterialEditor.ShaderProperty(this.uvSetSecondary, StandardShaderGUI.Styles.uvSetLabel.text); GUILayout.Label(StandardShaderGUI.Styles.forwardText, EditorStyles.boldLabel, new GUILayoutOption[0]); if (this.highlights != null) { this.m_MaterialEditor.ShaderProperty(this.highlights, StandardShaderGUI.Styles.highlightsText); } if (this.reflections != null) { this.m_MaterialEditor.ShaderProperty(this.reflections, StandardShaderGUI.Styles.reflectionsText); } if (EditorGUI.EndChangeCheck()) { UnityEngine.Object[] targets = this.blendMode.targets; for (int i = 0; i < targets.Length; i++) { UnityEngine.Object @object = targets[i]; StandardShaderGUI.MaterialChanged((Material)@object, this.m_WorkflowMode); } } EditorGUILayout.Space(); GUILayout.Label(StandardShaderGUI.Styles.advancedText, EditorStyles.boldLabel, new GUILayoutOption[0]); this.m_MaterialEditor.RenderQueueField(); this.m_MaterialEditor.EnableInstancingField(); }
private static void SetMaterialKeywords(Material material, StandardShaderGUI.WorkflowMode workflowMode) { StandardShaderGUI.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap") || material.GetTexture("_DetailNormalMap")); if (workflowMode == StandardShaderGUI.WorkflowMode.Specular) { StandardShaderGUI.SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap")); } else if (workflowMode == StandardShaderGUI.WorkflowMode.Metallic) { StandardShaderGUI.SetKeyword(material, "_METALLICGLOSSMAP", material.GetTexture("_MetallicGlossMap")); } StandardShaderGUI.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap")); StandardShaderGUI.SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap")); MaterialEditor.FixupEmissiveFlag(material); bool state = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == MaterialGlobalIlluminationFlags.None; StandardShaderGUI.SetKeyword(material, "_EMISSION", state); if (material.HasProperty("_SmoothnessTextureChannel")) { StandardShaderGUI.SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", StandardShaderGUI.GetSmoothnessMapChannel(material) == StandardShaderGUI.SmoothnessMapChannel.AlbedoAlpha); } }
private void DoEmissionArea(Material material) { bool flag = this.emissionScaleUI.floatValue > 0f; bool flag2 = this.emissionMap.textureValue != null; this.m_MaterialEditor.TexturePropertySingleLine(StandardShaderGUI.Styles.emissionText, this.emissionMap, (!flag) ? null : this.emissionColorUI, this.emissionScaleUI); if (this.emissionMap.textureValue != null && !flag2 && this.emissionScaleUI.floatValue <= 0f) { this.emissionScaleUI.floatValue = 1f; } if (flag) { bool flag3 = StandardShaderGUI.ShouldEmissionBeEnabled(StandardShaderGUI.EvalFinalEmissionColor(material)); EditorGUI.BeginDisabledGroup(!flag3); this.m_MaterialEditor.LightmapEmissionProperty(3); EditorGUI.EndDisabledGroup(); } if (!this.HasValidEmissiveKeyword(material)) { EditorGUILayout.HelpBox(StandardShaderGUI.Styles.emissiveWarning.text, MessageType.Warning); } }
private void DoEmissionArea(Material material) { float maxColorComponent = this.emissionColorForRendering.colorValue.maxColorComponent; bool flag1 = !this.HasValidEmissiveKeyword(material); bool flag2 = (double)maxColorComponent > 0.0; bool flag3 = (UnityEngine.Object) this.emissionMap.textureValue != (UnityEngine.Object)null; this.m_MaterialEditor.TexturePropertyWithHDRColor(StandardShaderGUI.Styles.emissionText, this.emissionMap, this.emissionColorForRendering, this.m_ColorPickerHDRConfig, false); if ((UnityEngine.Object) this.emissionMap.textureValue != (UnityEngine.Object)null && !flag3 && (double)maxColorComponent <= 0.0) { this.emissionColorForRendering.colorValue = Color.white; } if (flag2) { EditorGUI.BeginDisabledGroup(!StandardShaderGUI.ShouldEmissionBeEnabled(this.emissionColorForRendering.colorValue)); this.m_MaterialEditor.LightmapEmissionProperty(3); EditorGUI.EndDisabledGroup(); } if (!flag1) { return; } EditorGUILayout.HelpBox(StandardShaderGUI.Styles.emissiveWarning.text, MessageType.Warning); }
private static void MaterialChanged(Material material, StandardShaderGUI.WorkflowMode workflowMode) { StandardShaderGUI.SetupMaterialWithBlendMode(material, (StandardShaderGUI.BlendMode)material.GetFloat("_Mode")); StandardShaderGUI.SetMaterialKeywords(material, workflowMode); }
private bool HasValidEmissiveKeyword(Material material) { return(material.IsKeywordEnabled("_EMISSION") || !StandardShaderGUI.ShouldEmissionBeEnabled(material, this.emissionColorForRendering.colorValue)); }
public static void SetupMaterialWithBlendMode(Material material, StandardShaderGUI.BlendMode blendMode) { switch (blendMode) { case StandardShaderGUI.BlendMode.Opaque: material.SetOverrideTag("RenderType", string.Empty); material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 0); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; break; case StandardShaderGUI.BlendMode.Cutout: material.SetOverrideTag("RenderType", "TransparentCutout"); material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 0); material.SetInt("_ZWrite", 1); material.EnableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 2450; break; case StandardShaderGUI.BlendMode.Fade: material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", 5); material.SetInt("_DstBlend", 10); material.SetInt("_ZWrite", 0); material.DisableKeyword("_ALPHATEST_ON"); material.EnableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 3000; break; case StandardShaderGUI.BlendMode.Transparent: material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 10); material.SetInt("_ZWrite", 0); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 3000; break; } }
private static void SetMaterialKeywords(Material material, StandardShaderGUI.WorkflowMode workflowMode) { StandardShaderGUI.SetKeyword(material, "_NORMALMAP", (bool) ((UnityEngine.Object) material.GetTexture("_BumpMap")) || (bool) ((UnityEngine.Object) material.GetTexture("_DetailNormalMap"))); if (workflowMode == StandardShaderGUI.WorkflowMode.Specular) StandardShaderGUI.SetKeyword(material, "_SPECGLOSSMAP", (bool) ((UnityEngine.Object) material.GetTexture("_SpecGlossMap"))); else if (workflowMode == StandardShaderGUI.WorkflowMode.Metallic) StandardShaderGUI.SetKeyword(material, "_METALLICGLOSSMAP", (bool) ((UnityEngine.Object) material.GetTexture("_MetallicGlossMap"))); StandardShaderGUI.SetKeyword(material, "_PARALLAXMAP", (bool) ((UnityEngine.Object) material.GetTexture("_ParallaxMap"))); StandardShaderGUI.SetKeyword(material, "_DETAIL_MULX2", (bool) ((UnityEngine.Object) material.GetTexture("_DetailAlbedoMap")) || (bool) ((UnityEngine.Object) material.GetTexture("_DetailNormalMap"))); bool state = StandardShaderGUI.ShouldEmissionBeEnabled(material.GetColor("_EmissionColor")); StandardShaderGUI.SetKeyword(material, "_EMISSION", state); MaterialGlobalIlluminationFlags illuminationFlags1 = material.globalIlluminationFlags; if ((illuminationFlags1 & (MaterialGlobalIlluminationFlags.RealtimeEmissive | MaterialGlobalIlluminationFlags.BakedEmissive)) == MaterialGlobalIlluminationFlags.None) return; MaterialGlobalIlluminationFlags illuminationFlags2 = illuminationFlags1 & ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; if (!state) illuminationFlags2 |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; material.globalIlluminationFlags = illuminationFlags2; }
private static void MaterialChanged(Material material, StandardShaderGUI.WorkflowMode workflowMode) { StandardShaderGUI.SetupMaterialWithBlendMode(material, (StandardShaderGUI.BlendMode) material.GetFloat("_Mode")); StandardShaderGUI.SetMaterialKeywords(material, workflowMode); }