private static void UpdateMaterialSpecularSource(Material material) { SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecSource"); if (specSource == SpecularSource.NoSpecular) { LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", false); LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false); LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", false); } else if (specSource == SpecularSource.SpecularTextureAndColor && material.GetTexture("_SpecGlossMap")) { GlossinessSource glossSource = (GlossinessSource)material.GetFloat("_GlossinessSource"); if (glossSource == GlossinessSource.BaseAlpha) { LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", false); LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", true); } else { LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", true); LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false); } LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", false); } else { LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", false); LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP_BASE_ALPHA", false); LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", true); } }
// material main surface inputs public override void DrawSurfaceInputs(Material material) { base.DrawSurfaceInputs(material); //Specular SpecularSource specSource = (SpecularSource)mProperties.specHighlights.floatValue; EditorGUI.BeginDisabledGroup(specSource == SpecularSource.NoSpecular); TextureColorProps(materialEditor, StylesExt.specularMapText, mProperties.specGlossMap, mProperties.specColor, true); //Smoothness var opaque = ((BaseShaderGUI.SurfaceType)material.GetFloat("_Surface") == BaseShaderGUI.SurfaceType.Opaque); EditorGUI.indentLevel += 2; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = mProperties.smoothness.hasMixedValue; var smoothnessSource = (int)mProperties.smoothnessMapChannel.floatValue; var smoothness = mProperties.smoothness.floatValue; smoothness = EditorGUILayout.Slider(StylesExt.smoothnessText, smoothness, 0f, 1f); if (EditorGUI.EndChangeCheck()) { mProperties.smoothness.floatValue = smoothness; } EditorGUI.showMixedValue = false; EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(!opaque); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = mProperties.smoothnessMapChannel.hasMixedValue; if (opaque) { smoothnessSource = EditorGUILayout.Popup(StylesExt.smoothnessMapChannelText, smoothnessSource, Enum.GetNames(typeof(SmoothnessMapChannel))); } else { EditorGUILayout.Popup(StylesExt.smoothnessMapChannelText, 0, Enum.GetNames(typeof(SmoothnessMapChannel))); } if (EditorGUI.EndChangeCheck()) { mProperties.smoothnessMapChannel.floatValue = smoothnessSource; } EditorGUI.showMixedValue = false; EditorGUI.indentLevel -= 3; EditorGUI.EndDisabledGroup(); // EditorGUI.EndDisabledGroup(); // DrawNormalArea(materialEditor, mProperties.bumpMapProp); DrawEmissionProperties(material, true); DrawTileOffset(materialEditor, baseMapProp); }
public static void DoSpecularArea(SimpleLitProperties properties, MaterialEditor materialEditor, Material material) { SpecularSource specSource = (SpecularSource)properties.specHighlights.floatValue; EditorGUI.BeginDisabledGroup(specSource == SpecularSource.NoSpecular); BaseShaderGUI.TextureColorProps(materialEditor, Styles.specularMapText, properties.specGlossMap, properties.specColor, true); DoSmoothness(properties, material); EditorGUI.EndDisabledGroup(); }
public static void Advanced(SimpleLitProperties properties) { SpecularSource specularSource = (SpecularSource)properties.specHighlights.floatValue; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = properties.specHighlights.hasMixedValue; bool enabled = EditorGUILayout.Toggle(Styles.highlightsText, specularSource == SpecularSource.SpecularTextureAndColor); if (EditorGUI.EndChangeCheck()) { properties.specHighlights.floatValue = enabled ? (float)SpecularSource.SpecularTextureAndColor : (float)SpecularSource.NoSpecular; } EditorGUI.showMixedValue = false; }
private void DoSpecular() { EditorGUILayout.Space(); SpecularSource specularSource = (SpecularSource)specularSourceProp.floatValue; EditorGUI.BeginChangeCheck(); bool enabled = EditorGUILayout.Toggle(Styles.specularSourceLabel, specularSource == SpecularSource.SpecularTextureAndColor); if (EditorGUI.EndChangeCheck()) { specularSourceProp.floatValue = enabled ? (float)SpecularSource.SpecularTextureAndColor : (float)SpecularSource.NoSpecular; } SpecularSource specSource = (SpecularSource)specularSourceProp.floatValue; if (specSource != SpecularSource.NoSpecular) { bool hasSpecularMap = specularGlossMapProp.textureValue != null; materialEditor.TexturePropertySingleLine(Styles.specularGlossMapLabels[(int)glossinessSourceProp.floatValue], specularGlossMapProp, hasSpecularMap ? null : specularColorProp); EditorGUI.indentLevel += 2; if (RequiresAlpha()) { GUI.enabled = false; glossinessSourceProp.floatValue = (float)EditorGUILayout.Popup(Styles.glossinessSourceLabel, (int)GlossinessSource.SpecularAlpha, Styles.glossinessSourceNames); GUI.enabled = true; } else { int glossinessSource = (int)glossinessSourceProp.floatValue; EditorGUI.BeginChangeCheck(); glossinessSource = EditorGUILayout.Popup(Styles.glossinessSourceLabel, glossinessSource, Styles.glossinessSourceNames); if (EditorGUI.EndChangeCheck()) { glossinessSourceProp.floatValue = glossinessSource; } GUI.enabled = true; } EditorGUI.BeginChangeCheck(); float shininess = EditorGUILayout.Slider(Styles.shininessLabel, shininessProp.floatValue, kMinShininessValue, 1.0f); if (EditorGUI.EndChangeCheck()) { shininessProp.floatValue = shininess; } EditorGUI.indentLevel -= 2; } }
public override void DrawAdvancedOptions(Material material) { SpecularSource specularSource = (SpecularSource)mProperties.specHighlights.floatValue; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = mProperties.specHighlights.hasMixedValue; bool enabled = EditorGUILayout.Toggle(StylesExt.highlightsText, specularSource == SpecularSource.SpecularTextureAndColor); if (EditorGUI.EndChangeCheck()) { mProperties.specHighlights.floatValue = enabled ? (float)SpecularSource.SpecularTextureAndColor : (float)SpecularSource.NoSpecular; } EditorGUI.showMixedValue = false; base.DrawAdvancedOptions(material); }
private void DoSpecular() { EditorGUILayout.Space(); int source = (int)specularSourceProp.floatValue; EditorGUI.BeginChangeCheck(); source = EditorGUILayout.Popup(Styles.specularSourceLabel, source, Styles.specSourceNames); if (EditorGUI.EndChangeCheck()) { specularSourceProp.floatValue = source; } SpecularSource specSource = (SpecularSource)specularSourceProp.floatValue; if (specSource != SpecularSource.NoSpecular) { int glossinessSource = (int)glossinessSourceProp.floatValue; EditorGUI.BeginChangeCheck(); glossinessSource = EditorGUILayout.Popup(Styles.glossinessSourceLable, glossinessSource, Styles.glossinessSourceNames); if (EditorGUI.EndChangeCheck()) { glossinessSourceProp.floatValue = (float)glossinessSource; } } int glossSource = (int)glossinessSourceProp.floatValue; if (specSource == SpecularSource.SpecularTextureAndColor) { m_MaterialEditor.TexturePropertySingleLine(Styles.specularGlossMapLabels[glossSource], specularGlossMapProp, specularColorProp); } if (specSource != SpecularSource.NoSpecular) { EditorGUI.BeginChangeCheck(); float shininess = EditorGUILayout.Slider(Styles.shininessLabel, shininessProp.floatValue, kMinShininessValue, 1.0f); if (EditorGUI.EndChangeCheck()) { shininessProp.floatValue = shininess; } } }
private static void UpdateMaterialSpecularSource(Material material) { var opaque = ((BaseShaderGUI.SurfaceType)material.GetFloat("_Surface") == BaseShaderGUI.SurfaceType.Opaque); SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecularHighlights"); if (specSource == SpecularSource.NoSpecular) { CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", false); CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", false); CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false); } else { var smoothnessSource = (SmoothnessMapChannel)material.GetFloat("_SmoothnessSource"); bool hasMap = material.GetTexture("_SpecGlossMap"); CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasMap); CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", !hasMap); if (opaque) { CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", smoothnessSource == SmoothnessMapChannel.AlbedoAlpha); } else { CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false); } string color; if (smoothnessSource != SmoothnessMapChannel.AlbedoAlpha || !opaque) { color = "_SpecColor"; } else { color = "_BaseColor"; } var col = material.GetColor(color); float smoothness = material.GetFloat("_Smoothness"); if (smoothness != col.a) { col.a = smoothness; material.SetColor(color, col); } } }
private void UpdateMaterialSpecularSource(Material material) { SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecSource"); if (specSource == SpecularSource.NoSpecular) { CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", false); CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", false); CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false); } else { GlossinessSource glossSource = (GlossinessSource)material.GetFloat("_GlossinessSource"); bool hasGlossMap = material.GetTexture("_SpecGlossMap"); CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap); CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", !hasGlossMap); CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", glossSource == GlossinessSource.BaseAlpha); } }
public static void SetMaterialKeywords(Material material) { //Specular Source var opaque = (SurfaceType)material.GetFloat("_Surface") == SurfaceType.Opaque; SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecularHighlights"); if (specSource == SpecularSource.NoSpecular) { CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", false); CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", false); CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false); } else { var smoothnessSource = (SmoothnessMapChannel)material.GetFloat("_SmoothnessSource"); bool hasMap = material.GetTexture("_SpecGlossMap"); CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasMap); CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", !hasMap); if (opaque) { CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", smoothnessSource == SmoothnessMapChannel.AlbedoAlpha); } else { CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false); } string color; if (smoothnessSource != SmoothnessMapChannel.AlbedoAlpha || !opaque) { color = "_SpecColor"; } else { color = "_BaseColor"; } var col = material.GetColor(color); col.a = material.GetFloat("_Smoothness"); material.SetColor(color, col); } // //Cross-Hatch var uvSource = (UVSource)material.GetFloat("_CrossHatchUVMode"); switch (uvSource) { case UVSource.TexCoord: CoreUtils.SetKeyword(material, "_CROSSHATCH_UV_TRIPLANAR", false); CoreUtils.SetKeyword(material, "_CROSSHATCH_UV_SCREEN", false); break; case UVSource.TriPlanar: CoreUtils.SetKeyword(material, "_CROSSHATCH_UV_TRIPLANAR", true); CoreUtils.SetKeyword(material, "_CROSSHATCH_UV_SCREEN", false); break; case UVSource.ScreenSpace: CoreUtils.SetKeyword(material, "_CROSSHATCH_UV_TRIPLANAR", false); CoreUtils.SetKeyword(material, "_CROSSHATCH_UV_SCREEN", true); break; } }