public static GCurveParams Create() { GCurveParams param = new GCurveParams(); param.MasterCurve = AnimationCurve.EaseInOut(0, 0, 1, 1); param.RedCurve = AnimationCurve.Linear(0, 0, 1, 1); param.GreenCurve = AnimationCurve.Linear(0, 0, 1, 1); param.BlueCurve = AnimationCurve.Linear(0, 0, 1, 1); param.AlphaCurve = AnimationCurve.Linear(0, 0, 1, 1); return(param); }
public void Apply(RenderTexture targetRt, GTextureFilterParams param) { GCurveParams curveParam = param.Curve; RenderTexture bg = CloneBg(targetRt); Texture2D masterCurveTex = GCommon.CreateTextureFromCurve(curveParam.MasterCurve, 1024, 1); Texture2D redCurveTex = GCommon.CreateTextureFromCurve(curveParam.RedCurve, 1024, 1); Texture2D greenCurveTex = GCommon.CreateTextureFromCurve(curveParam.GreenCurve, 1024, 1); Texture2D blueCurveTex = GCommon.CreateTextureFromCurve(curveParam.BlueCurve, 1024, 1); Texture2D alphaCurveTex = GCommon.CreateTextureFromCurve(curveParam.AlphaCurve, 1024, 1); Mat.SetTexture("_MainTex", bg); Mat.SetTexture("_MasterCurve", masterCurveTex); Mat.SetTexture("_RedCurve", redCurveTex); Mat.SetTexture("_GreenCurve", greenCurveTex); Mat.SetTexture("_BlueCurve", blueCurveTex); Mat.SetTexture("_AlphaCurve", alphaCurveTex); GCommon.DrawQuad(targetRt, GCommon.FullRectUvPoints, Mat, 0); GUtilities.DestroyObject(masterCurveTex); GUtilities.DestroyObject(redCurveTex); GUtilities.DestroyObject(greenCurveTex); GUtilities.DestroyObject(blueCurveTex); GUtilities.DestroyObject(alphaCurveTex); }
private void DrawFilterLayer(GTextureFilterLayer layer, int index) { string label = string.Format("{0} {1}", ObjectNames.NicifyVariableName(layer.Type.ToString()), layer.Enabled ? "" : "[-]"); string id = "texture-creator-filter" + 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)) { ConfirmAndRemoveFilterAt(index); } } EditorGUILayout.EndHorizontal(); if (expanded) { EditorGUI.indentLevel += 1; layer.Enabled = EditorGUILayout.Toggle("Enable", layer.Enabled); GTextureFilterParams param = layer.Param; if (layer.Type == GTextureFilterType.Blur) { GBlurParams blur = param.Blur; blur.Radius = EditorGUILayout.DelayedIntField("Radius", blur.Radius); EditorGUILayout.LabelField("This filter is expensive!", GEditorCommon.WordWrapItalicLabel); param.Blur = blur; } else if (layer.Type == GTextureFilterType.Curve) { GCurveParams curve = param.Curve; curve.MasterCurve = EditorGUILayout.CurveField("Master", curve.MasterCurve, Color.white, GCommon.UnitRect); curve.RedCurve = EditorGUILayout.CurveField("Red", curve.RedCurve, Color.red, GCommon.UnitRect); curve.GreenCurve = EditorGUILayout.CurveField("Green", curve.GreenCurve, Color.green, GCommon.UnitRect); curve.BlueCurve = EditorGUILayout.CurveField("Blue", curve.BlueCurve, Color.blue, GCommon.UnitRect); curve.AlphaCurve = EditorGUILayout.CurveField("Alpha", curve.AlphaCurve, Color.gray, GCommon.UnitRect); param.Curve = curve; } else if (layer.Type == GTextureFilterType.Invert) { GInvertParams invert = param.Invert; invert.InvertRed = EditorGUILayout.Toggle("Red", invert.InvertRed); invert.InvertGreen = EditorGUILayout.Toggle("Green", invert.InvertGreen); invert.InvertBlue = EditorGUILayout.Toggle("Blue", invert.InvertBlue); invert.InvertAlpha = EditorGUILayout.Toggle("Alpha", invert.InvertAlpha); param.Invert = invert; } else if (layer.Type == GTextureFilterType.Step) { GStepParams step = param.Step; step.Count = EditorGUILayout.IntSlider("Count", step.Count, 1, 256); param.Step = step; } else if (layer.Type == GTextureFilterType.Warp) { GWarpParams warp = param.Warp; warp.MaskIsNormalMap = EditorGUILayout.Toggle("Is Normal Map", warp.MaskIsNormalMap); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Mask"); using (EditorGUI.IndentLevelScope level = new EditorGUI.IndentLevelScope(-1)) { warp.Mask = EditorGUILayout.ObjectField(warp.Mask, typeof(Texture2D), false) as Texture2D; } EditorGUILayout.EndHorizontal(); warp.Strength = EditorGUILayout.FloatField("Strength", warp.Strength); param.Warp = warp; } /* * else if (layer.Type == GTextureFilterType.HydraulicErosion) * { * GHydraulicErosionParams erosion = param.HydraulicErosion; * * erosion.Iteration = EditorGUILayout.IntField("Iteration", erosion.Iteration); * * Vector3 dim = erosion.Dimension; * dim = GEditorCommon.InlineVector3Field("Dimension", dim); * dim.Set(Mathf.Max(1, dim.x), Mathf.Max(1, dim.y), Mathf.Max(1, dim.z)); * erosion.Dimension = dim; * * erosion.Rain = EditorGUILayout.Slider("Rain", erosion.Rain, 0f, 1f); * erosion.Transportation = EditorGUILayout.Slider("Transportation", erosion.Transportation, 0f, 1f); * erosion.AngleMin = EditorGUILayout.Slider("Min Angle", erosion.AngleMin, 1f, 45f); * erosion.Evaporation = EditorGUILayout.Slider("Evaporation", erosion.Evaporation, 0f, 1f); * * EditorGUILayout.BeginHorizontal(); * EditorGUILayout.PrefixLabel("Water Source"); * using (EditorGUI.IndentLevelScope level = new EditorGUI.IndentLevelScope(-1)) * { * erosion.WaterSourceMap = EditorGUILayout.ObjectField(erosion.WaterSourceMap, typeof(Texture2D), false) as Texture2D; * } * EditorGUILayout.EndHorizontal(); * * EditorGUILayout.BeginHorizontal(); * EditorGUILayout.PrefixLabel("Hardness"); * using (EditorGUI.IndentLevelScope level = new EditorGUI.IndentLevelScope(-1)) * { * erosion.HardnessMap = EditorGUILayout.ObjectField(erosion.HardnessMap, typeof(Texture2D), false) as Texture2D; * } * EditorGUILayout.EndHorizontal(); * * param.HydraulicErosion = erosion; * } */ layer.Param = param; EditorGUI.indentLevel -= 1; } EditorGUI.indentLevel = indent; }