예제 #1
0
 public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, 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);
                 }
             }
         }
     }
 }
        Texture2D CreateTexture(Terrain t, Texture2D tex, string texNamePostfix, Color defaultColor)
        {
            // find/create manager
            var mgr = t.GetComponent <MicroSplatTerrain>();

            if (mgr == null)
            {
                return(null);
            }

            // if we still don't have a texture, create one
            if (tex == null)
            {
                tex = new Texture2D(t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, TextureFormat.RGBA32, false, true);

                for (int x = 0; x < tex.width; ++x)
                {
                    for (int y = 0; y < tex.height; ++y)
                    {
                        tex.SetPixel(x, y, defaultColor);
                    }
                }
                tex.Apply();
                tex.wrapMode = TextureWrapMode.Clamp;
                var path = MicroSplatUtilities.RelativePathFromAsset(t.terrainData);
                path += "/" + t.name + texNamePostfix + ".png";
                tex   = SaveTexture(path, tex);
                mgr.Sync();
            }


            return(tex);
        }
        //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 DrawShaderGUI(MicroSplatShaderGUI shaderGUI, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
 {
     if (alphaHole || alphaBelowHeight)
     {
         if (MicroSplatUtilities.DrawRollup("Alpha"))
         {
             if (mat.HasProperty("_AlphaData"))
             {
                 Vector4 vals    = shaderGUI.FindProp("_AlphaData", props).vectorValue;
                 Vector4 newVals = vals;
                 if (alphaHole)
                 {
                     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;
                 }
             }
         }
     }
 }
예제 #5
0
 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));
             }
         }
     }
 }
예제 #6
0
        void CreateTexture(Terrain t, string texNamePrefix = "", Material customMat = null)
        {
            // find/create manager
            var mgr = t.GetComponent <MicroSplatTerrain>();

            if (mgr == null)
            {
                return;
            }
            Texture2D tex = mgr.streamTexture;

            // if we still don't have a texture, create one
            if (tex == null)
            {
                tex = new Texture2D(t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, TextureFormat.ARGB32, false, true);
                mgr.streamTexture = tex;
                Color c = new Color(0, 0, 0, 0);
                for (int x = 0; x < tex.width; ++x)
                {
                    for (int y = 0; y < tex.height; ++y)
                    {
                        tex.SetPixel(x, y, c);
                    }
                }
                tex.Apply();
                tex.wrapMode = TextureWrapMode.Clamp;
                var path = MicroSplatUtilities.RelativePathFromAsset(t.terrainData);
                path += "/" + t.name + "_stream_data.png";
                mgr.streamTexture = SaveTexture(path, tex);
            }

            mgr.Sync();
        }
 void DrawStreamGUI()
 {
     if (MicroSplatUtilities.DrawRollup("Brush Settings"))
     {
         DrawBrushSettingsGUI();
     }
     DrawFillGUI();
 }
 void DrawTintGUI()
 {
     if (MicroSplatUtilities.DrawRollup("Brush Settings"))
     {
         DrawBrushSettingsGUI(true);
     }
     DrawFillGUI();
 }
        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);
                    }
                }
            }
        }
 void DrawBiomeGUI()
 {
     if (MicroSplatUtilities.DrawRollup("Brush Settings"))
     {
         DrawBrushSettingsGUI();
     }
     biomeChannel = EditorGUILayout.IntSlider("Target Biome Channel", biomeChannel, 0, 7);
     DrawFillGUI();
 }
        public static void DrawGUI(MicroSplatObject mso, Options o)
        {
            if (MicroSplatUtilities.DrawRollup("Compressor", false))
            {
                EditorGUILayout.HelpBox("You can use this section to automatically covert various maps to compressed formats before a build. Please note, that once compressed, external files will be used for things like the terrain splat maps, and changing the terrain through Unity's tools will have no effect", MessageType.Info);
                EditorGUILayout.LabelField("Compression Options");

                o.splatMaps = EditorGUILayout.Toggle(CCompSplatMaps, o.splatMaps);
                if (o.splatMaps)
                {
                    EditorGUILayout.HelpBox("This will remove the terrain painting from your terrain file to save memory! The Uncompress button will restore this from the output textures, but if you delete or unhook them your painting may be lost.", MessageType.Error);
                }
                o.streamMaps = EditorGUILayout.Toggle(CCompStreamMap, o.streamMaps);
                o.snowMask   = EditorGUILayout.Toggle(CCompSnowMaps, o.snowMask);
                o.biomeMask  = EditorGUILayout.Toggle(CCompBiomeMaps, o.biomeMask);
                o.tintMap    = EditorGUILayout.Toggle(CCompTintMaps, o.tintMap);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("Compress"))
                {
                    MicroSplatCompressor comp = new MicroSplatCompressor();
                    comp.Compress(mso, o);
                }
                if (GUILayout.Button("Uncompress"))
                {
                    MicroSplatCompressor comp = new MicroSplatCompressor();
                    comp.Revert(mso);
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("Compress Scene"))
                {
                    MicroSplatCompressor comp = new MicroSplatCompressor();
                    MicroSplatObject []  objs = GameObject.FindObjectsOfType <MicroSplatObject> ();
                    foreach (var obj in objs)
                    {
                        comp.Compress(obj, o);
                    }
                }
                if (GUILayout.Button("Uncompress Scene"))
                {
                    MicroSplatCompressor comp = new MicroSplatCompressor();
                    MicroSplatObject []  objs = GameObject.FindObjectsOfType <MicroSplatObject> ();
                    foreach (var obj in objs)
                    {
                        comp.Revert(obj);
                    }
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();
            }
        }
        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 static void EnforceDefaultTexture(MaterialProperty texProp, string autoTextureName)
 {
     if (texProp.textureValue == null)
     {
         Texture2D def = MicroSplatUtilities.GetAutoTexture(autoTextureName);
         if (def != null)
         {
             texProp.textureValue = def;
         }
     }
 }
 void DrawTintGUI()
 {
     if (MicroSplatUtilities.DrawRollup("Brush Settings"))
     {
         DrawBrushSettingsGUI(true);
     }
     if (GUILayout.Button("Clear Color"))
     {
         paintColor = new Color(0.5f, 0.5f, 0.5f, 0);
     }
     DrawFillGUI();
 }
        Texture2D CreateTexture(Terrain t, Texture2D tex, string texNamePostfix, Color defaultColor, bool linear)
        {
            // find/create manager
            var mgr = t.GetComponent <MicroSplatTerrain>();

            if (mgr == null)
            {
                return(null);
            }

            // if we still don't have a texture, create one
            if (tex == null)
            {
                tex = new Texture2D(t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, TextureFormat.RGBA32, false, linear);

                for (int x = 0; x < tex.width; ++x)
                {
                    for (int y = 0; y < tex.height; ++y)
                    {
                        tex.SetPixel(x, y, defaultColor);
                    }
                }
                tex.Apply();
                tex.wrapMode = TextureWrapMode.Clamp;
                var path = MicroSplatUtilities.RelativePathFromAsset(t.terrainData);
                path += "/" + t.name + texNamePostfix + ".png";
                tex   = SaveTexture(path, tex);
                var ai = AssetImporter.GetAtPath(path);
                var ti = ai as TextureImporter;
                if (ti != null)
                {
                    ti.sRGBTexture        = !linear;
                    ti.textureCompression = TextureImporterCompression.Uncompressed;
                    var ftm = ti.GetDefaultPlatformTextureSettings();
                    ftm.format = TextureImporterFormat.RGBA32;
                    ti.SetPlatformTextureSettings(ftm);

                    ti.mipmapEnabled = true;
                    ti.wrapMode      = TextureWrapMode.Clamp;
                    ti.SaveAndReimport();
                }
                mgr.Sync();
                EditorUtility.SetDirty(mgr);
            }


            return(tex);
        }
 void DrawWetnessGUI()
 {
     if (MicroSplatUtilities.DrawRollup("Brush Settings"))
     {
         DrawBrushSettingsGUI();
     }
     DrawFillGUI();
     if (MicroSplatUtilities.DrawRollup("Raycast Wetness", true, true))
     {
         EditorGUILayout.HelpBox("This utility will raycast against your terrain, generating a wetness map which will wet uncovered terrain. You can then use the maximum wetess value to remove the effect, raising it when it rains", MessageType.Info);
         if (GUILayout.Button("Calculate"))
         {
             DoWetnessRaycast();
         }
     }
 }
        void DrawSnowMaskGUI()
        {
            if (MicroSplatUtilities.DrawRollup("Brush Settings"))
            {
                DrawBrushSettingsGUI();
            }
            DrawFillGUI();

            if (MicroSplatUtilities.DrawRollup("Raycast Snow", true, true))
            {
                EditorGUILayout.HelpBox("This utility will raycast against your terrain, generating a snow mask which will prevent snow on covered terrain.", MessageType.Info);
                if (GUILayout.Button("Calculate"))
                {
                    DoSnowRaycast();
                }
            }
        }
