コード例 #1
0
        private void DrawPrototypesListGUI()
        {
            for (int i = 0; i < instance.Prototypes.Count; ++i)
            {
                GSplatPrototype p = instance.Prototypes[i];

                string label = p.Texture != null && !string.IsNullOrEmpty(p.Texture.name) ? p.Texture.name : "Splat " + i;
                string id    = "splat" + i + instance.GetInstanceID().ToString();

                int         index = i;
                GenericMenu menu  = new GenericMenu();
                menu.AddItem(
                    new GUIContent("Remove"),
                    false,
                    () => { ConfirmAndRemovePrototypeAtIndex(index); });

                GEditorCommon.Foldout(label, false, id, () =>
                {
                    p.Texture    = EditorGUILayout.ObjectField("Texture", p.Texture, typeof(Texture2D), false) as Texture2D;
                    p.NormalMap  = EditorGUILayout.ObjectField("Normal Map", p.NormalMap, typeof(Texture2D), false) as Texture2D;
                    p.TileSize   = EditorGUILayout.Vector2Field("Tile Size", p.TileSize);
                    p.TileOffset = EditorGUILayout.Vector2Field("Tile Offset", p.TileOffset);
                    p.Metallic   = EditorGUILayout.Slider("Metallic", p.Metallic, 0f, 1f);
                    p.Smoothness = EditorGUILayout.Slider("Smoothness", p.Smoothness, 0f, 1f);
                }, menu);
            }
        }
コード例 #2
0
        private void DrawAddPrototypeGUI()
        {
            EditorGUILayout.GetControlRect(GUILayout.Height(1));
            Rect      r = EditorGUILayout.GetControlRect(GUILayout.Height(GEditorCommon.objectSelectorDragDropHeight));
            Texture2D t = GEditorCommon.ObjectSelectorDragDrop <Texture2D>(r, "Drop a texture here!", "t:Texture2D");

            if (t != null)
            {
                GSplatPrototype p = new GSplatPrototype();
                p.Texture = t;
                instance.Prototypes.Add(p);
            }
        }
コード例 #3
0
        private void ConfirmAndRemovePrototypeAtIndex(int index)
        {
            GSplatPrototype p     = instance.Prototypes[index];
            string          label = p.Texture != null ? p.Texture.name : "Splat " + index;

            if (EditorUtility.DisplayDialog(
                    "Confirm",
                    "Remove " + label,
                    "OK", "Cancel"))
            {
                instance.Prototypes.RemoveAt(index);
            }
        }
