From d70fef1f9fa1e094c52817031dac5cb8a2ee074a Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Mon, 3 Feb 2020 17:17:49 -0500 Subject: [PATCH] BFLYT : Improve saving (material flags and part panes) --- .../FileFormats/Layout/CAFE/BFLYT.cs | 31 ++++++++-------- .../FileFormats/Layout/CAFE/BflytShader.cs | 4 +-- .../FileFormats/Layout/CTR/BclytShader.cs | 4 +-- .../FileFormats/Layout/Common.cs | 4 +-- .../FileFormats/Layout/Rev/BrlytShader.cs | 4 +-- .../Editor/Materials/PaneMatColorEditor.cs | 2 +- Toolbox/Shader/Layout/Bflyt.frag | 6 ++-- Toolbox/Shader/Layout/Bflyt.vert | 4 ++- Toolbox/Shader/Layout/Legacy/Bflyt.frag | 14 ++++---- Toolbox/Shader/Layout/Legacy/Bflyt.vert | 35 +++++++++++-------- 10 files changed, 61 insertions(+), 47 deletions(-) diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs index f58fd50b..2768dcdc 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs @@ -1896,14 +1896,18 @@ namespace LayoutBXLYT.Cafe writer.WriteString(LayoutFileName); writer.Align(4); - for (int i = 0; i < Properties.Count; i++) - Properties[i].WritePaneInfo(writer, header, startPos); - - for (int i = 0; i < Properties.Count; i++) - Properties[i].WriteUserData(writer, header, startPos); + // for (int i = 0; i < Properties.Count; i++) + // Properties[i].WriteProperties(writer, header, startPos); + + // for (int i = 0; i < Properties.Count; i++) + // Properties[i].WriteUserData(writer, header, startPos); for (int i = 0; i < Properties.Count; i++) + { Properties[i].WriteProperties(writer, header, startPos); + Properties[i].WriteUserData(writer, header, startPos); + Properties[i].WritePaneInfo(writer, header, startPos); + } } } @@ -2548,12 +2552,6 @@ namespace LayoutBXLYT.Cafe TextureTransforms = TextureTransforms.AddToArray(new TextureTransform()); } - [DisplayName("Thresholding Alpha Interpolation"), CategoryAttribute("Alpha")] - public override bool ThresholdingAlphaInterpolation - { - get { return Convert.ToBoolean((flags >> 18) & 0x1); } - } - [DisplayName("Black Color"), CategoryAttribute("Color")] public override STColor8 BlackColor { get; set; } @@ -2652,7 +2650,10 @@ namespace LayoutBXLYT.Cafe var hasIndParam = Convert.ToBoolean((flags >> 14) & 0x1); var projTexGenParamCount = Convert.ToUInt32((flags >> 15) & 0x3); var hasFontShadowParam = Convert.ToBoolean((flags >> 17) & 0x1); + AlphaInterpolation = Convert.ToBoolean((flags >> 18) & 0x1); + + Console.WriteLine($"MAT1 {Name}"); Console.WriteLine($"texCount {texCount}"); Console.WriteLine($"mtxCount {mtxCount}"); Console.WriteLine($"texCoordGenCount {texCoordGenCount}"); @@ -2664,6 +2665,7 @@ namespace LayoutBXLYT.Cafe Console.WriteLine($"hasIndParam {hasIndParam}"); Console.WriteLine($"projTexGenParamCount {projTexGenParamCount}"); Console.WriteLine($"hasFontShadowParam {hasFontShadowParam}"); + Console.WriteLine($"AlphaInterpolation {AlphaInterpolation}"); EnableAlphaCompare = hasAlphaCompare; EnableBlend = hasBlendMode; @@ -2750,7 +2752,6 @@ namespace LayoutBXLYT.Cafe flags += Bit.BitInsert(1, 1, 2, 24); ((TevStage)TevStages[i]).Write(writer); } - if (AlphaCompare != null && EnableAlphaCompare) { flags += Bit.BitInsert(1, 1, 1, 22); @@ -2784,8 +2785,10 @@ namespace LayoutBXLYT.Cafe FontShadowParameter.Write(writer); } - using (writer.TemporarySeek(flagPos, SeekOrigin.Begin)) - { + if (AlphaInterpolation) + flags += Bit.BitInsert(1, 1, 1, 13); + + using (writer.TemporarySeek(flagPos, SeekOrigin.Begin)) { writer.Write(flags); } } diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs index 172e9255..cc7a25b3 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs @@ -27,7 +27,7 @@ namespace LayoutBXLYT SetInt("textures0", 0); SetInt("textures1", 0); SetInt("textures2", 0); - SetBool("ThresholdingAlphaInterpolation", false); + SetBool("AlphaInterpolation", false); var rotationMatrix = Matrix4.Identity; SetMatrix("rotationMatrix", ref rotationMatrix); SetInt("numTevStages", 0); @@ -81,7 +81,7 @@ namespace LayoutBXLYT shader.SetVec2("uvTranslate0", new Vector2(0, 0)); shader.SetInt("flipTexture", 0); shader.SetInt("numTevStages", material.TevStages.Length); - shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation); + shader.SetBool("AlphaInterpolation", material.AlphaInterpolation); shader.SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0)); shader.SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0)); shader.SetInt("tevTexMode", 0); diff --git a/File_Format_Library/FileFormats/Layout/CTR/BclytShader.cs b/File_Format_Library/FileFormats/Layout/CTR/BclytShader.cs index 0fad2e85..ca980678 100644 --- a/File_Format_Library/FileFormats/Layout/CTR/BclytShader.cs +++ b/File_Format_Library/FileFormats/Layout/CTR/BclytShader.cs @@ -27,7 +27,7 @@ namespace LayoutBXLYT SetInt("textures0", 0); SetInt("textures1", 0); SetInt("textures2", 0); - SetBool("ThresholdingAlphaInterpolation", false); + SetBool("AlphaInterpolation", false); SetVec2("uvScale0", new Vector2(1, 1)); SetFloat("uvRotate0", 0); @@ -56,7 +56,7 @@ namespace LayoutBXLYT shader.SetFloat("uvRotate0", 0); shader.SetVec2("uvTranslate0", new Vector2(0, 0)); shader.SetInt("flipTexture", 0); - shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation); + shader.SetBool("AlphaInterpolation", material.AlphaInterpolation); shader.SetInt($"texCoords0GenType", 0); shader.SetInt($"texCoords0Source", 0); diff --git a/File_Format_Library/FileFormats/Layout/Common.cs b/File_Format_Library/FileFormats/Layout/Common.cs index 9a4887d6..3f942455 100644 --- a/File_Format_Library/FileFormats/Layout/Common.cs +++ b/File_Format_Library/FileFormats/Layout/Common.cs @@ -2277,8 +2277,8 @@ namespace LayoutBXLYT [TypeConverter(typeof(ExpandableObjectConverter))] public BxlytAlphaCompare AlphaCompare { get; set; } - [DisplayName("Thresholding Alpha Interpolation"), CategoryAttribute("Alpha")] - public virtual bool ThresholdingAlphaInterpolation { get; set; } + [DisplayName("Alpha Interpolation"), CategoryAttribute("Alpha")] + public virtual bool AlphaInterpolation { get; set; } [DisplayName("Texture Maps"), CategoryAttribute("Texture")] public BxlytTextureRef[] TextureMaps { get; set; } diff --git a/File_Format_Library/FileFormats/Layout/Rev/BrlytShader.cs b/File_Format_Library/FileFormats/Layout/Rev/BrlytShader.cs index d5d7d34d..58b28983 100644 --- a/File_Format_Library/FileFormats/Layout/Rev/BrlytShader.cs +++ b/File_Format_Library/FileFormats/Layout/Rev/BrlytShader.cs @@ -27,7 +27,7 @@ namespace LayoutBXLYT SetInt("textures0", 0); SetInt("textures1", 0); SetInt("textures2", 0); - SetBool("ThresholdingAlphaInterpolation", false); + SetBool("AlphaInterpolation", false); var rotationMatrix = Matrix4.Identity; SetMatrix("rotationMatrix", ref rotationMatrix); SetInt("numTevStages", 0); @@ -102,7 +102,7 @@ namespace LayoutBXLYT shader.SetVec2("uvTranslate0", new Vector2(0, 0)); shader.SetInt("flipTexture", 0); shader.SetInt("numTevStages", 0); - shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation); + shader.SetBool("AlphaInterpolation", material.AlphaInterpolation); shader.SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0)); shader.SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0)); shader.SetInt("tevTexMode", 0); diff --git a/File_Format_Library/GUI/BFLYT/Editor/Materials/PaneMatColorEditor.cs b/File_Format_Library/GUI/BFLYT/Editor/Materials/PaneMatColorEditor.cs index 2e6eccd3..6ef047fb 100644 --- a/File_Format_Library/GUI/BFLYT/Editor/Materials/PaneMatColorEditor.cs +++ b/File_Format_Library/GUI/BFLYT/Editor/Materials/PaneMatColorEditor.cs @@ -32,7 +32,7 @@ namespace LayoutBXLYT whiteColorPB.Color = material.WhiteColor.Color; blackColorBP.Color = material.BlackColor.Color; - chkAlphaInterpolation.Bind(material, "ThresholdingAlphaInterpolation"); + chkAlphaInterpolation.Bind(material, "AlphaInterpolation"); } private STColorDialog colorDlg; diff --git a/Toolbox/Shader/Layout/Bflyt.frag b/Toolbox/Shader/Layout/Bflyt.frag index 154cc02a..c4dec59b 100644 --- a/Toolbox/Shader/Layout/Bflyt.frag +++ b/Toolbox/Shader/Layout/Bflyt.frag @@ -30,7 +30,7 @@ uniform int tevStage5A; uniform int tevTexMode; -uniform int ThresholdingAlphaInterpolation; +uniform int AlphaInterpolation; uniform int numTevStages; uniform vec4 IndirectMat0; @@ -144,6 +144,8 @@ void main() { fragColor = vec4(1); + return; + vec4 textureMap0 = vec4(1); vec4 textureMap1 = vec4(1); vec4 textureMap2 = vec4(1); @@ -203,7 +205,7 @@ void main() } else { - if (ThresholdingAlphaInterpolation != 0) + if (AlphaInterpolation != 0) { //Todo these need to interpolate and be smoother if (textureMap0.a >= whiteColor.a) alpha = 1.0; diff --git a/Toolbox/Shader/Layout/Bflyt.vert b/Toolbox/Shader/Layout/Bflyt.vert index e88d2e83..a32d469c 100644 --- a/Toolbox/Shader/Layout/Bflyt.vert +++ b/Toolbox/Shader/Layout/Bflyt.vert @@ -6,6 +6,8 @@ in vec2 vTexCoord0; in vec2 vTexCoord1; in vec2 vTexCoord2; +uniform mat4 rotationMatrix; + uniform mat4 modelViewMatrix; uniform vec2 uvScale0; uniform vec2 uvRotate0; @@ -52,5 +54,5 @@ void main() TexCoord2 = SetFlip(texCoord0Transformed); VertexColor = vColor; - gl_Position = modelViewMatrix * vec4(vPosition, 0, 1); + gl_Position = modelViewMatrix * rotationMatrix * vec4(vPosition, 0, 1); } \ No newline at end of file diff --git a/Toolbox/Shader/Layout/Legacy/Bflyt.frag b/Toolbox/Shader/Layout/Legacy/Bflyt.frag index 94c7c34d..dee821e5 100644 --- a/Toolbox/Shader/Layout/Legacy/Bflyt.frag +++ b/Toolbox/Shader/Layout/Legacy/Bflyt.frag @@ -26,7 +26,7 @@ uniform int tevStage3A; uniform int tevStage4A; uniform int tevStage5A; -uniform int ThresholdingAlphaInterpolation; +uniform int AlphaInterpolation; uniform int numTevStages; uniform sampler2D uvTestPattern; @@ -38,15 +38,15 @@ vec3 ColorOP(int type, vec4 color) switch (type) { case 0: return color.rgb; - case 1: return vec3(1) - color.rgb; + case 1: return vec3(1.0) - color.rgb; case 2: return color.aaa; - case 3: return vec3(1) - color.aaa; + case 3: return vec3(1.0) - color.aaa; case 4: return color.rrr; - case 5: return vec3(1) - color.rrr; + case 5: return vec3(1.0) - color.rrr; case 6: return color.ggg; - case 7: return vec3(1) - color.ggg; + case 7: return vec3(1.0) - color.ggg; case 8: return color.bbb; - case 9: return vec3(1) - color.bbb; + case 9: return vec3(1.0) - color.bbb; default: return color.rgb; } } @@ -159,7 +159,7 @@ void main() } else { - if (ThresholdingAlphaInterpolation != 0) + if (AlphaInterpolation != 0) { //Todo these need to interpolate and be smoother if (textureMap0.a >= whiteColor.a) alpha = 1.0; diff --git a/Toolbox/Shader/Layout/Legacy/Bflyt.vert b/Toolbox/Shader/Layout/Legacy/Bflyt.vert index d2298416..a9259319 100644 --- a/Toolbox/Shader/Layout/Legacy/Bflyt.vert +++ b/Toolbox/Shader/Layout/Legacy/Bflyt.vert @@ -1,4 +1,6 @@ -uniform vec2 uvScale0; +#version 110 + +uniform vec2 uvScale0; uniform float uvRotate0; uniform vec2 uvTranslate0; uniform int flipTexture; @@ -24,27 +26,32 @@ vec2 SetFlip(vec2 tex) else if (flipTexture == 2) //FlipV return vec2(1, -1) * tex + vec2(0, 1); else if (flipTexture == 3) //Rotate90 - return rotateUV(tex, radians(90.0)); + { + float degreesR = 90.0; + return rotateUV(tex, radians(degreesR)); + } else if (flipTexture == 4) //Rotate180 - return rotateUV(tex, radians(180.0)); + { + float degreesR = 180.0; + return rotateUV(tex, radians(degreesR)); + } else if (flipTexture == 5) //Rotate270 - return rotateUV(tex, radians(270.0)); - + { + float degreesR = 270.0; + return rotateUV(tex, radians(degreesR)); + } return outTexCoord; } vec2 SetTexCoordType(int type, vec2 tex) { vec2 outTexCoord = tex; - switch (type) - { - case 0: return tex; //Tex0 - case 1: return tex; //Tex1 - case 2: return tex; //Tex2 - case 3: return tex; //Ortho - case 4: return tex; //Pane based - case 5: return tex; //Proj - } + if (type == 0) return tex; //Tex0 + if (type == 1) return tex; //Tex1 + if (type == 2) return tex; //Tex3 + if (type == 3) return tex; //Ortho + if (type == 4) return tex; //Pane based + if (type == 5) return tex; //Proj return outTexCoord; }