diff --git a/FModel/Resources/default.frag b/FModel/Resources/default.frag index 0838d154..2723f6c4 100644 --- a/FModel/Resources/default.frag +++ b/FModel/Resources/default.frag @@ -59,35 +59,41 @@ void main() { FragColor = fColor; } - else if (material.hasDiffuseColor) - { - FragColor = material.diffuseColor; - } else { vec3 n_normal_map = getNormalFromMap(); vec3 n_light_direction = normalize(light.position - fPos); - vec3 result = light.ambient * vec3(texture(material.diffuseMap, fTexCoords)); - - // diffuse float diff = max(dot(n_normal_map, n_light_direction), 0.0f); - vec4 diffuse_map = texture(material.diffuseMap, fTexCoords); - result += light.diffuse * diff * diffuse_map.rgb; - // specular - if (material.useSpecularMap) + if (material.hasDiffuseColor) { - vec3 n_view_direction = normalize(viewPos - fPos); - vec3 reflect_direction = reflect(-n_light_direction, n_normal_map); - float metallic = pow(max(dot(n_view_direction, reflect_direction), 0.0f), material.metallic_value); - vec3 specular_map = vec3(texture(material.specularMap, fTexCoords)); - result += light.specular * metallic * specular_map.b * material.roughness_value * specular_map.g * specular_map.r; + vec4 result = vec4(light.ambient, 1.0) * material.diffuseColor; + result += vec4(light.diffuse, 1.0) * diff * material.diffuseColor; + FragColor = result; } + else + { + vec3 result = light.ambient * vec3(texture(material.diffuseMap, fTexCoords)); - // emission - vec3 emission_map = vec3(texture(material.emissionMap, fTexCoords)); - result += material.emissionColor.rgb * emission_map; + // diffuse + vec4 diffuse_map = texture(material.diffuseMap, fTexCoords); + result += light.diffuse * diff * diffuse_map.rgb; - FragColor = vec4(result, 1.0); + // specular + if (material.useSpecularMap) + { + vec3 n_view_direction = normalize(viewPos - fPos); + vec3 reflect_direction = reflect(-n_light_direction, n_normal_map); + float metallic = pow(max(dot(n_view_direction, reflect_direction), 0.0f), material.metallic_value); + vec3 specular_map = vec3(texture(material.specularMap, fTexCoords)); + result += light.specular * metallic * specular_map.b * material.roughness_value * specular_map.g * specular_map.r; + } + + // emission + vec3 emission_map = vec3(texture(material.emissionMap, fTexCoords)); + result += material.emissionColor.rgb * emission_map; + + FragColor = vec4(result, 1.0); + } } } diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs index 80af062e..f9fa9c6a 100644 --- a/FModel/Views/Snooper/Model.cs +++ b/FModel/Views/Snooper/Model.cs @@ -18,7 +18,6 @@ public class Model : IDisposable private BufferObject _ebo; private BufferObject _vbo; - private BufferObject[] _morphVbo; private BufferObject _matrixVbo; private VertexArrayObject _vao; @@ -54,8 +53,6 @@ public class Model : IDisposable Transforms = new List(); Show = true; IsSavable = owner is not UWorld; - - _morphVbo = Array.Empty>(); } public Model(UObject owner, string name, string type, CBaseMeshLod lod, CMeshVertex[] vertices, FPackageIndex[] morphTargets = null, List skeleton = null, Transform transform = null) @@ -71,7 +68,6 @@ public class Model : IDisposable HasMorphTargets = morphTargets != null; if (HasMorphTargets) { - _morphVbo = new BufferObject[4 * morphTargets.Length]; // PositionDelta + SourceIdx var morph = morphTargets[0].Load().MorphLODModels[0]; foreach (var delta in morph.Vertices) { @@ -229,10 +225,6 @@ public class Model : IDisposable _ebo.Dispose(); _vbo.Dispose(); _matrixVbo.Dispose(); - for (int i = 0; i < _morphVbo.Length; i++) - { - _morphVbo[i].Dispose(); - } _vao.Dispose(); for (int section = 0; section < Sections.Length; section++) { diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs index dc649568..5baffb94 100644 --- a/FModel/Views/Snooper/SnimGui.cs +++ b/FModel/Views/Snooper/SnimGui.cs @@ -313,10 +313,12 @@ public class SnimGui : IDisposable ImGui.EndTabItem(); } + ImGui.BeginDisabled(!model.HasMorphTargets); if (ImGui.BeginTabItem("Shape Keys")) { ImGui.EndTabItem(); } + ImGui.EndDisabled(); } ImGui.End(); @@ -342,7 +344,7 @@ public class SnimGui : IDisposable ImGui.SetNextItemWidth(300); ImGui.ColorEdit4(section.TexturesLabels[0], ref section.DiffuseColor, ImGuiColorEditFlags.AlphaPreview | ImGuiColorEditFlags.AlphaBar); } - else + // else { for (var i = 0; i < section.Textures.Length; i++) { @@ -388,23 +390,6 @@ public class SnimGui : IDisposable } ImGui.EndGroup(); - // ImGui.Text($"Faces: {FacesCount} ({Math.Round(FacesCount / indices * 100f, 2)}%%)"); - // ImGui.Text($"First Face: {FirstFaceIndex}"); - // ImGui.Separator(); - // if (_hasDiffuseColor) - // { - // ImGui.ColorEdit4("Diffuse Color", ref _diffuseColor, ImGuiColorEditFlags.NoInputs); - // } - // else - // { - // ImGui.Text($"Diffuse: ({Parameters.Diffuse?.ExportType}) {Parameters.Diffuse?.Name}"); - // ImGui.Text($"Normal: ({Parameters.Normal?.ExportType}) {Parameters.Normal?.Name}"); - // ImGui.Text($"Specular: ({Parameters.Specular?.ExportType}) {Parameters.Specular?.Name}"); - // if (Parameters.HasTopEmissiveTexture) - // ImGui.Text($"Emissive: ({Parameters.Emissive?.ExportType}) {Parameters.Emissive?.Name}"); - // ImGui.Separator(); - // } - ImGui.End(); }