コード例 #4
0
        public void ConvertSplatsToAlbedo()
        {
            if (Splats == null)
            {
                return;
            }
            RenderTexture albedoRt = new RenderTexture(AlbedoMapResolution, AlbedoMapResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            Material      mat      = GInternalMaterials.SplatsToAlbedoMaterial;

            for (int i = 0; i < SplatControlMapCount; ++i)
            {
                Texture2D controlMap = GetSplatControl(i);
                mat.SetTexture("_Control0", controlMap);
                for (int channel = 0; channel < 4; ++channel)
                {
                    int prototypeIndex = i * 4 + channel;
                    if (prototypeIndex < Splats.Prototypes.Count)
                    {
                        GSplatPrototype p = Splats.Prototypes[prototypeIndex];
                        mat.SetTexture("_Splat" + channel, p.Texture);
                        Vector2 terrainSize  = new Vector2(TerrainData.Geometry.Width, TerrainData.Geometry.Length);
                        Vector2 textureScale = new Vector2(
                            p.TileSize.x != 0 ? terrainSize.x / p.TileSize.x : 0,
                            p.TileSize.y != 0 ? terrainSize.y / p.TileSize.y : 0);
                        Vector2 textureOffset = new Vector2(
                            p.TileOffset.x != 0 ? terrainSize.x / p.TileOffset.x : 0,
                            p.TileOffset.y != 0 ? terrainSize.y / p.TileOffset.y : 0);
                        mat.SetTextureScale("_Splat" + channel, textureScale);
                        mat.SetTextureOffset("_Splat" + channel, textureOffset);
                    }
                    else
                    {
                        mat.SetTexture("_Splat" + channel, null);
                        mat.SetTextureScale("_Splat" + channel, Vector2.zero);
                        mat.SetTextureOffset("_Splat" + channel, Vector2.zero);
                    }
                }

                GCommon.DrawQuad(albedoRt, GCommon.FullRectUvPoints, mat, 0);
            }

            GCommon.CopyFromRT(AlbedoMap, albedoRt);
            albedoRt.Release();
            GUtilities.DestroyObject(albedoRt);
        }
コード例 #5
0
        public void UpdateMaterials()
        {
            if (MaterialToRender != null)
            {
                if (MaterialToRender.HasProperty(AlbedoMapPropertyName))
                {
                    MaterialToRender.SetTexture(AlbedoMapPropertyName, AlbedoMap);
                }
                if (MaterialToRender.HasProperty(MetallicMapPropertyName))
                {
                    MaterialToRender.SetTexture(MetallicMapPropertyName, MetallicMap);
                }
                if (MaterialToRender.HasProperty(ColorByHeightPropertyName))
                {
                    MaterialToRender.SetTexture(ColorByHeightPropertyName, ColorByHeightMap);
                }
                if (MaterialToRender.HasProperty(ColorByNormalPropertyName))
                {
                    MaterialToRender.SetTexture(ColorByNormalPropertyName, ColorByNormalMap);
                }
                if (MaterialToRender.HasProperty(ColorBlendPropertyName))
                {
                    MaterialToRender.SetTexture(ColorBlendPropertyName, ColorBlendMap);
                }
                if (MaterialToRender.HasProperty(DimensionPropertyName))
                {
                    Vector4 dim = new Vector4(
                        TerrainData.Geometry.Width,
                        TerrainData.Geometry.Height,
                        TerrainData.Geometry.Length,
                        0);
                    MaterialToRender.SetVector(DimensionPropertyName, dim);
                }

                for (int i = 0; i < SplatControlMapCount; ++i)
                {
                    if (MaterialToRender.HasProperty(SplatControlMapPropertyName + i))
                    {
                        MaterialToRender.SetTexture(SplatControlMapPropertyName + i, GetSplatControl(i));
                    }
                }

                if (Splats != null)
                {
                    for (int i = 0; i < Splats.Prototypes.Count; ++i)
                    {
                        GSplatPrototype p = Splats.Prototypes[i];
                        if (MaterialToRender.HasProperty(SplatMapPropertyName + i))
                        {
                            MaterialToRender.SetTexture(SplatMapPropertyName + i, p.Texture);
                            Vector2 terrainSize  = new Vector2(TerrainData.Geometry.Width, TerrainData.Geometry.Length);
                            Vector2 textureScale = new Vector2(
                                p.TileSize.x != 0 ? terrainSize.x / p.TileSize.x : 0,
                                p.TileSize.y != 0 ? terrainSize.y / p.TileSize.y : 0);
                            Vector2 textureOffset = new Vector2(
                                p.TileOffset.x != 0 ? terrainSize.x / p.TileOffset.x : 0,
                                p.TileOffset.y != 0 ? terrainSize.y / p.TileOffset.y : 0);
                            MaterialToRender.SetTextureScale(SplatMapPropertyName + i, textureScale);
                            MaterialToRender.SetTextureOffset(SplatMapPropertyName + i, textureOffset);
                        }
                        if (MaterialToRender.HasProperty(SplatNormalPropertyName + i))
                        {
                            MaterialToRender.SetTexture(SplatNormalPropertyName + i, p.NormalMap);
                        }
                        if (MaterialToRender.HasProperty(SplatMetallicPropertyName + i))
                        {
                            MaterialToRender.SetFloat(SplatMetallicPropertyName + i, p.Metallic);
                        }
                        if (MaterialToRender.HasProperty(SplatSmoothnessPropertyName + i))
                        {
                            MaterialToRender.SetFloat(SplatSmoothnessPropertyName + i, p.Smoothness);
                        }
                    }
                }
            }
        }