Beispiel #1
0
 public override void DrawFeatureGUI(MicroSplatKeywords keywords)
 {
     windParticulate = (ParticulateMode)EditorGUILayout.EnumPopup(CWindParticulate, windParticulate);
     if (windParticulate != ParticulateMode.None)
     {
         EditorGUI.indentLevel++;
         windUpFilter = EditorGUILayout.Toggle(CUpFilter, windUpFilter);
         EditorGUI.indentLevel--;
     }
     glitter = EditorGUILayout.Toggle(CGlitter, glitter);
     if (keywords.IsKeywordEnabled("_SNOW"))
     {
         snowParticulate = (ParticulateMode)EditorGUILayout.EnumPopup(CSnowParticulate, snowParticulate);
         if (snowParticulate != ParticulateMode.None)
         {
             EditorGUI.indentLevel++;
             snowUpFilter = EditorGUILayout.Toggle(CUpFilter, windUpFilter);
             EditorGUI.indentLevel--;
         }
         snowGlitter = EditorGUILayout.Toggle(CSnowGlitter, snowGlitter);
     }
     else
     {
         snowParticulate = ParticulateMode.None;
         snowGlitter     = false;
     }
 }
 public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, MicroSplatKeywords keywords, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
 {
     if (alphaHole != AlphaHoleMode.None || alphaBelowHeight)
     {
         if (MicroSplatUtilities.DrawRollup("Alpha"))
         {
             if (mat.HasProperty("_AlphaData") && alphaHole == AlphaHoleMode.SplatIndex || alphaBelowHeight)
             {
                 Vector4 vals    = shaderGUI.FindProp("_AlphaData", props).vectorValue;
                 Vector4 newVals = vals;
                 if (alphaHole == AlphaHoleMode.SplatIndex)
                 {
                     newVals.x = (int)EditorGUILayout.IntSlider(CTextureIndex, (int)vals.x, 0, 16);
                 }
                 if (alphaBelowHeight)
                 {
                     newVals.y = EditorGUILayout.FloatField(CWaterLevel, vals.y);
                 }
                 if (newVals != vals)
                 {
                     shaderGUI.FindProp("_AlphaData", props).vectorValue = newVals;
                 }
             }
             else if (mat.HasProperty("_AlphaHoleTexture"))
             {
                 materialEditor.TexturePropertySingleLine(CAlphaTexture, shaderGUI.FindProp("_AlphaHoleTexture", props));
             }
         }
     }
 }
Beispiel #3
0
        static protected bool DrawPerTexPopUp(int curIdx, int pixel, string keyword, MicroSplatKeywords keywords, MicroSplatPropData propData, Channel channel,
                                              GUIContent label, GUIContent[] options)
        {
            EditorGUILayout.BeginHorizontal();
            bool enabled = PerTexToggle(keywords, keyword);

            GUI.enabled = enabled;
            Color c = propData.GetValue(curIdx, pixel);
            float v = c[(int)channel];

            EditorGUI.BeginChangeCheck();
            int selected = EditorGUILayout.Popup(label, (int)v, options);

            if (EditorGUI.EndChangeCheck())
            {
                c [(int)channel] = selected;
                propData.SetValue(curIdx, pixel, c);
            }

            if (GUILayout.Button("All", GUILayout.Width(40)))
            {
                for (int i = 0; i < 32; ++i)
                {
                    Color nv = propData.GetValue(i, pixel);
                    nv[(int)channel] = selected;
                    propData.SetValue(i, pixel, nv);
                }
            }

            GUI.enabled      = true;
            drawPertexToggle = true;
            EditorGUILayout.EndHorizontal();

            return(enabled);
        }
Beispiel #4
0
 public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, MicroSplatKeywords keywords, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
 {
     if (triplanarMode != TriplanarMode.None)
     {
         if (MicroSplatUtilities.DrawRollup("Triplanar") && mat.HasProperty("_TriplanarContrast"))
         {
             materialEditor.ShaderProperty(shaderGUI.FindProp("_TriplanarContrast", props), CTriplanarContrast);
             if (mat.HasProperty("_TriplanarUVScale"))
             {
                 EditorGUI.BeginChangeCheck();
                 Vector4 uvScale = shaderGUI.FindProp("_TriplanarUVScale", props).vectorValue;
                 Vector2 scl     = new Vector2(uvScale.x, uvScale.y);
                 Vector2 offset  = new Vector2(uvScale.z, uvScale.w);
                 scl    = EditorGUILayout.Vector2Field("Triplanar UV Scale", scl);
                 offset = EditorGUILayout.Vector2Field("Triplanar UV Offset", offset);
                 if (EditorGUI.EndChangeCheck())
                 {
                     uvScale.x = scl.x;
                     uvScale.y = scl.y;
                     uvScale.z = offset.x;
                     uvScale.w = offset.y;
                     shaderGUI.FindProp("_TriplanarUVScale", props).vectorValue = uvScale;
                     EditorUtility.SetDirty(mat);
                 }
             }
         }
     }
 }