예제 #18
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (isTessellated && mat.HasProperty("_TessData1") && MicroSplatUtilities.DrawRollup("Tessellation"))
            {
                var td1 = shaderGUI.FindProp("_TessData1", props);
                var td2 = shaderGUI.FindProp("_TessData2", props);
                EditorGUI.BeginChangeCheck();
                var td1v = td1.vectorValue;
                var td2v = td2.vectorValue;
                td1v.y = EditorGUILayout.Slider(CTessDisplacement, td1v.y, 0, 3);
                td1v.z = (float)EditorGUILayout.IntSlider(CTessMipBias, (int)td1v.z, 0, 6);
                td2v.z = 1.0f - (float)EditorGUILayout.Slider(CTessShaping, 1.0f - td2v.z, 0.0f, 0.999f);
                if (!perTexUpBias)
                {
                    td2v.w = (float)EditorGUILayout.Slider(CTessUpBias, td2v.w, 0.0f, 1);
                }

                td1v.x = EditorGUILayout.Slider(CTessTessellation, td1v.x, 1, 32);
                td2v.x = EditorGUILayout.FloatField(CTessMinDistance, td2v.x);
                td2v.y = EditorGUILayout.FloatField(CTessMaxDistance, td2v.y);

                if (EditorGUI.EndChangeCheck())
                {
                    td1.vectorValue = td1v;
                    td2.vectorValue = td2v;
                }
            }
            if (parallax && MicroSplatUtilities.DrawRollup("Parallax") && mat.HasProperty("_ParallaxParams"))
            {
                EditorGUI.BeginChangeCheck();

                var parprop = shaderGUI.FindProp("_ParallaxParams", props);

                Vector4 vec = parprop.vectorValue;
                vec.x = EditorGUILayout.Slider("Parallax Height", vec.x, 0.0f, 0.12f);
                vec.y = EditorGUILayout.FloatField("Parallax Fade Start", vec.y);
                vec.z = EditorGUILayout.FloatField("Parallax Fade Distance", vec.z);
                if (EditorGUI.EndChangeCheck())
                {
                    parprop.vectorValue = vec;
                }
            }
        }
        void DrawSettingsGUI()
        {
            EditorGUILayout.Separator();
            GUI.skin.box.normal.textColor = Color.white;
            if (MicroSplatUtilities.DrawRollup("MicroSplat Terrain Painter"))
            {
                bool oldEnabled = enabled;
                if (Event.current.isKey && Event.current.keyCode == KeyCode.Escape && Event.current.type == EventType.KeyUp)
                {
                    enabled = !enabled;
                }
                enabled = GUILayout.Toggle(enabled, "Active (ESC)");
                if (enabled != oldEnabled)
                {
                    InitTerrains();
                }

                brushVisualization = (BrushVisualization)EditorGUILayout.EnumPopup("Brush Visualization", brushVisualization);
                EditorGUILayout.Separator();
                GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
                EditorGUILayout.Separator();
            }
        }
