夜風のMixedReality

xRと出会って変わった人生と出会った技術を書き残すためのGeekなHoloRangerの居場所

MRTK GT用のToonShaderを開発する その④ PRのフィードバックを反映させる

本日はMRGT枠です。

〇MRGTとは?

MixedRealityToolkit GraphicsTools(略してMRTK GT もっと略してMRGT)はMicrosoftによって提供、開発されているMixedRealityデバイス向けアプリケーション開発のオープンソースプロジェクトです。

GraphicsToolsの名の通りグラフィックに特化した機能が提供されており、軽量なシェーダー、サンプル、Unityのエディタ内でのツールが提供されています。

github.com

オープンソースプロジェクト(OSS)であるため筆者も開発に参加しており、今回はGraphicsTools StandardShaderの開発を行っています。

〇フィードバックの反映

github.com

今回は主に次の2点の修正依頼がありました。

・誤字の修正

・UIの配置場所の変更

 筆者が出したPRではLightModeに新しく*Non-Photorealisticを追加しました。

 しかしこれではLit- Distantとの併用ができないたLight Modeを選択した際のオプションで選択ができるほうが良いというフィードバックをもらいました。

〇UIの変更

 まずStandardShaderGUI.csLigit Modeから追加したNon - Photorealisiticを削除します。

    /// <summary>
    /// What type of direct light affects the surface.
    /// </summary>
    public enum LightMode
     {
        Unlit = 0,
        LitDirectional = 1,
        LitDistant = 2
        LitDistant = 2,
        //NonPhotorealistic = 3
    }
public static readonly string[] lightModeNames = new string[] { "Unlit", "Lit - Directional", "Lit - Distant" , //"Non - Photorealistic"</s> };

また従来の仕組みではLightModeから排他的にシェーダーキーワードの有効化・無効化を行っていました。

ここも削除します。

 protected void RenderingOptions(MaterialEditor materialEditor, Material material)
        {
            EditorGUILayout.Space();
            GUILayout.Label(Styles.renderingOptionsTitle, EditorStyles.boldLabel);
            lightMode.floatValue = EditorGUILayout.Popup(Styles.lightMode, (int)lightMode.floatValue, Styles.lightModeNames);
            switch ((LightMode)lightMode.floatValue)
            {
                default:
                case LightMode.Unlit:
                    {
                        material.DisableKeyword(Styles.lightModeLitDirectional);
                        material.DisableKeyword(Styles.lightModeLitDistant);
                        //material.DisableKeyword(Styles.lightModeNPR);
                    }
                    break;
                case LightMode.LitDirectional:
                    {
                        material.EnableKeyword(Styles.lightModeLitDirectional);
                        material.DisableKeyword(Styles.lightModeLitDistant);
                       // material.DisableKeyword(Styles.lightModeNPR);
                    }
                    break;
                case LightMode.LitDistant:
                    {
                        material.DisableKeyword(Styles.lightModeLitDirectional);
                        material.EnableKeyword(Styles.lightModeLitDistant);
                     //   material.DisableKeyword(Styles.lightModeNPR);

                        GUILayout.Box(string.Format(Styles.propertiesComponentHelp, nameof(DistantLight), Styles.lightModeNames[(int)LightMode.LitDistant]), EditorStyles.helpBox, Array.Empty<GUILayoutOption>());
                    }
                    break;
             /*   case LightMode.NonPhotorealistic:
                    {
                        material.EnableKeyword(Styles.lightModeNPR);
                        material.DisableKeyword(Styles.lightModeLitDirectional);
                        material.DisableKeyword(Styles.lightModeLitDistant);
                    }
                    break;*/
            }

これでLightModeからNPRの表示が削除されました。

次にLigitModeでUnlit以外の選択をされている場面ですが、これは直後の処理で行われています。

 if ((LightMode)lightMode.floatValue != LightMode.Unlit)
            {
                materialEditor.ShaderProperty(specularHighlights, Styles.specularHighlights, 2);
                materialEditor.ShaderProperty(sphericalHarmonics, Styles.sphericalHarmonics, 2);
            }

LightModeがUnlit以外が選択されている場合GUIにspecularHighlightssphericalHarmonicsを表示させています。

ここにnonPhotorealisticRenderingの表示を追加します。

            if ((LightMode)lightMode.floatValue != LightMode.Unlit)
            {
                materialEditor.ShaderProperty(specularHighlights, Styles.specularHighlights, 2);
                materialEditor.ShaderProperty(sphericalHarmonics, Styles.sphericalHarmonics, 2);
                materialEditor.ShaderProperty(nonPhotorealisticRendering, Styles.nonPhotorealisticRendering, 2);//追加
            }

同様にnonPhotorealisticRenderingを定義します。

これはLightModeで従来enumの中に定義していたので表に出す形になります。

   protected static class Styles
        {
          ・・・
            public static readonly string lightModeLitDirectional = "_DIRECTIONAL_LIGHT";
            public static readonly string lightModeLitDistant = "_DISTANT_LIGHT";
            public static readonly GUIContent nonPhotorealisticRendering = new GUIContent("Non-Photorealistic Rendering","Non-Photorealistic Rendering");//追加
            public static readonly GUIContent specularHighlights = new GUIContent("Specular Highlights", "Calculate Specular Highlights");
            public static readonly GUIContent sphericalHarmonics = new GUIContent("Spherical Harmonics", "Read From Spherical Harmonics Data for Ambient Light");
            public static readonly GUIContent reflections = new GUIContent("Reflections", "Calculate Glossy Reflections");
        protected MaterialProperty smoothness;
        protected MaterialProperty lightMode;
        protected MaterialProperty nonPhotorealisticRendering;
        protected MaterialProperty specularHighlights;
        protected MaterialProperty sphericalHarmonics;
            nonPhotorealisticRendering = FindProperty("_NPR", props);
            specularHighlights = FindProperty("_SpecularHighlights", props);
            sphericalHarmonics = FindProperty("_SphericalHarmonics", props);
            reflections = FindProperty("_Reflections", props);

これでGUI上でNPRがLightModeから外れ、Unlit以外のLightModeを使用している場合に表示されるようになりました。

次にShader内部の処理を組み替えます。従来はLightModeで定義されていたNPRの定義をToggle型としてチェックボックスとして対応させます。

    Properties
    {
        // Main maps.
        _Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
       ・・・
        // Rendering options.
        [Enum(Microsoft.MixedReality.GraphicsTools.Editor.LightMode)] _DirectionalLight("Light Mode", Float) = 1.0 // "LitDirectional"
        [Toggle(_NON_PHOTOREALISTIC)] _NPR("Non-Photorealistic Rendering", Float) = 0.0//追加

以上でフィードバックいただいた個所の修正が完了しました。

これで再度Pushします。

本日は以上です