private void DisplaySmoothness()
    {
        SmoothnessSource source = SmoothnessSource.Uniform;

        if (IsKeywordEnable(KeywordType.kSmoothnessAlbedo))
        {
            source = SmoothnessSource.Albedo;
        }
        else if (IsKeywordEnable(KeywordType.kSmoothnessMetallic))
        {
            source = SmoothnessSource.Metallic;
        }

        EditorGUI.BeginChangeCheck();

        var slider = FindProperty("_Smoothness", _properties);

        EditorGUI.indentLevel += 2;
        _editor.ShaderProperty(slider, MakeLabel(slider));
        EditorGUI.indentLevel += 1;
        source = (SmoothnessSource)EditorGUILayout.EnumPopup(MakeLabel("Source"), source);
        EditorGUI.indentLevel -= 3;

        if (EditorGUI.EndChangeCheck())
        {
            RecordAction("Smoothness source");
            SetKeyword(KeywordType.kSmoothnessAlbedo, source == SmoothnessSource.Albedo);
            SetKeyword(KeywordType.kSmoothnessMetallic, source == SmoothnessSource.Metallic);
        }
    }
    void DoSmoothness()
    {
        SmoothnessSource source = SmoothnessSource.Uniform;

        if (IsKeywordEnabled("_SMOOTHNESS_ALBEDO"))
        {
            source = SmoothnessSource.Albedo;
        }
        else if (IsKeywordEnabled("_SMOOTHNESS_METALLIC"))
        {
            source = SmoothnessSource.Metallic;
        }
        MaterialProperty slider = FindProperty("_Smoothness");

        EditorGUI.indentLevel += 2;
        editor.ShaderProperty(slider, MakeLabel(slider));
        EditorGUI.indentLevel += 1;
        EditorGUI.BeginChangeCheck();
        source = (SmoothnessSource)EditorGUILayout.EnumPopup(
            MakeLabel("Source"), source
            );
        if (EditorGUI.EndChangeCheck())
        {
            RecordAction("Smoothness Source");
            SetKeyword("_SMOOTHNESS_ALBEDO", source == SmoothnessSource.Albedo);
            SetKeyword(
                "_SMOOTHNESS_METALLIC", source == SmoothnessSource.Metallic
                );
        }
        EditorGUI.indentLevel -= 3;
    }
    void DoSmoothness()
    {
        MaterialProperty smooth = FindProperty("_Smoothness");

        //做一个slider
        EditorGUI.indentLevel += 2;
        editor.ShaderProperty(smooth, MakeLabel(smooth, "smoothness"));


        //下拉菜单
        SmoothnessSource source = SmoothnessSource.Uniform;

        if (IsKeywordEnable("_SMOOTHNESS_ALBEDO"))
        {
            source = SmoothnessSource.Albedo;
        }
        else if (IsKeywordEnable("_SMOOTHNESS_METALIC"))
        {
            source = SmoothnessSource.Metalic;
        }
        EditorGUI.indentLevel += 2;
        EditorGUI.BeginChangeCheck();
        source = (SmoothnessSource)EditorGUILayout.EnumPopup("source", source);
        if (EditorGUI.EndChangeCheck())
        {
            //支持redo undo
            editor.RegisterPropertyChangeUndo("smooth");
            SetKeyword("_SMOOTHNESS_ALBEDO", source == SmoothnessSource.Albedo);
            SetKeyword("_SMOOTHNESS_METALIC", source == SmoothnessSource.Metalic);
        }
        EditorGUI.indentLevel -= 4;
    }
        private static 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
            {
                SmoothnessSource glossSource = (SmoothnessSource)material.GetFloat("_SmoothnessSource");
                bool             hasGlossMap = material.GetTexture("_SpecGlossMap");
                CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap);
                CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", !hasGlossMap);
                CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", glossSource == SmoothnessSource.BaseAlpha);
            }
        }
Beispiel #5
0
    void DoSmoothness()
    {
        SmoothnessSource source = SmoothnessSource.Uniform;

        if (IsKeywordEnabled("_SMOOTHNESS_ALBEDO"))
        {
            source = SmoothnessSource.SpecularMap;
        }

        MaterialProperty slider = FindProperty("_Smoothness");

        EditorGUI.indentLevel += 2;
        editor.ShaderProperty(slider, MakeLabel(slider));
        EditorGUI.indentLevel += 1;
        EditorGUI.BeginChangeCheck();
        source = (SmoothnessSource)EditorGUILayout.EnumPopup(
            MakeLabel("Source"), source);

        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_SMOOTHNESS_ALBEDO", source == SmoothnessSource.SpecularMap);
        }
        EditorGUI.indentLevel -= 3;
    }