Beispiel #5
0
 static bool PerTexToggle(MicroSplatKeywords keywords, string keyword)
 {
     if (drawPertexToggle)
     {
         bool enabled    = keywords.IsKeywordEnabled(keyword);
         bool newEnabled = EditorGUILayout.Toggle(enabled, GUILayout.Width(20));
         if (enabled != newEnabled)
         {
             if (newEnabled)
             {
                 keywords.EnableKeyword(keyword);
             }
             else
             {
                 keywords.DisableKeyword(keyword);
             }
         }
         return(newEnabled);
     }
     else
     {
         EditorGUILayout.LabelField("", GUILayout.Width(noPerTexToggleWidth));
         drawPertexToggle = true;
         return(keywords.IsKeywordEnabled(keyword));
     }
 }
        public static MicroSplatKeywords FindOrCreateKeywords(Material mat)
        {
            if (mat == null)
            {
                return(null);
            }
            var path = AssetDatabase.GetAssetPath(mat);

            if (string.IsNullOrEmpty(path))
            {
                Debug.LogWarning("Material has no path");

                // not sure what to do about this case. Mat should always have a path
                path = "Assets/MicroSplatKeywords.mat";
            }
            path = path.Replace("\\", "/");
            path = path.Replace(".mat", "_keywords.asset");

            MicroSplatKeywords keywords = AssetDatabase.LoadAssetAtPath <MicroSplatKeywords>(path);

            if (keywords == null)
            {
                keywords          = ScriptableObject.CreateInstance <MicroSplatKeywords>();
                keywords.keywords = new List <string>(mat.shaderKeywords);
                AssetDatabase.CreateAsset(keywords, path);
                UnityEditor.AssetDatabase.SaveAssets();
                mat.shaderKeywords = null;
            }

            return(keywords);
        }