예제 #20
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, MicroSplatKeywords keywords, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (windParticulate != ParticulateMode.None || snowParticulate != ParticulateMode.None || glitter || snowGlitter)
            {
                if (MicroSplatUtilities.DrawRollup("Wind Particulate and Glitter") && mat.HasProperty("_GlitterWind"))
                {
                    var texProp = shaderGUI.FindProp("_GlitterWind", props);
                    MicroSplatUtilities.WarnLinear(texProp.textureValue as Texture2D);
                    materialEditor.TexturePropertySingleLine(CGlitterWind, texProp);
                    MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_windglitter");

                    if ((windParticulate != ParticulateMode.None || snowParticulate != ParticulateMode.None) && mat.HasProperty("_WindParticulateRotation"))
                    {
                        EditorGUILayout.BeginHorizontal();
                        var oldEnabled = GUI.enabled;
                        if (globalWindRotation)
                        {
                            GUI.enabled = false;
                        }
                        materialEditor.ShaderProperty(shaderGUI.FindProp("_WindParticulateRotation", props), CWindRotation);
                        GUI.enabled        = oldEnabled;
                        globalWindRotation = DrawGlobalToggle(GetFeatureName(DefineFeature._GLOBALPARTICULATEROTATION), keywords);
                        EditorGUILayout.EndHorizontal();


                        if (windParticulate != ParticulateMode.None && MicroSplatUtilities.DrawRollup("Wind", true, true) && mat.HasProperty("_WindParticulateColor"))
                        {
                            materialEditor.ShaderProperty(shaderGUI.FindProp("_WindParticulateColor", props), CWindColor);

                            EditorGUILayout.BeginHorizontal();
                            oldEnabled = GUI.enabled;
                            if (globalWindStrength)
                            {
                                GUI.enabled = false;
                            }

                            materialEditor.ShaderProperty(shaderGUI.FindProp("_WindParticulateStrength", props), CWindStrength);
                            GUI.enabled        = oldEnabled;
                            globalWindStrength = DrawGlobalToggle(GetFeatureName(DefineFeature._GLOBALWINDPARTICULATESTRENGTH), keywords);
                            EditorGUILayout.EndHorizontal();


                            EditorGUI.BeginChangeCheck();
                            Vector4 speedPow = shaderGUI.FindProp("_WindParticulateParams", props).vectorValue;
                            speedPow.w = EditorGUILayout.FloatField(CWindScale, speedPow.w);
                            speedPow.x = EditorGUILayout.FloatField(CWindSpeed, speedPow.x);
                            speedPow.y = EditorGUILayout.Slider(CWindContrast, speedPow.y, 0.4f, 4.0f);
                            speedPow.z = EditorGUILayout.FloatField(CWindStretch, speedPow.z);

                            if (EditorGUI.EndChangeCheck())
                            {
                                shaderGUI.FindProp("_WindParticulateParams", props).vectorValue = speedPow;
                            }

                            if (windParticulate == ParticulateMode.ParticulateWithShadows)
                            {
                                EditorGUI.BeginChangeCheck();
                                Vector4 shadow      = shaderGUI.FindProp("_WindParticulateShadow", props).vectorValue;
                                Color   shadowColor = shaderGUI.FindProp("_WindParticulateShadowColor", props).colorValue;
                                shadowColor = EditorGUILayout.ColorField(CWindShadowColor, shadowColor);
                                shadow.x    = EditorGUILayout.Slider(CWindShadowOffset, shadow.x, 0, 0.1f);
                                shadow.y    = EditorGUILayout.Slider(CWindShadowStrength, shadow.y, 0, 2.0f);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    shaderGUI.FindProp("_WindParticulateShadow", props).vectorValue     = shadow;
                                    shaderGUI.FindProp("_WindParticulateShadowColor", props).colorValue = shadowColor;
                                }
                            }
                            if (mat.HasProperty("_WindParticulateHeightMask"))
                            {
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_WindParticulateHeightMask", props), CWindHeightMask);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_WindParticulateAngleMask", props), CWindAngleMask);
                                if (mat.HasProperty("_WindParticulateUpMask"))
                                {
                                    materialEditor.ShaderProperty(shaderGUI.FindProp("_WindParticulateUpMask", props), CUpFilterRange);
                                }
                            }

                            if (mat.HasProperty("_WindEmissive"))
                            {
                                Vector4 windEmis = shaderGUI.FindProp("_WindEmissive", props).vectorValue;
                                EditorGUI.BeginChangeCheck();
                                windEmis.x = EditorGUILayout.Slider(CWindEmissive, windEmis.x, 0, 1);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    shaderGUI.FindProp("_WindEmissive", props).vectorValue = windEmis;
                                }
                            }
                            if (mat.HasProperty("_WindParticulateOcclusionStrength"))
                            {
                                EditorGUI.BeginChangeCheck();
                                float ao = mat.GetFloat("_WindParticulateOcclusionStrength");
                                ao = EditorGUILayout.Slider(COcclusionStrength, ao, 0, 1);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    shaderGUI.FindProp("_WindParticulateOcclusionStrength", props).floatValue = ao;
                                }
                            }
                        }

                        if (snowParticulate != ParticulateMode.None && MicroSplatUtilities.DrawRollup("Snow Particulate Settings", true, true) && mat.HasProperty("_SnowParticulateColor"))
                        {
                            materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowParticulateColor", props), CWindColor);

                            EditorGUILayout.BeginHorizontal();
                            oldEnabled = GUI.enabled;
                            if (globalSnowStrength)
                            {
                                GUI.enabled = false;
                            }

                            materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowParticulateStrength", props), CWindStrength);
                            GUI.enabled        = oldEnabled;
                            globalSnowStrength = DrawGlobalToggle(GetFeatureName(DefineFeature._GLOBALSNOWPARTICULATESTRENGTH), keywords);
                            EditorGUILayout.EndHorizontal();

                            EditorGUI.BeginChangeCheck();
                            Vector4 speedPow = shaderGUI.FindProp("_SnowParticulateParams", props).vectorValue;
                            speedPow.w = EditorGUILayout.FloatField(CWindScale, speedPow.w);
                            speedPow.x = EditorGUILayout.FloatField(CWindSpeed, speedPow.x);
                            speedPow.y = EditorGUILayout.Slider(CWindContrast, speedPow.y, 0.4f, 4.0f);
                            speedPow.z = EditorGUILayout.FloatField(CWindStretch, speedPow.z);

                            if (EditorGUI.EndChangeCheck())
                            {
                                shaderGUI.FindProp("_SnowParticulateParams", props).vectorValue = speedPow;
                            }

                            if (snowParticulate == ParticulateMode.ParticulateWithShadows)
                            {
                                EditorGUI.BeginChangeCheck();
                                Vector4 shadow      = shaderGUI.FindProp("_SnowParticulateShadow", props).vectorValue;
                                Color   shadowColor = shaderGUI.FindProp("_SnowParticulateShadowColor", props).colorValue;
                                shadowColor = EditorGUILayout.ColorField(CWindShadowColor, shadowColor);
                                shadow.x    = EditorGUILayout.Slider(CWindShadowOffset, shadow.x, 0, 0.1f);
                                shadow.y    = EditorGUILayout.Slider(CWindShadowStrength, shadow.y, 0, 2.0f);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    shaderGUI.FindProp("_SnowParticulateShadow", props).vectorValue     = shadow;
                                    shaderGUI.FindProp("_SnowParticulateShadowColor", props).colorValue = shadowColor;
                                }
                            }

                            if (mat.HasProperty("_SnowParticulateHeightMask"))
                            {
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowParticulateHeightMask", props), CWindHeightMask);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowParticulateAngleMask", props), CWindAngleMask);
                                if (mat.HasProperty("_SnowParticulateUpMask"))
                                {
                                    materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowParticulateUpMask", props), CUpFilterRange);
                                }
                            }

                            if (mat.HasProperty("_WindEmissive"))
                            {
                                Vector4 windEmis = shaderGUI.FindProp("_WindEmissive", props).vectorValue;
                                EditorGUI.BeginChangeCheck();
                                windEmis.y = EditorGUILayout.Slider(CWindEmissive, windEmis.y, 0, 1);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    shaderGUI.FindProp("_WindEmissive", props).vectorValue = windEmis;
                                }
                            }

                            if (mat.HasProperty("_SnowParticulateOcclusionStrength"))
                            {
                                EditorGUI.BeginChangeCheck();
                                float ao = mat.GetFloat("_SnowParticulateOcclusionStrength");
                                ao = EditorGUILayout.Slider(COcclusionStrength, ao, 0, 1);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    shaderGUI.FindProp("_SnowParticulateOcclusionStrength", props).floatValue = ao;
                                }
                            }
                        }
                    }
                    if ((glitter || snowGlitter))
                    {
                        if (glitter && mat.HasProperty("_GlitterUVScale"))
                        {
                            if (MicroSplatUtilities.DrawRollup("Glitter", true, true))
                            {
                                var     scale = shaderGUI.FindProp("_GlitterUVScale", props);
                                Vector2 scl   = scale.vectorValue;
                                EditorGUI.BeginChangeCheck();
                                scl = EditorGUILayout.Vector2Field(CGlitterUVScale, scl);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    scale.vectorValue = scl;
                                }

                                materialEditor.ShaderProperty(shaderGUI.FindProp("_GlitterGraininess", props), CGlitterGraininess);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_GlitterShininess", props), CGlitterShininess);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_GlitterViewDep", props), CGlitterViewDep);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_GlitterStrength", props), CGlitterStrength);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_GlitterThreshold", props), CGlitterThreshold);

                                if (mat.HasProperty("_GlitterDistFade"))
                                {
                                    Vector4 fade = mat.GetVector("_GlitterDistFade");
                                    EditorGUI.BeginChangeCheck();

                                    fade.x = EditorGUILayout.FloatField("Begin Fade", fade.x);
                                    fade.z = EditorGUILayout.Slider("Opacity At Begin", fade.z, 0, 1);
                                    fade.y = EditorGUILayout.FloatField("Fade Range", fade.y);
                                    fade.w = EditorGUILayout.Slider("Opacity At End", fade.w, 0, 1);

                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        mat.SetVector("_GlitterDistFade", fade);
                                        EditorUtility.SetDirty(mat);
                                    }
                                }
                            }
                        }
                        if (snowGlitter && mat.HasProperty("_SnowGlitterUVScale"))
                        {
                            if (MicroSplatUtilities.DrawRollup("Snow Glitter", true, true))
                            {
                                var     scale = shaderGUI.FindProp("_SnowGlitterUVScale", props);
                                Vector2 scl   = scale.vectorValue;
                                EditorGUI.BeginChangeCheck();
                                scl = EditorGUILayout.Vector2Field(CGlitterUVScale, scl);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    scale.vectorValue = scl;
                                }

                                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowGlitterGraininess", props), CGlitterGraininess);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowGlitterShininess", props), CGlitterShininess);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowGlitterViewDep", props), CGlitterViewDep);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowGlitterStrength", props), CGlitterStrength);
                                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowGlitterThreshold", props), CGlitterThreshold);

                                if (mat.HasProperty("_SnowGlitterDistFade"))
                                {
                                    Vector4 fade = mat.GetVector("_SnowGlitterDistFade");
                                    EditorGUI.BeginChangeCheck();

                                    fade.x = EditorGUILayout.FloatField("Begin Fade", fade.x);
                                    fade.z = EditorGUILayout.Slider("Opacity At Begin", fade.z, 0, 1);
                                    fade.y = EditorGUILayout.FloatField("Fade Range", fade.y);
                                    fade.w = EditorGUILayout.Slider("Opacity At End", fade.w, 0, 1);

                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        mat.SetVector("_SnowGlitterDistFade", fade);
                                        EditorUtility.SetDirty(mat);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #21
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (specularFade)
            {
                if (MicroSplatUtilities.DrawRollup("Specular Height Fade") && mat.HasProperty("_SpecularFades"))
                {
                    Vector4 sf = mat.GetVector("_SpecularFades");
                    EditorGUI.BeginChangeCheck();
                    Vector2 vals = new Vector2(sf.x, sf.y);
                    vals = EditorGUILayout.Vector2Field(CSpecularHeights, vals);
                    sf.x = vals.x;
                    sf.y = vals.y;
                    if (EditorGUI.EndChangeCheck())
                    {
                        mat.SetVector("_SpecularFades", sf);
                        EditorUtility.SetDirty(mat);
                    }
                }
            }

            if (wetness || puddles || streams || lava)
            {
                if (MicroSplatUtilities.DrawRollup("Streams & Lava"))
                {
                    if (mat.HasProperty("_GlobalPorosity") && !mat.IsKeywordEnabled("_PERTEXPOROSITY"))
                    {
                        materialEditor.ShaderProperty(shaderGUI.FindProp("_GlobalPorosity", props), "Default Porosity");
                    }

                    if (wetness && mat.HasProperty("_WetnessParams"))
                    {
                        Vector4 wet = mat.GetVector("_WetnessParams");
                        EditorGUI.BeginChangeCheck();

                        EditorGUILayout.BeginHorizontal();
                        var oldEnabled = GUI.enabled;
                        if (globalWetness)
                        {
                            GUI.enabled = false;
                        }
                        EditorGUILayout.MinMaxSlider(CMinMaxWetness, ref wet.x, ref wet.y, 0, 1);
                        GUI.enabled   = oldEnabled;
                        globalWetness = DrawGlobalToggle(GetFeatureName(DefineFeature._GLOBALWETNESS), mat);
                        EditorGUILayout.EndHorizontal();

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_WetnessParams", wet);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                    if (heightWetness && mat.HasProperty("_HeightWetness"))
                    {
                        Vector4 wet = mat.GetVector("_HeightWetness");
                        EditorGUI.BeginChangeCheck();
                        wet.x = EditorGUILayout.FloatField(CHeightWetnessHeight, wet.x);
                        wet.y = EditorGUILayout.FloatField(CHeightWetnessContrast, wet.y);
                        wet.z = EditorGUILayout.FloatField(CHeightWetnessFrequency, wet.z);
                        wet.w = EditorGUILayout.FloatField(CHeightWetnessAmplitude, wet.w);
                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_HeightWetness", wet);
                            EditorUtility.SetDirty(mat);
                        }
                    }


                    // PUDDLES
                    if (puddles && mat.HasProperty("_PuddleParams") && MicroSplatUtilities.DrawRollup("Puddles", true, true))
                    {
                        Vector4 pudV = mat.GetVector("_PuddleParams");
                        EditorGUI.BeginChangeCheck();
                        pudV.x = EditorGUILayout.Slider(CPuddleBlend, pudV.x, 0.01f, 60.0f);

                        EditorGUILayout.BeginHorizontal();
                        var oldEnabled = GUI.enabled;
                        if (globalPuddles)
                        {
                            GUI.enabled = false;
                        }
                        pudV.y        = EditorGUILayout.Slider(CPuddleMax, pudV.y, 0.01f, 1.0f);
                        GUI.enabled   = oldEnabled;
                        globalPuddles = DrawGlobalToggle(GetFeatureName(DefineFeature._GLOBALPUDDLES), mat);
                        EditorGUILayout.EndHorizontal();

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_PuddleParams", pudV);
                            EditorUtility.SetDirty(mat);
                        }
                    }

                    if (rainDrops && mat.HasProperty("_RainDropTexture") && MicroSplatUtilities.DrawRollup("Rain Drops", true, true))
                    {
                        MicroSplatUtilities.EnforceDefaultTexture(shaderGUI.FindProp("_RainDropTexture", props), "microsplat_def_raindrops");
                        EditorGUI.BeginChangeCheck();
                        var rainParams = shaderGUI.FindProp("_RainIntensityScale", props);

                        Vector4 v = rainParams.vectorValue;


                        EditorGUILayout.BeginHorizontal();
                        var oldEnabled = GUI.enabled;
                        if (globalRain)
                        {
                            GUI.enabled = false;
                        }
                        v.x         = EditorGUILayout.Slider(CRainIntensity, v.x, 0, 1);
                        GUI.enabled = oldEnabled;
                        globalRain  = DrawGlobalToggle(GetFeatureName(DefineFeature._GLOBALRAIN), mat);
                        EditorGUILayout.EndHorizontal();

                        v.y = EditorGUILayout.FloatField(CRainUVScales, v.y);

                        if (EditorGUI.EndChangeCheck())
                        {
                            rainParams.vectorValue = v;
                        }
                    }


                    // Streams
                    if (streams && mat.HasProperty("_StreamBlend") && MicroSplatUtilities.DrawRollup("Streams", true, true))
                    {
                        materialEditor.TexturePropertySingleLine(CStreamFoamTex, shaderGUI.FindProp("_StreamNormal", props));
                        MicroSplatUtilities.EnforceDefaultTexture(shaderGUI.FindProp("_StreamNormal", props), "microsplat_def_streamfoam");
                        materialEditor.ShaderProperty(shaderGUI.FindProp("_StreamBlend", props), CStreamBlend);

                        EditorGUILayout.BeginHorizontal();
                        var oldEnabled = GUI.enabled;
                        if (globalStreams)
                        {
                            GUI.enabled = false;
                        }
                        materialEditor.ShaderProperty(shaderGUI.FindProp("_StreamMax", props), CMaxStream);
                        GUI.enabled   = oldEnabled;
                        globalStreams = DrawGlobalToggle(GetFeatureName(DefineFeature._GLOBALSTREAMS), mat);
                        EditorGUILayout.EndHorizontal();

                        Vector4 pudNF = mat.GetVector("_StreamNormalFoam");
                        EditorGUI.BeginChangeCheck();
                        pudNF.x = EditorGUILayout.Slider(CStreamNormalBlend, pudNF.x, 0, 1.0f);
                        pudNF.y = EditorGUILayout.Slider(CStreamFoamStr, pudNF.y, 0.0f, 35.0f);

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_StreamNormalFoam", pudNF);
                            EditorUtility.SetDirty(mat);
                        }

                        if (mat.HasProperty("_StreamFlowParams"))
                        {
                            EditorGUI.BeginChangeCheck();
                            Vector4 pudp  = mat.GetVector("_StreamFlowParams");
                            Vector4 pudUV = mat.GetVector("_StreamUVScales");
                            Vector2 puv   = new Vector2(pudUV.x, pudUV.y);
                            puv    = EditorGUILayout.Vector2Field(CStreamUVScale, puv);
                            pudp.x = EditorGUILayout.Slider(CStreamRefractionStrength, pudp.x, 0.0f, 0.5f);
                            pudp.w = EditorGUILayout.Slider(CStreamDepthDampen, pudp.w, 0.0f, 1.0f);
                            pudp.y = EditorGUILayout.FloatField(CStreamFlowSpeed, pudp.y);
                            pudp.z = EditorGUILayout.FloatField(CStreamFlowCycle, pudp.z);

                            if (EditorGUI.EndChangeCheck())
                            {
                                mat.SetVector("_StreamFlowParams", pudp);
                                mat.SetVector("_StreamUVScales", new Vector4(puv.x, puv.y, 0, 0));
                                EditorUtility.SetDirty(mat);
                            }
                        }

                        if (heightDampStreams && mat.HasProperty("_StreamFades"))
                        {
                            materialEditor.ShaderProperty(shaderGUI.FindProp("_StreamFades", props), CHeightDamp);
                        }
                    }



                    if (lava && mat.HasProperty("_LavaParams2") && MicroSplatUtilities.DrawRollup("Lava", true, true))
                    {
                        materialEditor.TexturePropertySingleLine(CLavaDiffuse, shaderGUI.FindProp("_LavaDiffuse", props));
                        MicroSplatUtilities.EnforceDefaultTexture(shaderGUI.FindProp("_LavaDiffuse", props), "microsplat_def_lava_01");
                        EditorGUI.BeginChangeCheck();
                        Vector4 lavaUVs = mat.GetVector("_LavaUVScale");
                        Vector2 luv     = new Vector2(lavaUVs.x, lavaUVs.y);
                        luv       = EditorGUILayout.Vector2Field(CLavaUVScale, luv);
                        lavaUVs.x = luv.x;
                        lavaUVs.y = luv.y;
                        Vector4 lavaParams = mat.GetVector("_LavaParams");


                        lavaParams.x = EditorGUILayout.Slider(CLavaBlend, lavaParams.x, 2.0f, 40.0f);
                        lavaParams.y = EditorGUILayout.Slider(CLavaMax, lavaParams.y, 0.0f, 1.0f);
                        lavaParams.z = EditorGUILayout.FloatField(CLavaSpeed, lavaParams.z);
                        lavaParams.w = EditorGUILayout.FloatField(CLavaIntensity, lavaParams.w);

                        Vector4 lavaParams2 = mat.GetVector("_LavaParams2");
                        lavaParams2.w = EditorGUILayout.Slider(CLavaDarkening, lavaParams2.w, 0.0f, 6.0f);
                        lavaParams2.x = EditorGUILayout.Slider(CLavaDistSize, lavaParams2.x, 0.0f, 0.3f);
                        lavaParams2.y = EditorGUILayout.Slider(CLavaDistRate, lavaParams2.y, 0.0f, 0.08f);
                        lavaParams2.z = EditorGUILayout.Slider(CLavaDistScale, lavaParams2.z, 0.02f, 1.0f);

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_LavaParams", lavaParams);
                            mat.SetVector("_LavaParams2", lavaParams2);
                            mat.SetVector("_LavaUVScale", lavaUVs);
                            EditorUtility.SetDirty(mat);
                        }
                        materialEditor.ShaderProperty(shaderGUI.FindProp("_LavaColorLow", props), CLavaColor);
                        materialEditor.ShaderProperty(shaderGUI.FindProp("_LavaColorHighlight", props), CLavaHighlightColor);
                        materialEditor.ShaderProperty(shaderGUI.FindProp("_LavaEdgeColor", props), CLavaEdgeColor);
                        if (mat.IsKeywordEnabled("_TESSDISTANCE") && mat.HasProperty("_LavaDislacementScale"))
                        {
                            materialEditor.ShaderProperty(shaderGUI.FindProp("_LavaDislacementScale", props), CLavaDisplacementScale);
                        }

                        if (heightDampLava && mat.HasProperty("_LavaFades"))
                        {
                            materialEditor.ShaderProperty(shaderGUI.FindProp("_LavaFades", props), CHeightDamp);
                        }
                    }
                }
            }
        }
        void DrawScatterGUI()
        {
            if (MicroSplatUtilities.DrawRollup("Brush Settings"))
            {
                brushSize    = EditorGUILayout.Slider("Brush Size", brushSize, 0.01f, 30.0f);
                brushFlow    = EditorGUILayout.Slider("Brush Flow", brushFlow, 0.1f, 128.0f);
                brushFalloff = EditorGUILayout.Slider("Brush Falloff", brushFalloff, 0.1f, 3.5f);


                Material tempMat = null;
                for (int i = 0; i < rawTerrains.Count; ++i)
                {
                    Terrain           t   = rawTerrains [i];
                    MicroSplatTerrain mst = t.GetComponent <MicroSplatTerrain> ();
                    if (mst != null)
                    {
                        if (mst.templateMaterial != null && mst.templateMaterial.HasProperty("_ScatterDiffuse"))
                        {
                            Texture2DArray diff = mst.templateMaterial.GetTexture("_ScatterDiffuse") as Texture2DArray;
                            scatterIndex = MicroSplatUtilities.DrawTextureSelector(scatterIndex, diff, false);
                            tempMat      = mst.templateMaterial;
                        }
                        else
                        {
                            scatterIndex = EditorGUILayout.IntField("Scatter Index", scatterIndex);
                        }
                    }
                    else
                    {
                        scatterIndex = EditorGUILayout.IntField("Scatter Index", scatterIndex);
                    }
                }


                //EditorGUILayout.MinMaxSlider (CSlopeRange, ref slopeRange.x, ref slopeRange.y, 0.0f, 1.0f);

                paintValue = EditorGUILayout.Slider("Target Opacity", paintValue, 0.0f, 1.0f);



#if __MICROSPLAT_SCATTER__
                if (tempMat != null)
                {
                    scatterLayer = (ScatterLayer)EditorGUILayout.EnumPopup(CScatterLayer, scatterLayer);
                    EditorGUILayout.Separator();

                    using (new GUILayout.VerticalScope(GUI.skin.box))
                    {
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.LabelField("Per Texture Properties");
                        bool changed = MicroSplatScatter.DrawPerTexExternal(tempMat, scatterIndex);
                        EditorGUILayout.Separator();
                        // sync compile changes
                        if (changed)
                        {
                            MicroSplatShaderGUI.MicroSplatCompiler comp = new MicroSplatShaderGUI.MicroSplatCompiler();
                            comp.Init();
                            comp.Compile(tempMat);
                        }
                        // sync property changes
                        if (EditorGUI.EndChangeCheck())
                        {
                            MicroSplatObject.SyncAll();
                        }
                    }
                }
#endif
                GUILayout.Box("", new GUILayoutOption [] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
                EditorGUILayout.Separator();
            }
            DrawFillGUI();
        }
예제 #23
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (geoTexture && MicroSplatUtilities.DrawRollup("Geo Texture"))
            {
                if (mat.HasProperty("_GeoTex"))
                {
                    var texProp = shaderGUI.FindProp("_GeoTex", props);
                    materialEditor.TexturePropertySingleLine(CGeoTex, texProp);
                    MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_geomap_01");

                    Vector4 parms = mat.GetVector("_GeoParams");
                    EditorGUI.BeginChangeCheck();
                    parms.x = EditorGUILayout.Slider("Blend", parms.x, 0, 1);
                    parms.y = 1.0f / Mathf.Max(parms.y, 0.00001f);
                    parms.y = EditorGUILayout.FloatField("World Scale", parms.y);
                    parms.y = 1.0f / Mathf.Max(parms.y, 0.00001f);
                    parms.z = EditorGUILayout.FloatField("World Offset", parms.z);
                    if (EditorGUI.EndChangeCheck())
                    {
                        mat.SetVector("_GeoParams", parms);
                        EditorUtility.SetDirty(mat);
                    }
                    if (geoRange && mat.HasProperty("_GeoRange"))
                    {
                        Vector4 rangeParams = mat.GetVector("_GeoRange");
                        EditorGUI.BeginChangeCheck();
                        rangeParams = EditorGUILayout.Vector4Field(CGeoRange, rangeParams);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (rangeParams.z < rangeParams.x || rangeParams.z < rangeParams.y)
                            {
                                rangeParams.z = rangeParams.y;
                            }
                            if (rangeParams.y < rangeParams.x)
                            {
                                rangeParams.y = rangeParams.x;
                            }
                            if (rangeParams.w < rangeParams.z)
                            {
                                rangeParams.z = rangeParams.w;
                            }

                            mat.SetVector("_GeoRange", rangeParams);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                    if (geoCurve && mat.HasProperty("_GeoCurveParams"))
                    {
                        var propData = MicroSplatShaderGUI.FindOrCreatePropTex(mat);
                        EditorGUI.BeginChangeCheck();
                        if (propData != null)
                        {
                            propData.geoCurve = EditorGUILayout.CurveField(CGeoCurve, propData.geoCurve);
                        }
                        Vector4 curveParams = mat.GetVector("_GeoCurveParams");
                        curveParams.x = EditorGUILayout.FloatField("Scale", curveParams.x);
                        curveParams.y = EditorGUILayout.FloatField("Offset", curveParams.y);
                        curveParams.z = EditorGUILayout.FloatField("Rotation", curveParams.z);

                        if (EditorGUI.EndChangeCheck())
                        {
                            AnimationCurve c = propData.geoCurve;
                            for (int i = 0; i < c.length; ++i)
                            {
                                c.keys[i].time = Mathf.Clamp01(c.keys[i].time);
                            }
                            mat.SetVector("_GeoCurveParams", curveParams);
                            EditorUtility.SetDirty(mat);
                            EditorUtility.SetDirty(propData);
                            MicroSplatTerrain.SyncAll();
                        }
                    }
                }
            }
            if ((tintBlendMode != BlendMode.Off || normalBlendMode != NormalBlendMode.Off || SAOMBlend != SAOMBlendMode.Off || emisBlend != SAOMBlendMode.Off) && MicroSplatUtilities.DrawRollup("Global Texture"))
            {
                if (tintBlendMode != BlendMode.Off && mat.HasProperty("_GlobalTintTex"))
                {
                    materialEditor.TexturePropertySingleLine(new GUIContent("Tint Texture", "Albedo Tint Texture"), shaderGUI.FindProp("_GlobalTintTex", props));
                    Vector4 parms = mat.GetVector("_GlobalTextureParams");
                    EditorGUI.BeginChangeCheck();
                    parms.x = EditorGUILayout.Slider("Blend", parms.x, 0, 1);
                    if (EditorGUI.EndChangeCheck())
                    {
                        mat.SetVector("_GlobalTextureParams", parms);
                        EditorUtility.SetDirty(mat);
                    }
                    if (mat.HasProperty("_GlobalTintFade"))
                    {
                        Vector4 fade = mat.GetVector("_GlobalTintFade");
                        EditorGUI.BeginChangeCheck();

                        fade.x = EditorGUILayout.FloatField("Begin Fade", fade.x);
                        fade.z = EditorGUILayout.Slider("Opacity At Begin", fade.z, 0, 1);
                        fade.y = EditorGUILayout.FloatField("Fade Range", fade.y);
                        fade.w = EditorGUILayout.Slider("Opacity At End", fade.w, 0, 1);

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_GlobalTintFade", fade);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                    if (mat.HasProperty("_GlobalTintUVScale"))
                    {
                        Vector4 uv     = mat.GetVector("_GlobalTintUVScale");
                        Vector2 scale  = new Vector2(uv.x, uv.y);
                        Vector2 offset = new Vector2(uv.z, uv.w);

                        EditorGUI.BeginChangeCheck();
                        scale  = EditorGUILayout.Vector2Field(CUVScale, scale);
                        offset = EditorGUILayout.Vector2Field(CUVOffset, offset);

                        if (EditorGUI.EndChangeCheck())
                        {
                            uv = new Vector4(scale.x, scale.y, offset.x, offset.y);
                            mat.SetVector("_GlobalTintUVScale", uv);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                }
                if (normalBlendMode != NormalBlendMode.Off && mat.HasProperty("_GlobalNormalTex"))
                {
                    materialEditor.TexturePropertySingleLine(new GUIContent("Normal Texture", "Global Normal Texture"), shaderGUI.FindProp("_GlobalNormalTex", props));
                    Vector4 parms = mat.GetVector("_GlobalTextureParams");
                    EditorGUI.BeginChangeCheck();
                    parms.y = EditorGUILayout.Slider("Blend", parms.y, 0, 3);
                    if (EditorGUI.EndChangeCheck())
                    {
                        mat.SetVector("_GlobalTextureParams", parms);
                        EditorUtility.SetDirty(mat);
                    }

                    if (mat.HasProperty("_GlobalNormalFade"))
                    {
                        Vector4 fade = mat.GetVector("_GlobalNormalFade");
                        EditorGUI.BeginChangeCheck();

                        fade.x = EditorGUILayout.FloatField("Begin Fade", fade.x);
                        fade.z = EditorGUILayout.Slider("Opacity At Begin", fade.z, 0, 1);
                        fade.y = EditorGUILayout.FloatField("Fade Range", fade.y);
                        fade.w = EditorGUILayout.Slider("Opacity At End", fade.w, 0, 1);

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_GlobalNormalFade", fade);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                    if (mat.HasProperty("_GlobalNormalUVScale"))
                    {
                        Vector4 uv     = mat.GetVector("_GlobalNormalUVScale");
                        Vector2 scale  = new Vector2(uv.x, uv.y);
                        Vector2 offset = new Vector2(uv.z, uv.w);

                        EditorGUI.BeginChangeCheck();
                        scale  = EditorGUILayout.Vector2Field(CUVScale, scale);
                        offset = EditorGUILayout.Vector2Field(CUVOffset, offset);

                        if (EditorGUI.EndChangeCheck())
                        {
                            uv = new Vector4(scale.x, scale.y, offset.x, offset.y);
                            mat.SetVector("_GlobalNormalUVScale", uv);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                }
                // saom
                if (SAOMBlend != SAOMBlendMode.Off && mat.HasProperty("_GlobalSAOMTex"))
                {
                    materialEditor.TexturePropertySingleLine(new GUIContent("Smoothness(R)/AO(G)/Metal(B) Texture", "Global smoothness, ao, metallic Texture"), shaderGUI.FindProp("_GlobalSAOMTex", props));
                    Vector4 parms = mat.GetVector("_GlobalTextureParams");
                    EditorGUI.BeginChangeCheck();
                    parms.z = EditorGUILayout.Slider("Blend", parms.z, 0, 3);
                    if (EditorGUI.EndChangeCheck())
                    {
                        mat.SetVector("_GlobalTextureParams", parms);
                        EditorUtility.SetDirty(mat);
                    }

                    if (mat.HasProperty("_GlobalSAOMFade"))
                    {
                        Vector4 fade = mat.GetVector("_GlobalSAOMFade");
                        EditorGUI.BeginChangeCheck();

                        fade.x = EditorGUILayout.FloatField("Begin Fade", fade.x);
                        fade.z = EditorGUILayout.Slider("Opacity At Begin", fade.z, 0, 1);
                        fade.y = EditorGUILayout.FloatField("Fade Range", fade.y);
                        fade.w = EditorGUILayout.Slider("Opacity At End", fade.w, 0, 1);

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_GlobalSAOMFade", fade);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                    if (mat.HasProperty("_GlobalSAOMUVScale"))
                    {
                        Vector4 uv     = mat.GetVector("_GlobalSAOMUVScale");
                        Vector2 scale  = new Vector2(uv.x, uv.y);
                        Vector2 offset = new Vector2(uv.z, uv.w);

                        EditorGUI.BeginChangeCheck();
                        scale  = EditorGUILayout.Vector2Field(CUVScale, scale);
                        offset = EditorGUILayout.Vector2Field(CUVOffset, offset);

                        if (EditorGUI.EndChangeCheck())
                        {
                            uv = new Vector4(scale.x, scale.y, offset.x, offset.y);
                            mat.SetVector("_GlobalSAOMUVScale", uv);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                }

                // emis
                if (emisBlend != SAOMBlendMode.Off && mat.HasProperty("_GlobalEmisTex"))
                {
                    materialEditor.TexturePropertySingleLine(new GUIContent("Emission Texture", "Global Emission"), shaderGUI.FindProp("_GlobalEmisTex", props));
                    Vector4 parms = mat.GetVector("_GlobalTextureParams");
                    EditorGUI.BeginChangeCheck();
                    parms.w = EditorGUILayout.Slider("Blend", parms.w, 0, 3);
                    if (EditorGUI.EndChangeCheck())
                    {
                        mat.SetVector("_GlobalTextureParams", parms);
                        EditorUtility.SetDirty(mat);
                    }

                    if (mat.HasProperty("_GlobalEmisFade"))
                    {
                        Vector4 fade = mat.GetVector("_GlobalEmisFade");
                        EditorGUI.BeginChangeCheck();

                        fade.x = EditorGUILayout.FloatField("Begin Fade", fade.x);
                        fade.z = EditorGUILayout.Slider("Opacity At Begin", fade.z, 0, 1);
                        fade.y = EditorGUILayout.FloatField("Fade Range", fade.y);
                        fade.w = EditorGUILayout.Slider("Opacity At End", fade.w, 0, 1);

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_GlobalEmisFade", fade);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                    if (mat.HasProperty("_GlobalEmisUVScale"))
                    {
                        Vector4 uv     = mat.GetVector("_GlobalEmisUVScale");
                        Vector2 scale  = new Vector2(uv.x, uv.y);
                        Vector2 offset = new Vector2(uv.z, uv.w);

                        EditorGUI.BeginChangeCheck();
                        scale  = EditorGUILayout.Vector2Field(CUVScale, scale);
                        offset = EditorGUILayout.Vector2Field(CUVOffset, offset);

                        if (EditorGUI.EndChangeCheck())
                        {
                            uv = new Vector4(scale.x, scale.y, offset.x, offset.y);
                            mat.SetVector("_GlobalEmisUVScale", uv);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                }
            }
        }
예제 #24
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (clusterMode != ClusterMode.None)
            {
                if (MicroSplatUtilities.DrawRollup("Texture Clustering"))
                {
                    if (clusterMode == ClusterMode.Stochastic)
                    {
                        if (mat.HasProperty("_StochasticContrast"))
                        {
                            materialEditor.RangeProperty(shaderGUI.FindProp("_StochasticContrast", props), "Blend Contrast");
                        }
                        if (mat.HasProperty("_StochasticScale"))
                        {
                            materialEditor.RangeProperty(shaderGUI.FindProp("_StochasticScale", props), "Noise Scale");
                        }
                    }
                    else
                    {
                        if (mat.HasProperty("_ClusterNoise"))
                        {
                            var noiseMap    = shaderGUI.FindProp("_ClusterNoise", props);
                            var albedoMap   = shaderGUI.FindProp("_ClusterDiffuse2", props);
                            var normalMap   = shaderGUI.FindProp("_ClusterNormal2", props);
                            var noiseParams = shaderGUI.FindProp("_ClusterParams", props);


                            materialEditor.TexturePropertySingleLine(CAlbedoTex2, albedoMap);
                            materialEditor.TexturePropertySingleLine(CNormalTex2, normalMap);

                            if (mat.HasProperty("_ClusterSmoothAO2"))
                            {
                                var smoothAO = shaderGUI.FindProp("_ClusterSmoothAO2", props);
                                materialEditor.TexturePropertySingleLine(CSmoothAO2, smoothAO);
                            }

                            if (mat.HasProperty("_ClusterEmissiveMetal2"))
                            {
                                var emis2 = shaderGUI.FindProp("_ClusterEmissiveMetal2", props);
                                materialEditor.TexturePropertySingleLine(CEmis2, emis2);
                            }



                            if (clusterMode == ClusterMode.ThreeVariants)
                            {
                                var albedoMap3 = shaderGUI.FindProp("_ClusterDiffuse3", props);
                                var normalMap3 = shaderGUI.FindProp("_ClusterNormal3", props);

                                materialEditor.TexturePropertySingleLine(CAlbedoTex3, albedoMap3);
                                materialEditor.TexturePropertySingleLine(CNormalTex3, normalMap3);

                                if (mat.HasProperty("_ClusterSmoothAO3"))
                                {
                                    var smoothAO = shaderGUI.FindProp("_ClusterSmoothAO3", props);
                                    materialEditor.TexturePropertySingleLine(CSmoothAO3, smoothAO);
                                }


                                if (mat.HasProperty("_ClusterEmissiveMetal3"))
                                {
                                    var emis3 = shaderGUI.FindProp("_ClusterEmissiveMetal3", props);
                                    materialEditor.TexturePropertySingleLine(CEmis3, emis3);
                                }
                            }

                            materialEditor.TexturePropertySingleLine(CNoiseTex, noiseMap);
                            MicroSplatUtilities.EnforceDefaultTexture(noiseMap, "microsplat_def_clusternoise");
                            if (secondNoise && mat.HasProperty("_ClusterNoise2"))
                            {
                                var noiseMap2 = shaderGUI.FindProp("_ClusterNoise2", props);
                                materialEditor.TexturePropertySingleLine(CNoiseTex, noiseMap2);
                                MicroSplatUtilities.EnforceDefaultTexture(noiseMap, "microsplat_def_clusternoise");
                            }

                            bool enabled = GUI.enabled;
                            if (perTexClusterContrast)
                            {
                                GUI.enabled = false;
                            }
                            var contrastProp = shaderGUI.FindProp("_ClusterContrast", props);
                            contrastProp.floatValue = EditorGUILayout.Slider(CInterpContrast, contrastProp.floatValue, 1.0f, 0.0001f);
                            if (perTexClusterContrast)
                            {
                                GUI.enabled = enabled;
                            }

                            if (perTexClusterBoost)
                            {
                                GUI.enabled = false;
                            }
                            var boostProp = shaderGUI.FindProp("_ClusterBoost", props);
                            boostProp.floatValue = EditorGUILayout.Slider(CClusterBoost, boostProp.floatValue, 0.5f, 4.0f);
                            if (perTexClusterBoost)
                            {
                                GUI.enabled = enabled;
                            }


                            var skew = shaderGUI.FindProp("_ClusterScaleVar", props);
                            skew.floatValue = EditorGUILayout.Slider(CClusterScale, skew.floatValue, 0.0f, 0.2f);


                            {
                                Vector4 vec = noiseParams.vectorValue;
                                EditorGUI.BeginChangeCheck();
                                Vector2 scale  = new Vector2(vec.x, vec.y);
                                Vector2 offset = new Vector2(vec.z, vec.w);

                                scale  = EditorGUILayout.Vector2Field("Scale", scale);
                                offset = EditorGUILayout.Vector2Field("Offset", offset);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    vec.x = scale.x;
                                    vec.y = scale.y;
                                    vec.z = offset.x;
                                    vec.w = offset.y;
                                    noiseParams.vectorValue = vec;
                                }
                            }
                            if (mat.HasProperty("_ClusterParams2"))
                            {
                                EditorGUILayout.LabelField("Second Octave Noise");
                                var     noiseParams2 = shaderGUI.FindProp("_ClusterParams2", props);
                                Vector4 vec          = noiseParams2.vectorValue;
                                EditorGUI.BeginChangeCheck();
                                Vector2 scale  = new Vector2(vec.x, vec.y);
                                Vector2 offset = new Vector2(vec.z, vec.w);

                                scale  = EditorGUILayout.Vector2Field("Scale", scale);
                                offset = EditorGUILayout.Vector2Field("Offset", offset);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    vec.x = scale.x;
                                    vec.y = scale.y;
                                    vec.z = offset.x;
                                    vec.w = offset.y;
                                    noiseParams2.vectorValue = vec;
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #25
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (detailNoise)
            {
                if (MicroSplatUtilities.DrawRollup("Detail Noise"))
                {
                    if (mat.HasProperty("_DetailNoise"))
                    {
                        var texProp = shaderGUI.FindProp("_DetailNoise", props);
                        MicroSplatUtilities.WarnLinear(texProp.textureValue as Texture2D);
                        materialEditor.TexturePropertySingleLine(CDetailNoiseTex, texProp);
                        MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_detail_noise");

                        Vector4 scaleStr    = shaderGUI.FindProp("_DetailNoiseScaleStrengthFade", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Strength", scaleStr.y);
                        newScaleStr.z = EditorGUILayout.FloatField("Fade Distance", scaleStr.z);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_DetailNoiseScaleStrengthFade", props).vectorValue = newScaleStr;
                        }
                    }
                }
            }

            if (distanceNoise)
            {
                if (MicroSplatUtilities.DrawRollup("Distance Noise"))
                {
                    if (mat.HasProperty("_DistanceNoise"))
                    {
                        var texProp = shaderGUI.FindProp("_DistanceNoise", props);
                        MicroSplatUtilities.WarnLinear(texProp.textureValue as Texture2D);
                        materialEditor.TexturePropertySingleLine(CDistanceNoiseTex, texProp);
                        MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_detail_noise");

                        Vector4 scaleStr    = shaderGUI.FindProp("_DistanceNoiseScaleStrengthFade", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Strength", scaleStr.y);
                        newScaleStr.z = EditorGUILayout.FloatField("Fade Start", scaleStr.z);
                        newScaleStr.w = EditorGUILayout.FloatField("Fade End", scaleStr.w);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_DistanceNoiseScaleStrengthFade", props).vectorValue = newScaleStr;
                        }
                    }
                }
            }
            if (distanceResample != DistanceResampleMode.None && mat.HasProperty("_ResampleDistanceParams"))
            {
                if (MicroSplatUtilities.DrawRollup("Distance Resample"))
                {
                    if (distanceResampleFade == DistanceResampleFade.CrossFade && mat.HasProperty("_ResampleDistanceParams"))
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector4 vec = mat.GetVector("_ResampleDistanceParams");
                        vec.x = EditorGUILayout.FloatField("Resample UV Scale", vec.x);

                        Vector2 xy = EditorGUILayout.Vector2Field("Resample Begin/End", new Vector2(vec.y, vec.z));
                        if (EditorGUI.EndChangeCheck())
                        {
                            vec.y = xy.x;
                            vec.z = xy.y;
                            mat.SetVector("_ResampleDistanceParams", vec);
                            EditorUtility.SetDirty(mat);
                        }
                    }
                    else
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector4 vec = mat.GetVector("_ResampleDistanceParams");
                        vec.x = EditorGUILayout.FloatField("Resample UV Scale", vec.x);

                        if (EditorGUI.EndChangeCheck())
                        {
                            mat.SetVector("_ResampleDistanceParams", vec);
                            EditorUtility.SetDirty(mat);
                        }
                    }

                    if (distanceResampleFade == DistanceResampleFade.Constant || distanceResampleFade == DistanceResampleFade.Noise)
                    {
                        var prop = shaderGUI.FindProp("_DistanceResampleConstant", props);
                        materialEditor.RangeProperty(prop, "Distance Resample Constant");
                    }
                    if (distanceResampleFade == DistanceResampleFade.Noise)
                    {
                        var     prop = shaderGUI.FindProp("_DistanceResampleNoiseParams", props);
                        Vector2 vals = new Vector2(prop.vectorValue.x, prop.vectorValue.y);
                        EditorGUI.BeginChangeCheck();
                        vals = EditorGUILayout.Vector2Field("Noise Freq and Amp", vals);
                        if (EditorGUI.EndChangeCheck())
                        {
                            prop.vectorValue = new Vector4(vals.x, vals.y, 0, 0);
                        }
                    }
                }
            }
            if (noiseChannelCount != NormalNoiseChannels.Off && mat.HasProperty("_NormalNoiseScaleStrength"))
            {
                if (MicroSplatUtilities.DrawRollup("Normal Noise"))
                {
                    {
                        var texProp = shaderGUI.FindProp("_NormalNoise", props);
                        materialEditor.TexturePropertySingleLine(CNormalNoiseTex, texProp);
                        MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_detail_normal_01");

                        Vector4 scaleStr    = shaderGUI.FindProp("_NormalNoiseScaleStrength", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Strength", scaleStr.y);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_NormalNoiseScaleStrength", props).vectorValue = newScaleStr;
                        }
                    }
                    if (noiseChannelCount == NormalNoiseChannels.Two || noiseChannelCount == NormalNoiseChannels.Three)
                    {
                        if (mat.HasProperty("_NormalNoiseScaleStrength2"))
                        {
                            var texProp = shaderGUI.FindProp("_NormalNoise2", props);
                            materialEditor.TexturePropertySingleLine(CNormalNoiseTex, texProp);
                            MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_detail_normal_02");

                            Vector4 scaleStr    = shaderGUI.FindProp("_NormalNoiseScaleStrength2", props).vectorValue;
                            Vector4 newScaleStr = scaleStr;
                            newScaleStr.x = EditorGUILayout.FloatField("Scale", scaleStr.x);
                            newScaleStr.y = EditorGUILayout.FloatField("Strength", scaleStr.y);
                            if (newScaleStr != scaleStr)
                            {
                                shaderGUI.FindProp("_NormalNoiseScaleStrength2", props).vectorValue = newScaleStr;
                            }
                        }
                    }
                    if (noiseChannelCount == NormalNoiseChannels.Three)
                    {
                        if (mat.HasProperty("_NormalNoiseScaleStrength3"))
                        {
                            var texProp = shaderGUI.FindProp("_NormalNoise3", props);
                            materialEditor.TexturePropertySingleLine(CNormalNoiseTex, texProp);
                            MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_detail_normal_03");

                            Vector4 scaleStr    = shaderGUI.FindProp("_NormalNoiseScaleStrength3", props).vectorValue;
                            Vector4 newScaleStr = scaleStr;
                            newScaleStr.x = EditorGUILayout.FloatField("Scale", scaleStr.x);
                            newScaleStr.y = EditorGUILayout.FloatField("Strength", scaleStr.y);
                            if (newScaleStr != scaleStr)
                            {
                                shaderGUI.FindProp("_NormalNoiseScaleStrength3", props).vectorValue = newScaleStr;
                            }
                        }
                    }
                }
            }
            if (antiTileOptions != 0)
            {
                if (MicroSplatUtilities.DrawRollup("Anti Tile Array") && mat.HasProperty("_AntiTileArray"))
                {
                    var array = shaderGUI.FindProp("_AntiTileArray", props);
                    materialEditor.TexturePropertySingleLine(CAntiTileArray, array);

                    if (mat.HasProperty("_AntiTileNormalNoiseScaleStr") && (((int)antiTileOptions & (int)AntiTileOptions.NoiseNormal) != 0))
                    {
                        Vector4 scaleStr    = shaderGUI.FindProp("_AntiTileNormalNoiseScaleStr", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Normal Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Normal Strength", scaleStr.y);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_AntiTileNormalNoiseScaleStr", props).vectorValue = newScaleStr;
                        }
                        EditorGUILayout.Space();
                    }
                    if (mat.HasProperty("_AntiTileDetailNoiseScaleFadeStr") && (((int)antiTileOptions & (int)AntiTileOptions.DetailNoise) != 0))
                    {
                        Vector4 scaleStr    = shaderGUI.FindProp("_AntiTileDetailNoiseScaleFadeStr", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Detail Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Detail Fade Distance", scaleStr.y);
                        newScaleStr.z = EditorGUILayout.FloatField("Detail Strength", scaleStr.z);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_AntiTileDetailNoiseScaleFadeStr", props).vectorValue = newScaleStr;
                        }
                        EditorGUILayout.Space();
                    }
                    if (mat.HasProperty("_AntiTileDistanceNoiseScaleFadeStr") && (((int)antiTileOptions & (int)AntiTileOptions.DistanceNoise) != 0))
                    {
                        Vector4 scaleStr    = shaderGUI.FindProp("_AntiTileDistanceNoiseScaleFadeStr", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Distance Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Distance Fade Start", scaleStr.y);
                        newScaleStr.z = EditorGUILayout.FloatField("Distance Fade End", scaleStr.z);
                        newScaleStr.w = EditorGUILayout.FloatField("Distance Strength", scaleStr.w);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_AntiTileDistanceNoiseScaleFadeStr", props).vectorValue = newScaleStr;
                        }
                    }
                }
            }
        }
예제 #26
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (snow && mat.HasProperty("_SnowParams") && MicroSplatUtilities.DrawRollup("Snow"))
            {
                var snowDiff = shaderGUI.FindProp("_SnowDiff", props);
                var snowNorm = shaderGUI.FindProp("_SnowNormal", props);
                materialEditor.TexturePropertySingleLine(CDiffTex, snowDiff);
                materialEditor.TexturePropertySingleLine(CNormTex, snowNorm);
                MicroSplatUtilities.EnforceDefaultTexture(snowDiff, "microsplat_def_snow_diff");
                MicroSplatUtilities.EnforceDefaultTexture(snowNorm, "microsplat_def_snow_normsao");

                if (mat.HasProperty("_SnowUVScales"))
                {
                    Vector4 snowUV = shaderGUI.FindProp("_SnowUVScales", props).vectorValue;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("UV Scale");
                    snowUV.x = EditorGUILayout.FloatField(snowUV.x);
                    snowUV.y = EditorGUILayout.FloatField(snowUV.y);
                    EditorGUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        shaderGUI.FindProp("_SnowUVScales", props).vectorValue = snowUV;
                        EditorUtility.SetDirty(mat);
                    }
                }

                if (snowFootsteps && mat.HasProperty("_SnowTrackDiff"))
                {
                    var trackDiff = shaderGUI.FindProp("_SnowTrackDiff", props);
                    var trackNorm = shaderGUI.FindProp("_SnowTrackNSAO", props);
                    materialEditor.TexturePropertySingleLine(CFootstepDiffTex, trackDiff);
                    materialEditor.TexturePropertySingleLine(CFootstepNormTex, trackNorm);
                    MicroSplatUtilities.EnforceDefaultTexture(trackDiff, "microsplat_def_snow_footstep_diff");
                    MicroSplatUtilities.EnforceDefaultTexture(trackNorm, "microsplat_def_snow_footstep_normsao");
                    Vector4 snowUV = shaderGUI.FindProp("_SnowFootstepUVScales", props).vectorValue;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Footstep UV Scale");
                    snowUV.x = EditorGUILayout.FloatField(snowUV.x);
                    snowUV.y = EditorGUILayout.FloatField(snowUV.y);
                    EditorGUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        shaderGUI.FindProp("_SnowFootstepUVScales", props).vectorValue = snowUV;
                        EditorUtility.SetDirty(mat);
                    }
                }



                // influence, erosion, crystal, melt
                Vector4 p1 = shaderGUI.FindProp("_SnowParams", props).vectorValue;
                Vector4 hr = shaderGUI.FindProp("_SnowHeightAngleRange", props).vectorValue;

                EditorGUILayout.BeginHorizontal();
                bool oldEnabled = GUI.enabled;
                if (globalLevel)
                {
                    GUI.enabled = false;
                }
                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowAmount", props), "Amount");
                GUI.enabled = oldEnabled;
                globalLevel = DrawGlobalToggle(GetFeatureName(SnowDefineFeature._USEGLOBALSNOWLEVEL), mat);
                EditorGUILayout.EndHorizontal();

                EditorGUI.BeginChangeCheck();

                p1.x = EditorGUILayout.Slider(CHeightClear, p1.x, 0, 1);
                p1.y = EditorGUILayout.Slider(CErosionClearing, p1.y, 0, 1);
                EditorGUILayout.BeginHorizontal();
                oldEnabled = GUI.enabled;
                if (globalHeight)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PrefixLabel(CHeightRange);
                hr.x         = EditorGUILayout.FloatField(hr.x);
                hr.y         = EditorGUILayout.FloatField(hr.y);
                GUI.enabled  = oldEnabled;
                globalHeight = DrawGlobalToggle(GetFeatureName(SnowDefineFeature._USEGLOBALSNOWHEIGHT), mat);
                EditorGUILayout.EndHorizontal();


                hr.z = 1.0f - hr.z;
                hr.w = 1.0f - hr.w;
                EditorGUILayout.MinMaxSlider(CAngleRange, ref hr.w, ref hr.z, 0.0f, 1.0f);
                hr.z = 1.0f - hr.z;
                hr.w = 1.0f - hr.w;

                p1.z = EditorGUILayout.FloatField(CCrystals, p1.z);
                p1.w = EditorGUILayout.Slider(CMelt, p1.w, 0, 0.6f);

                if (EditorGUI.EndChangeCheck())
                {
                    shaderGUI.FindProp("_SnowParams", props).vectorValue           = p1;
                    shaderGUI.FindProp("_SnowHeightAngleRange", props).vectorValue = hr;
                }

                Vector4 up = mat.GetVector("_SnowUpVector");
                EditorGUI.BeginChangeCheck();
                Vector3 newUp = EditorGUILayout.Vector3Field(CUpVector, new Vector3(up.x, up.y, up.z));
                if (EditorGUI.EndChangeCheck())
                {
                    newUp.Normalize();
                    mat.SetVector("_SnowUpVector", new Vector4(newUp.x, newUp.y, newUp.z, 0));
                    EditorUtility.SetDirty(mat);
                }

                if (snowNormalNoise)
                {
                    if (mat.HasProperty("_SnowNormalNoise"))
                    {
                        var texProp = shaderGUI.FindProp("_SnowNormalNoise", props);
                        materialEditor.TexturePropertySingleLine(CDistanceNoise, texProp);
                        MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_snow_normalnoise");


                        Vector4 scaleStr    = shaderGUI.FindProp("_SnowNormalNoiseScaleStrength", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Noise UV Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Noise Strength", scaleStr.y);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_SnowNormalNoiseScaleStrength", props).vectorValue = newScaleStr;
                        }
                    }
                }
                if (snowDistanceResample)
                {
                    if (mat.HasProperty("_SnowDistanceResampleScaleStrengthFade"))
                    {
                        Vector4 scaleStr    = shaderGUI.FindProp("_SnowDistanceResampleScaleStrengthFade", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Resample UV Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Resample Strength", scaleStr.y);
                        newScaleStr.z = EditorGUILayout.FloatField("Resample Fade Start", scaleStr.z);
                        newScaleStr.w = EditorGUILayout.FloatField("Resample Fade End", scaleStr.w);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_SnowDistanceResampleScaleStrengthFade", props).vectorValue = newScaleStr;
                        }
                    }
                }
            }
        }
예제 #27
0
        public override void DrawShaderGUI(MicroSplatShaderGUI shaderGUI, MicroSplatKeywords keywords, Material mat, MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (snow != SnowMode.None && mat.HasProperty("_SnowParams") && MicroSplatUtilities.DrawRollup("Snow"))
            {
                var snowDiff = shaderGUI.FindProp("_SnowDiff", props);
                var snowNorm = shaderGUI.FindProp("_SnowNormal", props);
                materialEditor.TexturePropertySingleLine(CDiffTex, snowDiff);
                materialEditor.TexturePropertySingleLine(CNormTex, snowNorm);
                MicroSplatUtilities.EnforceDefaultTexture(snowDiff, "microsplat_def_snow_diff");
                MicroSplatUtilities.EnforceDefaultTexture(snowNorm, "microsplat_def_snow_normsao");
                if (mat.HasProperty("_SnowTint"))
                {
                    materialEditor.ColorProperty(shaderGUI.FindProp("_SnowTint", props), "Snow Tint");
                }
                if (mat.HasProperty("_SnowMask"))
                {
                    var maskTex = shaderGUI.FindProp("_SnowMask", props);
                    materialEditor.TexturePropertySingleLine(CSnowTex, maskTex);
                }
                if (mat.HasProperty("_SnowUVScales"))
                {
                    Vector4 snowUV = shaderGUI.FindProp("_SnowUVScales", props).vectorValue;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("UV Scale");
                    snowUV.x = EditorGUILayout.FloatField(snowUV.x);
                    snowUV.y = EditorGUILayout.FloatField(snowUV.y);
                    EditorGUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        shaderGUI.FindProp("_SnowUVScales", props).vectorValue = snowUV;
                        EditorUtility.SetDirty(mat);
                    }
                }
                if (mat.HasProperty("_SnowSSSTint"))
                {
                    var prop = shaderGUI.FindProp("_SnowSSSTint", props);
                    EditorGUI.BeginChangeCheck();
                    Color c = prop.colorValue;
                    c   = EditorGUILayout.ColorField(CSSSTint, c);
                    c.a = EditorGUILayout.Slider(CSSSThickness, c.a, 0, 1);

                    if (EditorGUI.EndChangeCheck())
                    {
                        prop.colorValue = c;
                        EditorUtility.SetDirty(mat);
                    }
                }


                // influence, erosion, crystal, melt
                Vector4 p1 = shaderGUI.FindProp("_SnowParams", props).vectorValue;
                Vector4 hr = shaderGUI.FindProp("_SnowHeightAngleRange", props).vectorValue;

                EditorGUILayout.BeginHorizontal();
                bool oldEnabled = GUI.enabled;
                if (globalLevel)
                {
                    GUI.enabled = false;
                }
                materialEditor.ShaderProperty(shaderGUI.FindProp("_SnowAmount", props), "Amount");
                GUI.enabled = oldEnabled;
                globalLevel = DrawGlobalToggle(GetFeatureName(SnowDefineFeature._USEGLOBALSNOWLEVEL), keywords);
                EditorGUILayout.EndHorizontal();

                EditorGUI.BeginChangeCheck();

                if (snow == SnowMode.Rich)
                {
                    p1.x = EditorGUILayout.Slider(CHeightClear, p1.x, 0, 1);
                }
                p1.y = EditorGUILayout.Slider(CErosionClearing, p1.y, 0, 1);

                EditorGUILayout.BeginHorizontal();
                oldEnabled = GUI.enabled;
                if (globalHeight)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PrefixLabel(CHeightRange);
                hr.x         = EditorGUILayout.FloatField(hr.x);
                hr.y         = EditorGUILayout.FloatField(hr.y);
                GUI.enabled  = oldEnabled;
                globalHeight = DrawGlobalToggle(GetFeatureName(SnowDefineFeature._USEGLOBALSNOWHEIGHT), keywords);
                EditorGUILayout.EndHorizontal();


                hr.z = 1.0f - hr.z;
                hr.w = 1.0f - hr.w;
                EditorGUILayout.MinMaxSlider(CAngleRange, ref hr.w, ref hr.z, 0.0f, 1.0f);
                hr.z = 1.0f - hr.z;
                hr.w = 1.0f - hr.w;

                p1.z = EditorGUILayout.FloatField(CCrystals, p1.z);
                p1.w = EditorGUILayout.Slider(CMelt, p1.w, 0, 0.6f);

                if (EditorGUI.EndChangeCheck())
                {
                    shaderGUI.FindProp("_SnowParams", props).vectorValue           = p1;
                    shaderGUI.FindProp("_SnowHeightAngleRange", props).vectorValue = hr;
                }

                Vector4 up = mat.GetVector("_SnowUpVector");
                EditorGUI.BeginChangeCheck();
                Vector3 newUp = EditorGUILayout.Vector3Field(CUpVector, new Vector3(up.x, up.y, up.z));
                if (EditorGUI.EndChangeCheck())
                {
                    newUp.Normalize();
                    mat.SetVector("_SnowUpVector", new Vector4(newUp.x, newUp.y, newUp.z, 0));
                    EditorUtility.SetDirty(mat);
                }

                if (snowRim && mat.HasProperty("_SnowRimPower"))
                {
                    materialEditor.ColorProperty(shaderGUI.FindProp("_SnowRimColor", props), "Rim Light Color");
                    materialEditor.RangeProperty(shaderGUI.FindProp("_SnowRimPower", props), "Rim Light Power");
                }

                if (snowSparkle && mat.HasProperty("_SnowSparkleNoise"))
                {
                    var texProp = shaderGUI.FindProp("_SnowSparkleNoise", props);
                    materialEditor.TexturePropertySingleLine(CSparkleNoise, texProp);
                    MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_perlin4");
                    materialEditor.ColorProperty(shaderGUI.FindProp("_SnowSparkleTint", props), "Sparkle Tint");
                    materialEditor.RangeProperty(shaderGUI.FindProp("_SnowSparkleStrength", props), "Sparkle Strength");
                    materialEditor.RangeProperty(shaderGUI.FindProp("_SnowSparkleEmission", props), "Sparkle Emission Strength");
                    materialEditor.FloatProperty(shaderGUI.FindProp("_SnowSparkleSize", props), "Sparkle Size");
                    materialEditor.FloatProperty(shaderGUI.FindProp("_SnowSparkleDensity", props), "Sparkle Density");
                    materialEditor.FloatProperty(shaderGUI.FindProp("_SnowSparkleViewDependency", props), "Sparkle View Dependency");
                    materialEditor.FloatProperty(shaderGUI.FindProp("_SnowSparkleNoiseDensity", props), "Sparkle Noise Density");
                    materialEditor.FloatProperty(shaderGUI.FindProp("_SnowSparkleNoiseAmplitude", props), "Sparkle Noise Amplitude");
                }

                if (snowNormalNoise)
                {
                    if (mat.HasProperty("_SnowNormalNoise"))
                    {
                        var texProp = shaderGUI.FindProp("_SnowNormalNoise", props);
                        materialEditor.TexturePropertySingleLine(CDistanceNoise, texProp);
                        MicroSplatUtilities.EnforceDefaultTexture(texProp, "microsplat_def_snow_normalnoise");


                        Vector4 scaleStr    = shaderGUI.FindProp("_SnowNormalNoiseScaleStrength", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Noise UV Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Noise Strength", scaleStr.y);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_SnowNormalNoiseScaleStrength", props).vectorValue = newScaleStr;
                        }
                    }
                }
                if (snowDistanceResample)
                {
                    if (mat.HasProperty("_SnowDistanceResampleScaleStrengthFade"))
                    {
                        Vector4 scaleStr    = shaderGUI.FindProp("_SnowDistanceResampleScaleStrengthFade", props).vectorValue;
                        Vector4 newScaleStr = scaleStr;
                        newScaleStr.x = EditorGUILayout.FloatField("Resample UV Scale", scaleStr.x);
                        newScaleStr.y = EditorGUILayout.FloatField("Resample Strength", scaleStr.y);
                        newScaleStr.z = EditorGUILayout.FloatField("Resample Fade Start", scaleStr.z);
                        newScaleStr.w = EditorGUILayout.FloatField("Resample Fade End", scaleStr.w);
                        if (newScaleStr != scaleStr)
                        {
                            shaderGUI.FindProp("_SnowDistanceResampleScaleStrengthFade", props).vectorValue = newScaleStr;
                        }
                    }
                }

#if __MICROSPLAT_TEXTURECLUSTERS__
                if (snowStochastic)
                {
                    if (mat.HasProperty("_SnowStochasticScale"))
                    {
                        materialEditor.RangeProperty(shaderGUI.FindProp("_SnowStochasticScale", props), "Stochastic Scale");
                        materialEditor.RangeProperty(shaderGUI.FindProp("_SnowStochasticContrast", props), "Stochastic Contrast");
                    }
                }
#endif

                if (mat.HasProperty("_TessDisplaceSnowMultiplier"))
                {
                    materialEditor.RangeProperty(shaderGUI.FindProp("_TessDisplaceSnowMultiplier", props), "Displacement Multiplier");
                }
            }
        }
        void CompressTerrainSplats(MicroSplatTerrain t)
        {
            int splatCount = t.terrain.terrainData.alphamapTextureCount;

            // write out
            for (int i = 0; i < splatCount; ++i)
            {
                var tex  = t.terrain.terrainData.GetAlphamapTexture(i);
                var path = MicroSplatUtilities.RelativePathFromAsset(t);
                path += "/" + t.name + "_splat" + i + ".tga";
                System.IO.File.WriteAllBytes(path, tex.EncodeToTGA());
            }

            AssetDatabase.Refresh();
            // load and adjust importer
            for (int i = 0; i < splatCount; ++i)
            {
                var path = MicroSplatUtilities.RelativePathFromAsset(t);
                path += "/" + t.name + "_splat" + i + ".tga";

                var tex = CompressTexture(path, false);

                if (i == 0)
                {
                    t.customControl0 = tex;
                }
                else if (i == 1)
                {
                    t.customControl1 = tex;
                }
                else if (i == 2)
                {
                    t.customControl2 = tex;
                }
                else if (i == 3)
                {
                    t.customControl3 = tex;
                }
                else if (i == 4)
                {
                    t.customControl4 = tex;
                }
                else if (i == 5)
                {
                    t.customControl5 = tex;
                }
                else if (i == 6)
                {
                    t.customControl6 = tex;
                }
                else if (i == 7)
                {
                    t.customControl7 = tex;
                }
            }
            EditorUtility.SetDirty(t);

            MicroSplatKeywords keywords = MicroSplatUtilities.FindOrCreateKeywords(t.templateMaterial);

            if (!keywords.IsKeywordEnabled("_CUSTOMSPLATTEXTURES"))
            {
                keywords.EnableKeyword("_CUSTOMSPLATTEXTURES");
                MicroSplatShaderGUI.MicroSplatCompiler compiler = new MicroSplatShaderGUI.MicroSplatCompiler();
                compiler.Compile(t.templateMaterial);
                MicroSplatTerrain.SyncAll();
            }

            // destructive operation
            t.terrain.terrainData.alphamapResolution = 16;
        }