Beispiel #6
0
    public override void OnGUI(MaterialEditor editor, MaterialProperty[] properties)
    {
        this.target     = editor.target as Material;
        this.editor     = editor;
        this.properties = properties;

        RenderingMode renderingMode = RenderingMode.Opaque;

        if (IsKeywordEnabled("_RENDERING_CUTOUT"))
        {
            renderingMode = RenderingMode.Cutout;
        }
        else if (IsKeywordEnabled("_RENDERING_FADE"))
        {
            renderingMode = RenderingMode.Fade;
        }
        else if (IsKeywordEnabled("_RENDERING_TRANSPARENT"))
        {
            renderingMode = RenderingMode.Transparent;
        }

        EditorGUI.BeginChangeCheck();
        renderingMode = (RenderingMode)EditorGUILayout.EnumPopup("Rendering Mode", renderingMode);
        if (EditorGUI.EndChangeCheck())
        {
            editor.RegisterPropertyChangeUndo("Rendering Mode");
            SetKeyword("_RENDERING_CUTOUT", renderingMode == RenderingMode.Cutout);
            SetKeyword("_RENDERING_FADE", renderingMode == RenderingMode.Fade);
            SetKeyword("_RENDERING_TRANSPARENT", renderingMode == RenderingMode.Transparent);
            RenderingSettings settings = RenderingSettings.modes[(int)renderingMode];
            foreach (Material m in editor.targets)
            {
                m.renderQueue = (int)settings.queue;
                m.SetOverrideTag("RenderType", settings.renderType);
                m.SetInt("_SrcBlend", (int)settings.srcBlend);
                m.SetInt("_DstBlend", (int)settings.dstBlend);
                m.SetInt("_ZWrite", settings.zWrite ? 1 : 0);
            }
        }


        // wireframe render
        if (target.HasProperty("_WireframeColor"))
        {
            GUILayout.Label("Wireframe", EditorStyles.boldLabel);
            EditorGUI.indentLevel += 2;
            editor.ShaderProperty(FindProperty("_WireframeColor"), MakeLabel("Color"));
            editor.ShaderProperty(FindProperty("_WireframeSmoothing"), MakeLabel("Smoothing", "In screen space."));
            editor.ShaderProperty(FindProperty("_WireframeThickness"), MakeLabel("Thickness", "In screen space.")
                                  );
            EditorGUI.indentLevel -= 2;
        }

        // Main Maps
        GUILayout.Label("Main Maps", EditorStyles.boldLabel);
        MaterialProperty mainTex = FindProperty("_MainTex");

        editor.TexturePropertySingleLine(MakeLabel(mainTex, "Albedo (RGB)"), mainTex, FindProperty("_Color"));

        // cutout
        if (renderingMode == RenderingMode.Cutout)
        {
            MaterialProperty alphatCutoff = FindProperty("_Cutoff");
            EditorGUI.indentLevel += 2;
            editor.ShaderProperty(alphatCutoff, MakeLabel(alphatCutoff));
            EditorGUI.indentLevel -= 2;
        }

        // metallic
        MaterialProperty metallic = FindProperty("_MetallicMap");

        EditorGUI.BeginChangeCheck();
        editor.TexturePropertySingleLine(MakeLabel(metallic, "Metallic (R)"), metallic, metallic.textureValue ? null : FindProperty("_Metallic"));
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_METALLIC_MAP", metallic.textureValue);
        }

        // smothnes
        SmoothnessSource source = SmoothnessSource.Uniform;

        if (IsKeywordEnabled("_SMOOTHNESS_ALBEDO"))
        {
            source = SmoothnessSource.Albedo;
        }
        else if (IsKeywordEnabled("_SMOOTHNESS_METALLIC"))
        {
            source = SmoothnessSource.Metallic;
        }
        MaterialProperty smoothness = FindProperty("_Smoothness");

        EditorGUI.indentLevel += 2;
        editor.ShaderProperty(smoothness, MakeLabel(smoothness));
        EditorGUI.BeginChangeCheck();
        source = (SmoothnessSource)EditorGUILayout.EnumPopup("Source", source);
        if (EditorGUI.EndChangeCheck())
        {
            editor.RegisterPropertyChangeUndo("Smoothness Source");
            SetKeyword("_SMOOTHNESS_ALBEDO", source == SmoothnessSource.Albedo);
            SetKeyword("_SMOOTHNESS_METALLIC", source == SmoothnessSource.Metallic);
        }
        EditorGUI.indentLevel -= 2;

        // normal
        MaterialProperty normal = FindProperty("_NormalMap");

        EditorGUI.BeginChangeCheck();
        editor.TexturePropertySingleLine(MakeLabel(normal), normal, FindProperty("_BumpScale"));
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_NORMAL_MAP", normal.textureValue);
        }

        // emission
        MaterialProperty emission = FindProperty("_EmissionMap");

        EditorGUI.BeginChangeCheck();
        editor.TexturePropertyWithHDRColor(
            MakeLabel(emission, "Emission (RGB)"), emission, FindProperty("_Emission"),
            emissionConfig, false
            );
        editor.LightmapEmissionProperty(2);
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_EMISSION_MAP", emission.textureValue);
            foreach (Material m in editor.targets)
            {
                m.globalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
            }
        }

        // occlusion
        MaterialProperty occlusion = FindProperty("_OcclusionMap");

        EditorGUI.BeginChangeCheck();
        editor.TexturePropertySingleLine(
            MakeLabel(occlusion, "Occlusion (G)"), occlusion,
            occlusion.textureValue ? FindProperty("_OcclusionStrength") : null
            );
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_OCCLUSION_MAP", occlusion.textureValue);
        }

        // detail mask
        MaterialProperty detailmask = FindProperty("_DetailMask");

        EditorGUI.BeginChangeCheck();
        editor.TexturePropertySingleLine(
            MakeLabel(detailmask, "Detail Mask (A)"), detailmask
            );
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_DETAIL_MASK", detailmask.textureValue);
        }

        editor.TextureScaleOffsetProperty(mainTex);

        // Second Maps
        GUILayout.Label("Secondary Maps", EditorStyles.boldLabel);

        MaterialProperty detailTex = FindProperty("_DetailTex");

        EditorGUI.BeginChangeCheck();
        editor.TexturePropertySingleLine(
            MakeLabel(detailTex, "Albedo (RGB) multiplied by 2"), detailTex
            );
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_DETAIL_ALBEDO_MAP", detailTex.textureValue);
        }

        MaterialProperty detailNormal = FindProperty("_DetailNormalMap");

        EditorGUI.BeginChangeCheck();
        editor.TexturePropertySingleLine(
            MakeLabel(detailNormal), detailNormal, FindProperty("_DetailBumpScale")
            );
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword("_DETAIL_NORMAL_MAP", detailNormal.textureValue);
        }

        editor.TextureScaleOffsetProperty(detailTex);

        // Advanced
        GUILayout.Label("Advanced Options", EditorStyles.boldLabel);
        editor.EnableInstancingField();
    }