Beispiel #7
0
        protected bool DrawGlobalToggle(string keyword, MicroSplatKeywords keywords)
        {
            bool b = keywords.IsKeywordEnabled(keyword);

            if (globalButtonPressedStyle == null)
            {
                globalButtonPressedStyle = new GUIStyle(GUI.skin.label);
                globalButtonPressedStyle.normal.background = new Texture2D(1, 1);
                globalButtonPressedStyle.normal.background.SetPixel(0, 0, Color.yellow);
                globalButtonPressedStyle.normal.background.Apply();
                globalButtonPressedStyle.normal.textColor = Color.black;
            }

            bool pressed = (GUILayout.Button(globalButton, b ? globalButtonPressedStyle : GUI.skin.label, GUILayout.Width(14)));


            if (pressed)
            {
                if (b)
                {
                    keywords.DisableKeyword(keyword);
                }
                else
                {
                    keywords.EnableKeyword(keyword);
                }
                b = !b;
                EditorUtility.SetDirty(keywords);
            }
            return(b);
        }
   static Material SetupMaterial(MicroSplatKeywords kwds, Material mat, MicroSplatBaseFeatures.DebugOutput debugOutput, bool useDebugTopo)
   {
      MicroSplatShaderGUI.MicroSplatCompiler comp = new MicroSplatShaderGUI.MicroSplatCompiler();

      List<string> keywords = new List<string>(kwds.keywords);

      RemoveKeyword(keywords, "_SNOW");
      RemoveKeyword(keywords, "_TESSDISTANCE");
      RemoveKeyword(keywords, "_WINDPARTICULATE");
      RemoveKeyword(keywords, "_SNOWPARTICULATE");
      RemoveKeyword(keywords, "_GLITTER");
      RemoveKeyword(keywords, "_SNOWGLITTER");

      keywords.Add(FeatureFromOutput(debugOutput).ToString());
      if (useDebugTopo)
      {
         keywords.Add("_DEBUG_USE_TOPOLOGY");
      }

      string shader = comp.Compile(keywords.ToArray(), "RenderBake_" + debugOutput.ToString());
      Shader s = ShaderUtil.CreateShaderAsset(shader);
      Material renderMat = new Material(mat);
      renderMat.shader = s;
      return renderMat;
   }
        //GUIContent CShadowMap = new GUIContent("Shadow Map", "Shadow Map for distant terrain");

        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, MicroSplatKeywords keywords, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if ((grassMap || shadowMap) && MicroSplatUtilities.DrawRollup("Vegetation Studio"))
            {
                if (grassMap && mat.HasProperty("_VSTint"))
                {
                    EditorGUI.BeginChangeCheck();
                    var c = mat.GetColor("_VSTint");
                    c = EditorGUILayout.ColorField(CShaderTint, c);
                    if (EditorGUI.EndChangeCheck())
                    {
                        mat.SetColor("_VSTint", c);
                        EditorUtility.SetDirty(mat);
                    }
                }

                if (shadowMap && mat.HasProperty("_VSShadowMap"))
                {
                    var offsetProp = shaderGUI.FindProp("_VSShadowMapOffsetStrength", props);

                    Vector4 v = offsetProp.vectorValue;
                    EditorGUI.BeginChangeCheck();
                    //v.x = EditorGUILayout.FloatField("Offset", v.x);
                    v.y = EditorGUILayout.Slider("Min Tree Height", v.y, 0, 1.0f);
                    v.z = EditorGUILayout.Slider("Shadow Strength", v.z, 0, 1.0f);
                    v.w = EditorGUILayout.Slider("Shadow Ambient", v.w, 0, 1.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        offsetProp.vectorValue = v;
                    }
                }
            }
        }
        public override void DrawFeatureGUI(MicroSplatKeywords keywords)
        {
            if (keywords.IsKeywordEnabled("_MICROMESH"))
            {
                return;
            }
            bool old = terrainBlend;

            terrainBlend = EditorGUILayout.Toggle(CTerrainBlend, terrainBlend);
            if (old)
            {
                EditorGUI.indentLevel++;

                objectNormalBlend   = EditorGUILayout.Toggle(CObjectNormalBlend, objectNormalBlend);
                disableAlphaControl = EditorGUILayout.Toggle(CDisableAlphaControl, disableAlphaControl);
                blendNoise          = (BlendNoise)EditorGUILayout.EnumPopup(CBlendNoise, blendNoise);
                disableAlphaHoles   = EditorGUILayout.Toggle(CDisableAlphaHoles, disableAlphaHoles);
                if (keywords.IsKeywordEnabled("_DETAILNOISE") || keywords.IsKeywordEnabled("_ANTITILEARRAYDETAIL"))
                {
                    disableDetailNoise = EditorGUILayout.Toggle(CDisableDetailNoise, disableDetailNoise);
                }
                if (keywords.IsKeywordEnabled("_DISTANCENOISE") || keywords.IsKeywordEnabled("_ANTITILEARRAYDISTANCE"))
                {
                    disableDistanceNoise = EditorGUILayout.Toggle(CDisableDistanceNoise, disableDistanceNoise);
                }
                if (keywords.IsKeywordEnabled("_DISTANCERESAMPLE"))
                {
                    disableDistanceResampling = EditorGUILayout.Toggle(CDisableDistanceResample, disableDistanceResampling);
                }
                EditorGUI.indentLevel--;
            }
        }
 public override void DrawFeatureGUI(MicroSplatKeywords keywords)
 {
     if (!keywords.IsKeywordEnabled("_MICROVERTEXMESH") || (keywords.IsKeywordEnabled("_MSRENDERLOOP_UNITYLD")))
     {
         isTessellated = EditorGUILayout.Toggle(CShaderTessellation, isTessellated);
     }
     parallax = (ParallaxMode)EditorGUILayout.EnumPopup(CParallax, parallax);
 }
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, MicroSplatKeywords keywords, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (MicroSplatUtilities.DrawRollup("Splats"))
            {
                var albedoMap = shaderGUI.FindProp("_Diffuse", props);
                var normalMap = shaderGUI.FindProp("_NormalSAO", props);
                materialEditor.TexturePropertySingleLine(CAlbedoTex, albedoMap);
                if (!disableNormals)
                {
                    if (packMode == TextureArrayConfig.PackingMode.Fastest)
                    {
                        materialEditor.TexturePropertySingleLine(CNormalSpec, normalMap);
                    }
                    else
                    {
                        materialEditor.TexturePropertySingleLine(CNormal, normalMap);
                    }
                }

                if (emissiveArray && mat.HasProperty("_EmissiveMetal"))
                {
                    var emisMap = shaderGUI.FindProp("_EmissiveMetal", props);
                    materialEditor.TexturePropertySingleLine(CEmisMetal, emisMap);
                }

                if (packMode == TextureArrayConfig.PackingMode.Quality && mat.HasProperty("_SmoothAO"))
                {
                    var smoothAO = shaderGUI.FindProp("_SmoothAO", props);
                    materialEditor.TexturePropertySingleLine(CSmoothAO, smoothAO);
                }

                if (!disableHeightBlend)
                {
                    var contrastProp = shaderGUI.FindProp("_Contrast", props);
                    contrastProp.floatValue = EditorGUILayout.Slider(CInterpContrast, contrastProp.floatValue, 1.0f, 0.0001f);
                }


                if (!keywords.IsKeywordEnabled("_TRIPLANAR"))
                {
                    EditorGUI.BeginChangeCheck();
                    Vector4 uvScale = shaderGUI.FindProp("_UVScale", props).vectorValue;
                    Vector2 scl     = new Vector2(uvScale.x, uvScale.y);
                    Vector2 offset  = new Vector2(uvScale.z, uvScale.w);
                    scl    = EditorGUILayout.Vector2Field("Global UV Scale", scl);
                    offset = EditorGUILayout.Vector2Field("Global UV Offset", offset);
                    if (EditorGUI.EndChangeCheck())
                    {
                        uvScale.x = scl.x;
                        uvScale.y = scl.y;
                        uvScale.z = offset.x;
                        uvScale.w = offset.y;
                        shaderGUI.FindProp("_UVScale", props).vectorValue = uvScale;
                        EditorUtility.SetDirty(mat);
                    }
                }
            }
        }
