Esempio n. 1
0
        public void Generate(RenderTexture targetRt)
        {
            GBlendMapGeneratorParams param = GTextureToolParams.Instance.Blend;

            RenderTexture bg = new RenderTexture(targetRt);

            GCommon.CopyToRT(targetRt, bg);

            GCommon.FillTexture(targetRt, Color.black);
            for (int i = 0; i < param.Layers.Count; ++i)
            {
                GBlendLayer l = param.Layers[i];
                Mat.SetTexture("_Background", bg);
                Mat.SetTexture("_Foreground", l.Texture);
                Mat.SetFloat("_Number", l.Number);
                Mat.SetVector("_Vector", l.Vector);
                Mat.SetInt("_Ops", (int)l.BlendOps);
                Mat.SetFloat("_LerpFactor", l.LerpFactor);
                Mat.SetTexture("_LerpMask", l.LerpMask);
                Mat.SetInt("_Saturate", l.Saturate ? 1 : 0);

                GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, (int)l.DataSource);
                GCommon.CopyToRT(targetRt, bg);
            }

            bg.Release();
            GUtilities.DestroyObject(bg);
        }
Esempio n. 2
0
        public static GBlendLayer Create()
        {
            GBlendLayer layer = new GBlendLayer();

            layer.dataSource = GBlendDataSource.Texture;
            layer.texture    = null;
            layer.number     = 1;
            layer.vector     = Vector4.one;
            layer.blendOps   = GBlendOperation.Add;
            layer.lerpFactor = 0.5f;
            layer.saturate   = true;
            return(layer);
        }
        private void DrawBlendMapParams()
        {
            GBlendMapGeneratorParams param = GTextureToolParams.Instance.Blend;

            List <GBlendLayer> layers = param.Layers;

            for (int i = 0; i < layers.Count; ++i)
            {
                DrawBlendLayer(layers[i], i);
                GEditorCommon.Separator();
            }

            if (GUILayout.Button("Add Layer"))
            {
                layers.Add(GBlendLayer.Create());
            }

            GTextureToolParams.Instance.Blend = param;
        }
        private void DrawBlendLayer(GBlendLayer layer, int index)
        {
            string label = string.Format("{0} {1}", "Layer", index);
            string id    = "texture-creator-blend-layer" + index;

            string prefKey  = GEditorCommon.GetProjectRelatedEditorPrefsKey("foldout", id);
            bool   expanded = EditorPrefs.GetBool(prefKey, true);

            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            Rect headerRect = EditorGUILayout.BeginHorizontal();

            expanded = EditorGUILayout.Foldout(expanded, label);
            EditorPrefs.SetBool(prefKey, expanded);
            GUILayout.FlexibleSpace();
            Rect deleteButtonRect = EditorGUILayout.GetControlRect(GUILayout.Width(15));

            if (headerRect.Contains(Event.current.mousePosition))
            {
                if (GUI.Button(deleteButtonRect, "X", EditorStyles.label))
                {
                    ConfirmAndRemoveBlendLayerAt(index);
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel = indent;

            if (expanded)
            {
                //EditorGUI.indentLevel += 1;
                layer.DataSource = (GBlendDataSource)EditorGUILayout.EnumPopup("Source", layer.DataSource);
                if (layer.DataSource == GBlendDataSource.Texture)
                {
                    layer.Texture = GEditorCommon.InlineTexture2DField("Texture", layer.Texture, -1);
                }
                else if (layer.DataSource == GBlendDataSource.Number)
                {
                    layer.Number = EditorGUILayout.FloatField("Number", layer.Number);
                }
                else if (layer.DataSource == GBlendDataSource.Vector)
                {
                    layer.Vector = GEditorCommon.InlineVector4Field("Vector", layer.Vector);
                }

                if (index == 0)
                {
                    layer.BlendOps = GBlendOperation.Add;
                }
                GUI.enabled    = index != 0;
                layer.BlendOps = (GBlendOperation)EditorGUILayout.EnumPopup("Operation", layer.BlendOps);
                GUI.enabled    = true;
                if (layer.BlendOps == GBlendOperation.Lerp)
                {
                    layer.LerpFactor = EditorGUILayout.Slider("Factor", layer.LerpFactor, 0f, 1f);
                    layer.LerpMask   = GEditorCommon.InlineTexture2DField("Mask", layer.LerpMask, -1);
                }

                layer.Saturate = EditorGUILayout.Toggle("Saturate", layer.Saturate);
                //EditorGUI.indentLevel -= 1;
            }
        }