From 617dfad22e13b6426de3b9e94f1c934d855cf0ee Mon Sep 17 00:00:00 2001 From: 4sval Date: Sun, 4 Dec 2022 02:15:42 +0100 Subject: [PATCH] fixed 0 padding + ao pixel color fighting --- CUE4Parse | 2 +- FModel/Resources/default.frag | 30 +++---- FModel/Views/SettingsView.xaml | 2 +- FModel/Views/Snooper/Material.cs | 61 +++++++------- FModel/Views/Snooper/SnimGui.cs | 135 ++++++++++++++++-------------- FModel/Views/Snooper/Transform.cs | 56 +++++++++++++ 6 files changed, 176 insertions(+), 110 deletions(-) diff --git a/CUE4Parse b/CUE4Parse index 5987bbdb..2ce15122 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit 5987bbdb4e094c8c08e7b3cf05fc6ad6728299fb +Subproject commit 2ce1512277e2f3f7b64975c46ce978efe824df2f diff --git a/FModel/Resources/default.frag b/FModel/Resources/default.frag index b6ffe102..573990d8 100644 --- a/FModel/Resources/default.frag +++ b/FModel/Resources/default.frag @@ -1,4 +1,4 @@ -#version 330 core +#version 330 core #define PI 3.1415926535897932384626433832795 #define MAX_UV_COUNT 8 @@ -23,13 +23,13 @@ struct Boost float Exponent; }; -struct Mask +struct AoParams { sampler2D Sampler; - Boost SkinBoost; - float AmbientOcclusion; - float Curvature; + + Boost ColorBoost; + bool HasColorBoost; }; struct Parameters @@ -39,8 +39,8 @@ struct Parameters Texture SpecularMasks[MAX_UV_COUNT]; Texture Emissive[MAX_UV_COUNT]; - Mask M; - bool HasM; + AoParams Ao; + bool HasAo; float Roughness; float EmissiveMult; @@ -172,19 +172,15 @@ void main() vec4 diffuse = SamplerToVector(uParameters.Diffuse[layer].Sampler); vec3 result = uParameters.Diffuse[layer].Color.rgb * diffuse.rgb; - if (uParameters.HasM) + if (uParameters.HasAo) { - vec3 m = SamplerToVector(uParameters.M.Sampler).rgb; - - float subsurface = clamp(1.0f, 0.0f, m.b * .04f); - if (subsurface > 0.0f && uParameters.M.SkinBoost.Exponent > 0.0f) + vec3 m = SamplerToVector(uParameters.Ao.Sampler).rgb; + if (uParameters.Ao.HasColorBoost) { - vec3 color = uParameters.M.SkinBoost.Color * uParameters.M.SkinBoost.Exponent; - result *= clamp(vec3(1.0f), vec3(0.0f), color * m.b); + vec3 color = uParameters.Ao.ColorBoost.Color * uParameters.Ao.ColorBoost.Exponent; + result = mix(result, result * color, m.b); } - - if (m.r > 0.0f) result *= m.r * uParameters.M.AmbientOcclusion; - if (m.g > 0.0f) result += m.g * uParameters.M.Curvature; + result = mix(result * m.r * uParameters.Ao.AmbientOcclusion, result, m.g); } vec4 emissive = SamplerToVector(uParameters.Emissive[layer].Sampler); diff --git a/FModel/Views/SettingsView.xaml b/FModel/Views/SettingsView.xaml index dfae0bd7..7826269e 100644 --- a/FModel/Views/SettingsView.xaml +++ b/FModel/Views/SettingsView.xaml @@ -372,7 +372,7 @@ IsChecked="{Binding SaveMaterials, Source={x:Static local:Settings.UserSettings.Default}, Mode=TwoWay}"/> - + diff --git a/FModel/Views/Snooper/Material.cs b/FModel/Views/Snooper/Material.cs index 6bf7f7dc..57bb00c2 100644 --- a/FModel/Views/Snooper/Material.cs +++ b/FModel/Views/Snooper/Material.cs @@ -28,8 +28,8 @@ public class Material : IDisposable public Vector4[] DiffuseColor; public Vector4[] EmissiveColor; - public Mask M; - public bool HasM; + public AoParams Ao; + public bool HasAo; public float Roughness = 0.5f; public float EmissiveMult = 1f; @@ -89,12 +89,16 @@ public void Setup(Options options, int numTexCoords) } { // scalars - if (Parameters.TryGetTexture2d(out var original, "M", "AEM") && options.TryGetTexture(original, false, out var transformed)) + if (Parameters.TryGetTexture2d(out var original, "M", "PackedTexture", "AEM") && + !original.Name.Equals("T_BlackMask") && options.TryGetTexture(original, false, out var transformed)) { - M = new Mask { Texture = transformed, AmbientOcclusion = 0.7f }; - HasM = true; + HasAo = true; + Ao = new AoParams { Texture = transformed, AmbientOcclusion = 0.7f }; if (Parameters.TryGetLinearColor(out var l, "Skin Boost Color And Exponent")) - M.SkinBoost = new Boost { Color = new Vector3(l.R, l.G, l.B), Exponent = l.A }; + { + Ao.HasColorBoost = true; + Ao.ColorBoost = new Boost { Color = new Vector3(l.R, l.G, l.B), Exponent = l.A }; + } } if (Parameters.TryGetScalar(out var roughnessMin, "RoughnessMin", "SpecRoughnessMin") && @@ -197,13 +201,13 @@ public void Render(Shader shader) Emissive[i]?.Bind(TextureUnit.Texture0 + unit++); } - M.Texture?.Bind(TextureUnit.Texture31); - shader.SetUniform("uParameters.M.Sampler", 31); - shader.SetUniform("uParameters.M.SkinBoost.Color", M.SkinBoost.Color); - shader.SetUniform("uParameters.M.SkinBoost.Exponent", M.SkinBoost.Exponent); - shader.SetUniform("uParameters.M.AmbientOcclusion", M.AmbientOcclusion); - shader.SetUniform("uParameters.M.Curvature", M.Curvature); - shader.SetUniform("uParameters.HasM", HasM); + Ao.Texture?.Bind(TextureUnit.Texture31); + shader.SetUniform("uParameters.Ao.Sampler", 31); + shader.SetUniform("uParameters.Ao.HasColorBoost", Ao.HasColorBoost); + shader.SetUniform("uParameters.Ao.ColorBoost.Color", Ao.ColorBoost.Color); + shader.SetUniform("uParameters.Ao.ColorBoost.Exponent", Ao.ColorBoost.Exponent); + shader.SetUniform("uParameters.Ao.AmbientOcclusion", Ao.AmbientOcclusion); + shader.SetUniform("uParameters.HasAo", HasAo); shader.SetUniform("uParameters.Roughness", Roughness); shader.SetUniform("uParameters.EmissiveMult", EmissiveMult); @@ -227,17 +231,18 @@ public void ImGuiParameters() ImGui.DragFloat("", ref UVScale, _step, _zero, _infinite, _mult, _clamp); ImGui.PopID(); - if (HasM) + if (HasAo) { SnimGui.Layout("Ambient Occlusion");ImGui.PushID(4); - ImGui.DragFloat("", ref M.AmbientOcclusion, _step, _zero, 1.0f, _mult, _clamp); - ImGui.PopID();SnimGui.Layout("Curvature");ImGui.PushID(5); - ImGui.DragFloat("", ref M.Curvature, _step, _zero, 1.0f, _mult, _clamp); - ImGui.PopID();SnimGui.Layout("Color Boost");ImGui.PushID(6); - ImGui.ColorEdit3("", ref M.SkinBoost.Color); - ImGui.PopID();SnimGui.Layout("Color Boost Exponent");ImGui.PushID(7); - ImGui.DragFloat("", ref M.SkinBoost.Exponent, _step, _zero, _infinite, _mult, _clamp); - ImGui.PopID(); + ImGui.DragFloat("", ref Ao.AmbientOcclusion, _step, _zero, 1.0f, _mult, _clamp);ImGui.PopID(); + if (Ao.HasColorBoost) + { + SnimGui.Layout("Color Boost");ImGui.PushID(5); + ImGui.ColorEdit3("", ref Ao.ColorBoost.Color);ImGui.PopID(); + SnimGui.Layout("Color Boost Exponent");ImGui.PushID(6); + ImGui.DragFloat("", ref Ao.ColorBoost.Exponent, _step, _zero, _infinite, _mult, _clamp); + ImGui.PopID(); + } } ImGui.EndTable(); } @@ -308,7 +313,7 @@ public void ImGuiTextures(Dictionary icons, Model model) 0 => Diffuse[SelectedChannel]?.GetPointer(), 1 => Normals[SelectedChannel]?.GetPointer(), 2 => SpecularMasks[SelectedChannel]?.GetPointer(), - 3 => M.Texture?.GetPointer(), + 3 => Ao.Texture?.GetPointer(), 4 => Emissive[SelectedChannel]?.GetPointer(), _ => null }; @@ -332,18 +337,18 @@ public void Dispose() { Emissive[i]?.Dispose(); } - M.Texture?.Dispose(); + Ao.Texture?.Dispose(); GL.DeleteProgram(_handle); } } -public struct Mask +public struct AoParams { public Texture Texture; - public Boost SkinBoost; - public float AmbientOcclusion; - public float Curvature; + + public Boost ColorBoost; + public bool HasColorBoost; } public struct Boost diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs index 0cb4854d..4dc28248 100644 --- a/FModel/Views/Snooper/SnimGui.cs +++ b/FModel/Views/Snooper/SnimGui.cs @@ -6,6 +6,8 @@ using ImGuiNET; using OpenTK.Windowing.Common; using System.Numerics; +using FModel.Settings; +using OpenTK.Graphics.OpenGL4; namespace FModel.Views.Snooper; @@ -37,9 +39,11 @@ public void Reset() public class SnimGui { public readonly ImGuiController Controller; - private bool _viewportFocus; private readonly Swap _swapper = new (); private readonly Save _saver = new (); + private readonly string _renderer; + private readonly string _version; + private bool _viewportFocus; private readonly Vector4 _accentColor = new (0.125f, 0.42f, 0.831f, 1.0f); private readonly Vector4 _alertColor = new (0.831f, 0.573f, 0.125f, 1.0f); @@ -49,6 +53,8 @@ public class SnimGui public SnimGui(int width, int height) { + _renderer = GL.GetString(StringName.Renderer); + _version = "OpenGL " + GL.GetString(StringName.Version); Controller = new ImGuiController(width, height); Theme(); } @@ -76,6 +82,46 @@ public void Render(Snooper s) private void DrawWorld(Snooper s) { + if (ImGui.BeginTable("world_details", 2, ImGuiTableFlags.SizingStretchProp)) + { + var length = s.Renderer.Options.Models.Count; + Layout("Renderer");ImGui.Text($" : {_renderer}"); + Layout("Version");ImGui.Text($" : {_version}"); + Layout("Loaded Models");ImGui.Text($" : x{length}");ImGui.SameLine(); + + var b = false; + if (ImGui.SmallButton("Save All")) + { + foreach (var model in s.Renderer.Options.Models.Values) + { + b |= model.TrySave(out _, out _); + } + } + + Modal("Saved", b, () => + { + ImGui.TextWrapped($"Successfully saved {length} models"); + ImGui.Separator(); + + var size = new Vector2(120, 0); + if (ImGui.Button("OK", size)) + { + ImGui.CloseCurrentPopup(); + } + + ImGui.SetItemDefaultFocus(); + ImGui.SameLine(); + + if (ImGui.Button("Show In Explorer", size)) + { + Process.Start("explorer.exe", $"/select, \"{UserSettings.Default.ModelDirectory.Replace('/', '\\')}\""); + ImGui.CloseCurrentPopup(); + } + }); + + ImGui.EndTable(); + } + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); if (ImGui.CollapsingHeader("Editor")) { @@ -194,7 +240,8 @@ private void DrawOuliner(Snooper s) { s.Renderer.Options.SelectModel(guid); } - if (ImGui.BeginPopupContextItem()) + + Popup(() => { s.Renderer.Options.SelectModel(guid); if (ImGui.MenuItem("Show", null, model.Show)) model.Show = !model.Show; @@ -206,6 +253,7 @@ private void DrawOuliner(Snooper s) _saver.Value = model.TrySave(out _saver.Label, out _saver.Path); s.WindowShouldFreeze(false); } + ImGui.BeginDisabled(true); // ImGui.BeginDisabled(!model.HasSkeleton); if (ImGui.Selectable("Animate")) @@ -213,23 +261,24 @@ private void DrawOuliner(Snooper s) s.Renderer.Options.AnimateMesh(true); s.WindowShouldClose(true, false); } + ImGui.EndDisabled(); if (ImGui.Selectable("Teleport To")) { var instancePos = model.Transforms[model.SelectedInstance].Position; s.Camera.Position = new Vector3(instancePos.X, instancePos.Y, instancePos.Z); } + if (ImGui.Selectable("Delete")) s.Renderer.Options.Models.Remove(guid); if (ImGui.Selectable("Deselect")) s.Renderer.Options.SelectModel(Guid.Empty); ImGui.Separator(); if (ImGui.Selectable("Copy Name to Clipboard")) ImGui.SetClipboardText(model.Name); - ImGui.EndPopup(); - } + }); ImGui.PopID(); i++; } - Popup("Saved", _saver.Value, () => + Modal("Saved", _saver.Value, () => { ImGui.TextWrapped($"Successfully saved {_saver.Label}"); ImGui.Separator(); @@ -332,7 +381,7 @@ private void DrawDetails(Snooper s) { s.Renderer.Options.SelectSection(i); } - if (ImGui.BeginPopupContextItem()) + Popup(() => { s.Renderer.Options.SelectSection(i); if (ImGui.MenuItem("Show", null, section.Show)) section.Show = !section.Show; @@ -347,13 +396,12 @@ private void DrawDetails(Snooper s) } ImGui.Separator(); if (ImGui.Selectable("Copy Name to Clipboard")) ImGui.SetClipboardText(material.Name); - ImGui.EndPopup(); - } + }); ImGui.PopID(); } ImGui.EndTable(); - Popup("Swap?", _swapper.Value, () => + Modal("Swap?", _swapper.Value, () => { ImGui.TextWrapped("You're about to swap a material.\nThe window will close for you to extract a material!\n\n"); ImGui.Separator(); @@ -386,64 +434,12 @@ private void DrawDetails(Snooper s) if (ImGui.BeginTabItem("Transform")) { - const int width = 100; - var speed = s.Camera.Speed / 100f; - ImGui.PushID(0); ImGui.BeginDisabled(model.TransformsCount < 2); ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X); ImGui.SliderInt("", ref model.SelectedInstance, 0, model.TransformsCount - 1, "Instance %i", ImGuiSliderFlags.AlwaysClamp); ImGui.EndDisabled(); ImGui.PopID(); - ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); - if (ImGui.TreeNode("Location")) - { - ImGui.PushID(1); - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("X", ref model.Transforms[model.SelectedInstance].Position.X, speed, 0f, 0f, "%.2f m"); - - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Position.Z, speed, 0f, 0f, "%.2f m"); - - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Position.Y, speed, 0f, 0f, "%.2f m"); - - ImGui.PopID(); - ImGui.TreePop(); - } - - ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); - if (ImGui.TreeNode("Rotation")) - { - ImGui.PushID(2); - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("X", ref model.Transforms[model.SelectedInstance].Rotation.Roll, .5f, 0f, 0f, "%.1f°"); - - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Rotation.Pitch, .5f, 0f, 0f, "%.1f°"); - - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Rotation.Yaw, .5f, 0f, 0f, "%.1f°"); - - ImGui.PopID(); - ImGui.TreePop(); - } - - if (ImGui.TreeNode("Scale")) - { - ImGui.PushID(3); - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("X", ref model.Transforms[model.SelectedInstance].Scale.X, speed, 0f, 0f, "%.3f"); - - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Scale.Z, speed, 0f, 0f, "%.3f"); - - ImGui.SetNextItemWidth(width); - ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Scale.Y, speed, 0f, 0f, "%.3f"); - - ImGui.PopID(); - ImGui.TreePop(); - } - + model.Transforms[model.SelectedInstance].ImGuiTransform(s.Camera.Speed / 100f); model.UpdateMatrix(model.SelectedInstance); ImGui.EndTabItem(); } @@ -586,8 +582,20 @@ private void Draw3DViewport(Snooper s) ImGui.PopStyleVar(); } - private void Popup(string title, bool condition, Action content) + private void Popup(Action content) + { + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(4f)); + if (ImGui.BeginPopupContextItem()) + { + content(); + ImGui.EndPopup(); + } + ImGui.PopStyleVar(); + } + + private void Modal(string title, bool condition, Action content) { + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(4f)); var pOpen = true; if (condition) ImGui.OpenPopup(title); ImGui.SetNextWindowPos(ImGui.GetMainViewport().GetCenter(), ImGuiCond.Appearing, new Vector2(.5f)); @@ -596,6 +604,7 @@ private void Popup(string title, bool condition, Action content) content(); ImGui.EndPopup(); } + ImGui.PopStyleVar(); } private void Window(string name, Action content, bool styled = true) diff --git a/FModel/Views/Snooper/Transform.cs b/FModel/Views/Snooper/Transform.cs index d1dd32ea..d5a0bdc9 100644 --- a/FModel/Views/Snooper/Transform.cs +++ b/FModel/Views/Snooper/Transform.cs @@ -1,5 +1,6 @@ using System.Numerics; using CUE4Parse.UE4.Objects.Core.Math; +using ImGuiNET; namespace FModel.Views.Snooper; @@ -22,4 +23,59 @@ public static Transform Identity Matrix4x4.CreateRotationZ(Helper.DegreesToRadians(Rotation.Pitch)) * Matrix4x4.CreateTranslation(Position) * Relation; + + public void ImGuiTransform(float speed) + { + const int width = 100; + + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); + if (ImGui.TreeNode("Location")) + { + ImGui.PushID(1); + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("X", ref Position.X, speed, 0f, 0f, "%.2f m"); + + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("Y", ref Position.Z, speed, 0f, 0f, "%.2f m"); + + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("Z", ref Position.Y, speed, 0f, 0f, "%.2f m"); + + ImGui.PopID(); + ImGui.TreePop(); + } + + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); + if (ImGui.TreeNode("Rotation")) + { + ImGui.PushID(2); + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("X", ref Rotation.Roll, .5f, 0f, 0f, "%.1f°"); + + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("Y", ref Rotation.Pitch, .5f, 0f, 0f, "%.1f°"); + + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("Z", ref Rotation.Yaw, .5f, 0f, 0f, "%.1f°"); + + ImGui.PopID(); + ImGui.TreePop(); + } + + if (ImGui.TreeNode("Scale")) + { + ImGui.PushID(3); + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("X", ref Scale.X, speed, 0f, 0f, "%.3f"); + + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("Y", ref Scale.Z, speed, 0f, 0f, "%.3f"); + + ImGui.SetNextItemWidth(width); + ImGui.DragFloat("Z", ref Scale.Y, speed, 0f, 0f, "%.3f"); + + ImGui.PopID(); + ImGui.TreePop(); + } + } }