Beispiel #13
0
        public override void DrawFeatureGUI(MicroSplatKeywords keywords)
        {
            wetness = EditorGUILayout.Toggle(CWetness, wetness);
            if (wetness)
            {
                EditorGUI.indentLevel++;
                heightWetness = EditorGUILayout.Toggle(CHeightWetness, heightWetness);
                EditorGUI.indentLevel--;
            }
            puddles = EditorGUILayout.Toggle(CPuddles, puddles);
            if (puddles)
            {
                EditorGUI.indentLevel++;
                rainDrops = EditorGUILayout.Toggle(CRainDrops, rainDrops);
                EditorGUI.indentLevel--;
            }
            streams = EditorGUILayout.Toggle(CStreams, streams);
            if (streams)
            {
                EditorGUI.indentLevel++;
                heightDampStreams = EditorGUILayout.Toggle(CHeightDampStreams, heightDampStreams);
                EditorGUI.indentLevel--;
            }
            lava = EditorGUILayout.Toggle(CLava, lava);
            if (lava)
            {
                EditorGUI.indentLevel++;
                heightDampLava = EditorGUILayout.Toggle(CHeightDampLava, heightDampLava);
#if __MICROSPLAT_TEXTURECLUSTERS__
                lavaStochastic = EditorGUILayout.Toggle(CLavaStochastic, lavaStochastic);
#endif
                EditorGUI.indentLevel--;
            }



            if ((streams || lava) && !keywords.IsKeywordEnabled("_MICROMESH"))
            {
                dynamicFlows = EditorGUILayout.Toggle(CDynamicFlows, dynamicFlows);
            }
            else
            {
                dynamicFlows = false;
            }



            if (keywords.IsKeywordEnabled("_SNOW"))
            {
                wetnessMaskSnow = EditorGUILayout.Toggle(CWetnessMaskSnow, wetnessMaskSnow);
            }
            else
            {
                wetnessMaskSnow = false;
            }

            specularFade = EditorGUILayout.Toggle(CSpecularFade, specularFade);
        }
Beispiel #14
0
 public override void DrawPerTextureGUI(int index, MicroSplatKeywords keywords, Material mat, MicroSplatPropData propData)
 {
     InitPropData(8, propData, new Color(1.0f, 0, 0, 0)); //snow strength
     if (snow == SnowMode.Rich)
     {
         perTexSnow = DrawPerTexFloatSlider(index, 8, GetFeatureName(SnowDefineFeature._PERTEXSNOWSTRENGTH),
                                            keywords, propData, Channel.R, CPerTexSnow, 0, 1);
     }
 }
Beispiel #15
0
        public void Pack(MicroSplatKeywords keywords)
        {
            var pck = Pack();

            for (int i = 0; i < pck.Length; ++i)
            {
                keywords.EnableKeyword(pck[i]);
            }
        }
    bool DrawRenderLoopGUI(MicroSplatKeywords keywords, Material targetMat)
    {
#if UNITY_2018_1_OR_NEWER
        // init render loop name list
        if (renderLoopNames == null || renderLoopNames.Length != availableRenderLoops.Count)
        {
            var rln = new List <GUIContent>();
            for (int i = 0; i < availableRenderLoops.Count; ++i)
            {
                rln.Add(new GUIContent(availableRenderLoops[i].GetDisplayName()));
            }
            renderLoopNames = rln.ToArray();
        }

        if (renderLoopNames.Length == 1)
        {
            return(false);
        }

        int curRenderLoopIndex = 0;
        for (int i = 0; i < keywords.keywords.Count; ++i)
        {
            string s = keywords.keywords[i];
            for (int j = 0; j < availableRenderLoops.Count; ++j)
            {
                if (s == availableRenderLoops[j].GetRenderLoopKeyword())
                {
                    curRenderLoopIndex  = j;
                    compiler.renderLoop = availableRenderLoops[j];
                    break;
                }
            }
        }

        int oldIdx = curRenderLoopIndex;
        curRenderLoopIndex = EditorGUILayout.Popup(CRenderLoop, curRenderLoopIndex, renderLoopNames);
        if (oldIdx != curRenderLoopIndex && curRenderLoopIndex >= 0 && curRenderLoopIndex < availableRenderLoops.Count)
        {
            if (compiler.renderLoop != null)
            {
                keywords.DisableKeyword(compiler.renderLoop.GetRenderLoopKeyword());
            }
            compiler.renderLoop = availableRenderLoops[curRenderLoopIndex];
            keywords.EnableKeyword(compiler.renderLoop.GetRenderLoopKeyword());
            return(true);
        }
#endif

#if UNITY_2018_3_OR_NEWER
        if (targetMat != null && !targetMat.enableInstancing)
        {
            EditorUtility.SetDirty(targetMat);
            targetMat.enableInstancing = true;
        }
#endif
        return(false);
    }
