public virtual void SetupBlendMode() { blendPreset = (BlendPreset)this.blendPresetProperty.floatValue; blendModeSrc = (BlendMode)this.blendModeSrcProperty.floatValue; blendModeDst = (BlendMode)this.blendModeDstProperty.floatValue; blendOp = (BlendOp)this.blendOpProperty.floatValue; blendPreset = (BlendPreset)EditorGUILayout.EnumPopup("Blend Mode", blendPreset); bool disableCustomBlend = true; switch (blendPreset) { case BlendPreset.Alpha_Blend: blendModeSrc = BlendMode.SrcAlpha; blendModeDst = BlendMode.OneMinusSrcAlpha; blendOp = BlendOp.Add; break; case BlendPreset.Add: blendModeSrc = BlendMode.SrcAlpha; blendModeDst = BlendMode.One; blendOp = BlendOp.Add; break; case BlendPreset.AddRev: blendModeSrc = BlendMode.SrcAlpha; blendModeDst = BlendMode.One; blendOp = BlendOp.ReverseSubtract; break; case BlendPreset.Multiply: blendModeSrc = BlendMode.Zero; blendModeDst = BlendMode.SrcColor; blendOp = BlendOp.Add; break; case BlendPreset.PreMulBlend: blendModeSrc = BlendMode.One; blendModeDst = BlendMode.OneMinusSrcAlpha; blendOp = BlendOp.Add; break; case BlendPreset.Custom: disableCustomBlend = false; break; } EditorGUI.BeginDisabledGroup(disableCustomBlend); blendModeSrc = (BlendMode)EditorGUILayout.EnumPopup("Src", blendModeSrc); blendModeDst = (BlendMode)EditorGUILayout.EnumPopup("Dest", blendModeDst); blendOp = (BlendOp)EditorGUILayout.EnumPopup("Op", blendOp); EditorGUI.EndDisabledGroup(); }
public void DrawCommon(Common common) { common.cull = (Cull)this.Draw("Cull", common.cull); common.zTest = (Test)this.Draw("Z-Test", common.zTest); common.zWrite = (Toggle)this.Draw("Z-Write", common.zWrite); if (common.zWrite != Toggle.Off) { common.alphaTest = (Test)this.Draw("Alpha Test", common.alphaTest); if (common.alphaTest != Test.Always && common.alphaTest != Test.Default && common.alphaTest != Test.Off) { common.alphaCutoff = (string)this.Draw("Cutoff", common.alphaCutoff); } } BlendPreset preset = common.blendPreset; common.blendPreset = (BlendPreset)this.Draw("Blend Preset", common.blendPreset); bool custom = common.blendPreset == BlendPreset.Custom; bool extended = common.blendPreset == BlendPreset.CustomExtended; bool showBlend = MaterialBuffer.options["ShowDefault"] || (custom || extended); if (preset != common.blendPreset && custom) { common.blend = new Blend[2] { Blend.One, Blend.Zero }; } if (common.blendPreset != BlendPreset.Off && showBlend) { ++EditorGUI.indentLevel; EditorGUI.BeginDisabledGroup(!custom && !extended); string blendName = extended ? "Color" : "Color & Alpha"; common.blend = this.Draw(blendName, common.blend).As <List <object> >().ConvertAll <object, Blend>(); if (extended) { common.blendAlpha = this.Draw("Alpha", common.blendAlpha).As <List <object> >().ConvertAll <object, Blend>(); } EditorGUI.EndDisabledGroup(); --EditorGUI.indentLevel; } if (common.blendPreset != BlendPreset.Default && common.blendPreset != BlendPreset.Off) { common.blendOp = (BlendOp)this.Draw("Blend Operation", common.blendOp); } common.offset = (Vector2)this.Draw("Offset", common.offset, Vector2.zero); }
public void SortPreset(Common common, bool identifyPreset = false) { Blend[] blend = common.blend; BlendPreset preset = common.blendPreset; if (identifyPreset) { if (blend[0] == Blend.One && blend[1] == Blend.Zero) { preset = BlendPreset.Default; } if (blend[0] == Blend.SrcAlpha && blend[1] == Blend.OneMinusSrcAlpha) { preset = BlendPreset.AlphaBlended; } if (blend[0] == Blend.One && blend[1] == Blend.One) { preset = BlendPreset.Additive; } if (blend[0] == Blend.OneMinusDstColor && blend[1] == Blend.One) { preset = BlendPreset.AdditiveSoft; } if (blend[0] == Blend.DstColor && blend[1] == Blend.Zero) { preset = BlendPreset.Multiplicative; } if (blend[0] == Blend.DstColor && blend[1] == Blend.SrcColor) { preset = BlendPreset.Multiplicative2x; } if (preset == common.blendPreset) { preset = BlendPreset.Custom; } common.blendPreset = preset; } if (preset == BlendPreset.AlphaBlended) { blend = new Blend[2] { Blend.SrcAlpha, Blend.OneMinusSrcAlpha }; } if (preset == BlendPreset.Additive) { blend = new Blend[2] { Blend.One, Blend.One }; } if (preset == BlendPreset.AdditiveSoft) { blend = new Blend[2] { Blend.OneMinusDstColor, Blend.One }; } if (preset == BlendPreset.Multiplicative) { blend = new Blend[2] { Blend.DstColor, Blend.Zero }; } if (preset == BlendPreset.Multiplicative2x) { blend = new Blend[2] { Blend.DstColor, Blend.SrcColor }; } common.blend = blend; }