Beispiel #7
0
    public override void OnGUI(MaterialEditor editor, MaterialProperty[] properties)
    {
        //render default material editor
        //base.OnGUI(editor, properties);


        //reference
        this.target     = editor.target as Material;
        this.editor     = editor;
        this.properties = properties;


        //label
        GUILayout.Label("Main Maps", EditorStyles.boldLabel);


        //find property
        MaterialProperty albedoPro = FindProperty("_Albedo");
        MaterialProperty tint      = FindProperty("_Tint");


        // make label from property
        GUIContent albedoMapLabel = makeLabel(albedoPro, "albedo map");


        //add texturemap to GUI
        editor.TexturePropertySingleLine(albedoMapLabel, albedoPro, tint);


        //texture scale and offset , GUI indent
        EditorGUI.indentLevel += 2;
        editor.TextureScaleOffsetProperty(albedoPro);
        EditorGUI.indentLevel -= 2;


        //show property depend on the texture value
        MaterialProperty normalPro = FindProperty("_Normal");

        editor.TexturePropertySingleLine(makeLabel(normalPro), normalPro, normalPro.textureValue?FindProperty("_NormalScale"):null);


        //slider
        // MaterialProperty metalicPro = FindProperty("_Metalic");
        // editor.ShaderProperty(metalicPro, makeLabel(metalicPro));


        //adjust shader feature by texture value
        EditorGUI.BeginChangeCheck();
        MaterialProperty metalicPro    = FindProperty("_Metalic");
        MaterialProperty metalicMapPro = FindProperty("_MetalicMap");

        editor.TexturePropertySingleLine(makeLabel(metalicMapPro), metalicMapPro, metalicMapPro.textureValue ? null : metalicPro);
        if (EditorGUI.EndChangeCheck())
        {
            seKeywords("_METALIC_MAP", metalicMapPro.textureValue);
        }


        //dropdown menu
        //set variable value on gui
        SmoothnessSource source = SmoothnessSource.Uniform;

        if (this.target.IsKeywordEnabled("_SMOOTHNESS_ALBEDO"))
        {
            source = SmoothnessSource.Albedo;
        }
        else if (this.target.IsKeywordEnabled("_SMOOTHNESS_METALLIC"))
        {
            source = SmoothnessSource.Metallic;
        }
        //check GUI change
        EditorGUI.BeginChangeCheck();
        //set variabl value
        source = (SmoothnessSource)EditorGUILayout.EnumPopup("Source", source);
        if (EditorGUI.EndChangeCheck())
        {
            seKeywords("_SMOOTHNESS_ALBEDO", source == SmoothnessSource.Albedo);
            seKeywords("_SMOOTHNESS_METALLIC", source == SmoothnessSource.Metallic);
        }


        //HDR color picker
        MaterialProperty emissionMapPro = FindProperty("_EmissionMap");
        MaterialProperty esmissionPro   = FindProperty("_Emission");

        editor.TexturePropertyWithHDRColor(makeLabel(emissionMapPro), emissionMapPro, esmissionPro, false);
    }