Beispiel #17
0
        public void Compile(Material m, string shaderName = null)
        {
            int hash = 0;

            MicroSplatKeywords keywords = MicroSplatUtilities.FindOrCreateKeywords(m);

            for (int i = 0; i < keywords.keywords.Count; ++i)
            {
                hash += 31 + keywords.keywords [i].GetHashCode();
            }
            var    path = AssetDatabase.GetAssetPath(m.shader);
            string nm   = m.shader.name;

            if (!string.IsNullOrEmpty(shaderName))
            {
                nm = shaderName;
            }
            string baseName = "Hidden/" + nm + "_Base" + hash.ToString();

            string terrainShader = Compile(keywords.keywords.ToArray(), nm, baseName);

            if (renderLoop != null)
            {
                keywords.EnableKeyword(renderLoop.GetRenderLoopKeyword());
            }

            GenerateAuxShaders(nm, path, keywords.keywords);

            MicroSplatUtilities.Checkout(path);
            System.IO.File.WriteAllText(path, terrainShader);

            if (!keywords.IsKeywordEnabled("_MICROMESH") && !keywords.IsKeywordEnabled("_MICROVERTEXMESH") && !keywords.IsKeywordEnabled("_MEGASPLAT") && !keywords.IsKeywordEnabled("_MICROTERRAINMESH"))
            {
                // generate fallback
                string[] oldKeywords = new string[keywords.keywords.Count];
                System.Array.Copy(keywords.keywords.ToArray(), oldKeywords, keywords.keywords.Count);
                keywords.DisableKeyword("_TESSDISTANCE");
                keywords.DisableKeyword("_PARALLAX");
                keywords.DisableKeyword("_DETAILNOISE");
                keywords.EnableKeyword("_MICROSPLATBASEMAP");

                string fallback = Compile(keywords.keywords.ToArray(), baseName);
                keywords.keywords = new List <string> (oldKeywords);
                string fallbackPath = path.Replace(".shader", "_Base.shader");
                MicroSplatUtilities.Checkout(fallbackPath);
                System.IO.File.WriteAllText(fallbackPath, fallback);
            }


            EditorUtility.SetDirty(m);
            AssetDatabase.Refresh();
#if __MICROSPLAT_MESH__
            MicroSplatMesh.ClearMaterialCache();
#endif
            MicroSplatObject.SyncAll();
        }
Beispiel #18
0
 public override void DrawFeatureGUI(MicroSplatKeywords keywords)
 {
     triplanarMode = (TriplanarMode)EditorGUILayout.EnumPopup(CTriplanar, triplanarMode);
     if (triplanarMode != TriplanarMode.None)
     {
         EditorGUI.indentLevel++;
         space = (TriplanarSpace)EditorGUILayout.EnumPopup(CSpace, space);
         EditorGUI.indentLevel--;
     }
 }
      public override void DrawPerTextureGUI(int index, MicroSplatKeywords keywords, Material mat, MicroSplatPropData propData)
      {
         InitPropData(0, propData, new Color(1.0f, 1.0f, 0.0f, 0.0f)); // uvscale2, uvOffset
         InitPropData(1, propData, new Color(1.0f, 1.0f, 1.0f, 0.0f)); // tint, interp contrast
         InitPropData(2, propData, new Color(1.0f, 0.0f, 1.0f, 0.0f)); // norm str, smooth str, ao str, metal values
         InitPropData(3, propData, new Color(0.0f, 1.0f, 0.4f, 1.0f)); // brightness, contrast, porosity, foam
         InitPropData(9, propData, new Color(1, 1, 1, 1));
         InitPropData(10, propData, new Color(1, 1, 1, 1));

         if (perTexUVScale && samplerMode == SamplerMode.Default)
         {
            EditorGUILayout.HelpBox("On some GPUs, small artifacts can appear with per-texture UV scales. Switching sampler mode to Mip (fast) or Gradient (slow) will fix the issue", MessageType.Info);
         }

         perTexUVScale = DrawPerTexVector2Vector2(index, 0, GetFeatureName(DefineFeature._PERTEXUVSCALEOFFSET), 
            keywords, propData, CPerTexUV, CPerTexUVOffset);

         if (!disableHeightBlend)
         {
            perTexInterpContrast = DrawPerTexFloatSlider(index, 1, GetFeatureName(DefineFeature._PERTEXINTERPCONTRAST),
               keywords, propData, Channel.A, CPerTexInterp, -1.0f, 1.0f);
         }

         perTexTint = DrawPerTexColor(index, 1, GetFeatureName(DefineFeature._PERTEXTINT),
            keywords, propData, CPerTexTint, false);

         perTexBrightness = DrawPerTexFloatSlider(index, 3, GetFeatureName(DefineFeature._PERTEXBRIGHTNESS),
            keywords, propData, Channel.R, CPerTexBrightness, -1.0f, 1.0f);

         perTexContrast = DrawPerTexFloatSlider(index, 3, GetFeatureName(DefineFeature._PERTEXCONTRAST),
            keywords, propData, Channel.G, CPerTexContrast, 0.1f, 3.0f);

         perTexSaturation = DrawPerTexFloatSlider(index, 9, GetFeatureName(DefineFeature._PERTEXSATURATION),
            keywords, propData, Channel.A, CPerTexSaturation, 0.0f, 2.0f);

         perTexNormStr = DrawPerTexFloatSlider(index, 2, GetFeatureName(DefineFeature._PERTEXNORMSTR),
            keywords, propData, Channel.R, CPerTexNormStr, 0.0f, 3.0f);
         
         perTexSmoothStr = DrawPerTexFloatSlider(index, 2, GetFeatureName(DefineFeature._PERTEXSMOOTHSTR),
            keywords, propData, Channel.G, CPerTexSmoothStr, -1.0f, 1.0f);

         perTexAOStr = DrawPerTexFloatSlider(index, 2, GetFeatureName(DefineFeature._PERTEXAOSTR),
            keywords, propData, Channel.B, CPerTexAOStr, 0.5f, 3.0f);

         perTexMetallic = DrawPerTexFloatSlider(index, 2, GetFeatureName(DefineFeature._PERTEXMETALLIC),
            keywords, propData, Channel.A, CPerTexMetallic, 0, 1);

         perTexHeightOffset = DrawPerTexFloatSlider(index, 10, GetFeatureName(DefineFeature._PERTEXHEIGHTOFFSET),
                                              keywords, propData, Channel.B, CPerTexHeightOffset, 0, 2);

         perTexHeightContrast = DrawPerTexFloatSlider(index, 10, GetFeatureName(DefineFeature._PERTEXHEIGHTCONTRAST),
                                              keywords, propData, Channel.A, CPerTexHeightContrast, 0.2f, 4);


      }
        void RevertTerrainSplats(MicroSplatTerrain t)
        {
            MicroSplatKeywords keywords = MicroSplatUtilities.FindOrCreateKeywords(t.templateMaterial);

            if (keywords.IsKeywordEnabled("_CUSTOMSPLATTEXTURES"))
            {
                if (t.customControl0 == null)
                {
                    Debug.LogError("Could not revert terrain because textures are missing!");
                    return;
                }

                UncompressTexture(t.customControl0);
                UncompressTexture(t.customControl1);
                UncompressTexture(t.customControl2);
                UncompressTexture(t.customControl3);
                UncompressTexture(t.customControl4);
                UncompressTexture(t.customControl5);
                UncompressTexture(t.customControl6);
                UncompressTexture(t.customControl7);

                int size   = t.customControl0.width;
                int layers = t.terrain.terrainData.alphamapLayers;
                t.terrain.terrainData.alphamapResolution = size;
                var maps = t.terrain.terrainData.GetAlphamaps(0, 0, size, size);

                ExtractSplats(ref maps, t.customControl0, 0, layers);
                ExtractSplats(ref maps, t.customControl1, 4, layers);
                ExtractSplats(ref maps, t.customControl2, 8, layers);
                ExtractSplats(ref maps, t.customControl3, 12, layers);
                ExtractSplats(ref maps, t.customControl4, 16, layers);
                ExtractSplats(ref maps, t.customControl5, 20, layers);
                ExtractSplats(ref maps, t.customControl6, 24, layers);
                ExtractSplats(ref maps, t.customControl7, 28, layers);

                t.terrain.terrainData.SetAlphamaps(0, 0, maps);
                EditorUtility.SetDirty(t.terrain.terrainData);


                keywords.DisableKeyword("_CUSTOMSPLATTEXTURES");
                MicroSplatShaderGUI.MicroSplatCompiler compiler = new MicroSplatShaderGUI.MicroSplatCompiler();
                compiler.Compile(t.templateMaterial);
                t.customControl0 = null;
                t.customControl1 = null;
                t.customControl2 = null;
                t.customControl3 = null;
                t.customControl4 = null;
                t.customControl5 = null;
                t.customControl6 = null;
                t.customControl7 = null;
                EditorUtility.SetDirty(t);
                MicroSplatTerrain.SyncAll();
            }
        }
 public override void DrawFeatureGUI(MicroSplatKeywords keywords)
 {
     grassMap  = EditorGUILayout.Toggle(CShaderGrassMap, grassMap);
     shadowMap = EditorGUILayout.Toggle(CShaderShadowMap, shadowMap);
     if (shadowMap)
     {
         EditorGUI.indentLevel++;
         shadowTapCount = (ShadowTapCount)EditorGUILayout.EnumPopup(CShaderTapCount, shadowTapCount);
         EditorGUI.indentLevel--;
     }
 }
 public override void DrawFeatureGUI(MicroSplatKeywords keywords)
 {
     clusterMode = (ClusterMode)EditorGUILayout.EnumPopup(CShaderClusters, clusterMode);
     if (clusterMode != ClusterMode.None && clusterMode != ClusterMode.Stochastic)
     {
         EditorGUI.indentLevel++;
         clusterNoiseUV = (ClusterNoiseUV)EditorGUILayout.EnumPopup(CClusterNoiseUVs, clusterNoiseUV);
         secondNoise    = EditorGUILayout.Toggle(CClusterNoise2, secondNoise);
         EditorGUI.indentLevel--;
     }
 }
Beispiel #23
0
 public override void DrawPerTextureGUI(int index, MicroSplatKeywords keywords, Material mat, MicroSplatPropData propData)
 {
     if (windParticulate != ParticulateMode.None)
     {
         perTexParticulate = DrawPerTexFloatSlider(index, 7, GetFeatureName(DefineFeature._PERTEXWINDPARTICULATE), keywords, propData, Channel.A, CPTWindParticulateStrength, 0, 1.0f);
     }
     if (glitter)
     {
         DrawPerTexFloatSliderNoToggle(index, 8, GetFeatureName(DefineFeature._GLITTER), keywords, propData, Channel.G, CPTGlitterStrength, 0, 1.0f);
     }
 }
Beispiel #24
0
        public override void DrawPerTextureGUI(int index, MicroSplatKeywords keywords, Material mat, MicroSplatPropData propData)
        {
            if (wetness || streams)
            {
                perTexPorosity = DrawPerTexFloatSlider(index, 3, GetFeatureName(DefineFeature._PERTEXPOROSITY),
                                                       keywords, propData, Channel.B, CPerTexPorosity, 0.0f, 1.0f);
            }

            if (streams)
            {
                perTexFoam = DrawPerTexFloatSlider(index, 3, GetFeatureName(DefineFeature._PERTEXFOAM),
                                                   keywords, propData, Channel.A, CPerTexFoam, 0.0f, 2.0f);
            }
        }
        public override void DrawPerTextureGUI(int index, MicroSplatKeywords keywords, Material mat, MicroSplatPropData propData)
        {
            if (isTessellated)
            {
                InitPropData(6, propData, new Color(1.0f, 0.0f, 0.0f, 0.5f)); // displace, up, offset

                perTexDisplace = DrawPerTexFloatSlider(index, 6, GetFeatureName(DefineFeature._PERTEXTESSDISPLACE),
                                                       keywords, propData, Channel.R, CPerTexDisplace, 0, 2);

                perTexUpBias = DrawPerTexFloatSlider(index, 6, GetFeatureName(DefineFeature._PERTEXTESSUPBIAS),
                                                     keywords, propData, Channel.G, CPerTexUpBias, 0, 1);

                perTexOffset = DrawPerTexFloatSlider(index, 6, GetFeatureName(DefineFeature._PERTEXTESSOFFSET),
                                                     keywords, propData, Channel.B, CPerTexOffset, -1, 1);

                perTexMipLevel = DrawPerTexFloatSlider(index, 4, GetFeatureName(DefineFeature._PERTEXTESSMIPLEVEL),
                                                       keywords, propData, Channel.A, CPerTexMipLevel, 0, 6);

                perTexShaping = DrawPerTexFloatSlider(index, 14, GetFeatureName(DefineFeature._PERTEXTESSSHAPING),
                                                      keywords, propData, Channel.A, CPerTexShaping, 0.001f, 0.999f);

                if (perTexOffset)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button(CComputeIdeal))
                    {
                        float h = IdealOffset(mat.GetTexture("_Diffuse") as Texture2DArray, index);
                        propData.SetValue(index, 6, (int)Channel.B, h);
                        AssetDatabase.Refresh();
                    }
                    if (GUILayout.Button(CComputeIdealAll))
                    {
                        var ta = mat.GetTexture("_Diffuse") as Texture2DArray;
                        for (int i = 0; i < 16; ++i)
                        {
                            float h = IdealOffset(ta, i);
                            propData.SetValue(i, 6, (int)Channel.B, h);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            if (parallax == ParallaxMode.Offset)
            {
                perTexParallax = DrawPerTexFloatSlider(index, 6, GetFeatureName(DefineFeature._PERTEXPARALLAX),
                                                       keywords, propData, Channel.A, CPerTexParallax, 0, 1);
            }
        }
Beispiel #26
0
        public override void DrawPerTextureGUI(int index, MicroSplatKeywords keywords, Material mat, MicroSplatPropData propData)
        {
            if (triplanarMode != TriplanarMode.None)
            {
                InitPropData(9, propData, new Color(0.0f, 0.5f, 0.0f, 0.0f));

                perTexTriplanar = DrawPerTexFloatSlider(index, 9, GetFeatureName(DefineFeature._PERTEXTRIPLANAR),
                                                        keywords, propData, Channel.R, CPerTexTriplanar, 0, 1);

                if (triplanarMode == TriplanarMode.HeightBlended)
                {
                    perTexTriplanarContrast = DrawPerTexFloatSlider(index, 9, GetFeatureName(DefineFeature._PERTEXTRIPLANARCONTRAST),
                                                                    keywords, propData, Channel.G, CPerTexTriplanarContrast, 0.01f, 1);
                }
            }
        }
Beispiel #27
0
        public override void DrawFeatureGUI(MicroSplatKeywords keywords)
        {
            snow = (SnowMode)EditorGUILayout.EnumPopup(CShaderSnow, snow);
            if (snow != SnowMode.None)
            {
                EditorGUI.indentLevel++;
                useWorldSpaceUV      = EditorGUILayout.Toggle(CWorldSpaceUV, useWorldSpaceUV);
                snowNormalNoise      = EditorGUILayout.Toggle(CShaderNormalNoise, snowNormalNoise);
                snowDistanceResample = EditorGUILayout.Toggle(CShaderSnowDistanceResample, snowDistanceResample);
#if __MICROSPLAT_TEXTURECLUSTERS__
                snowStochastic = EditorGUILayout.Toggle(CShaderSnowStochastic, snowStochastic);
#endif
                snowRim     = EditorGUILayout.Toggle(CSnowRim, snowRim);
                snowSSS     = EditorGUILayout.Toggle(CShaderSnowSSS, snowSSS);
                snowSparkle = EditorGUILayout.Toggle(CSnowSparkle, snowSparkle);
                snowMask    = EditorGUILayout.Toggle(CSnowMask, snowMask);
                EditorGUI.indentLevel--;
            }
        }
        public override void DrawPerTextureGUI(int index, MicroSplatKeywords keywords, Material mat, MicroSplatPropData propData)
        {
            if (clusterMode != ClusterMode.None && clusterMode != ClusterMode.Stochastic)
            {
                perTexClusterContrast = DrawPerTexFloatSlider(index, 10, GetFeatureName(DefineFeature._PERTEXCLUSTERCONTRAST),
                                                              keywords, propData, Channel.R, CPerTexClusterContrast, 1.0f, 0.01f);

                perTexClusterBoost = DrawPerTexFloatSlider(index, 10, GetFeatureName(DefineFeature._PERTEXCLUSTERBOOST),
                                                           keywords, propData, Channel.G, CPerTextureClusterBoost, 0.5f, 4.0f);
            }

            if (clusterMode == ClusterMode.Stochastic)
            {
                perTexStochastic = DrawPerTexFloatSlider(index, 9, GetFeatureName(DefineFeature._PERTEXSTOCHASTIC),
                                                         keywords, propData, Channel.B, CPerTexStochastic, 0.0f, 1.0f);

                perTexClusterContrast = DrawPerTexFloatSlider(index, 10, GetFeatureName(DefineFeature._PERTEXCLUSTERCONTRAST),
                                                              keywords, propData, Channel.R, CPerTexClusterContrast, 0.01f, 1.0f);
            }
        }
    public void RevisionFromMat()
    {
#if UNITY_EDITOR
        if (keywordSO == null && templateMaterial != null)
        {
            var path = UnityEditor.AssetDatabase.GetAssetPath(templateMaterial);
            path      = path.Replace(".mat", "_keywords.asset");
            keywordSO = UnityEditor.AssetDatabase.LoadAssetAtPath <MicroSplatKeywords>(path);
            if (keywordSO == null)
            {
                keywordSO          = ScriptableObject.CreateInstance <MicroSplatKeywords>();
                keywordSO.keywords = new List <string>(templateMaterial.shaderKeywords);
                UnityEditor.AssetDatabase.CreateAsset(keywordSO, path);
                UnityEditor.AssetDatabase.SaveAssets();
                templateMaterial.shaderKeywords = null;
            }
            UnityEditor.EditorUtility.SetDirty(this);
        }
#endif
    }
      public override void DrawFeatureGUI(MicroSplatKeywords keywords)
      {
         bool isSurfaceShader = keywords.IsKeywordEnabled("_MSRENDERLOOP_SURFACESHADER");
         packMode = (TextureArrayConfig.PackingMode)EditorGUILayout.EnumPopup(CPackMode, packMode);
         perfMode = (PerformanceMode)EditorGUILayout.EnumPopup(CShaderPerfMode, perfMode);
         maxTextureCount = (MaxTextureCount)EditorGUILayout.EnumPopup(CMaxTexCount, maxTextureCount);
         if (isSurfaceShader)
         {
            lightingMode = (LightingMode)EditorGUILayout.EnumPopup(CLightingMode, lightingMode);
         }
         uvMode = (UVMode)EditorGUILayout.EnumPopup(CUVMode, uvMode);
         shaderModel = (ShaderModel)EditorGUILayout.EnumPopup(CForceShaderModel, shaderModel);
         samplerMode = (SamplerMode)EditorGUILayout.EnumPopup(CSamplerMode, samplerMode);
         emissiveArray = EditorGUILayout.Toggle(CEmissiveArray, emissiveArray);
         perPixelNormal = EditorGUILayout.Toggle(CPerPixelNormal, perPixelNormal);
         disableHeightBlend = EditorGUILayout.Toggle(CDisableHeightBlend, disableHeightBlend);
         disableNormals = EditorGUILayout.Toggle(CDisableNormals, disableNormals);
         useCustomSplatMaps = EditorGUILayout.Toggle(CUseCustomSplatMaps, useCustomSplatMaps);

         debugOutput = (DebugOutput)EditorGUILayout.EnumPopup("Debug", debugOutput);
      }