diff --git a/CUE4Parse b/CUE4Parse index 2eb7988f..19781943 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit 2eb7988f9e80c15f6828dca37ced41ccccebdc84 +Subproject commit 19781943809b520d21bc038a1078148f632c1a4c diff --git a/FModel/Resources/default.frag b/FModel/Resources/default.frag index 87171dcd..458fa27f 100644 --- a/FModel/Resources/default.frag +++ b/FModel/Resources/default.frag @@ -3,12 +3,13 @@ in vec3 fPos; in vec3 fNormal; in vec2 fTexCoords; +in float fTexIndex; in vec4 fColor; struct Material { - sampler2D diffuseMap; - sampler2D normalMap; - sampler2D specularMap; + sampler2D diffuseMap[4]; + sampler2D normalMap[4]; + sampler2D specularMap[4]; sampler2D emissionMap; bool useSpecularMap; @@ -36,9 +37,21 @@ uniform bool display_vertex_colors; out vec4 FragColor; +vec4 getValueFromSamplerArray(sampler2D array[4]) { + if (fTexIndex < 1.0) { + return texture(array[0], fTexCoords); + } if (fTexIndex < 2.0) { + return texture(array[2], fTexCoords); + } if (fTexIndex < 3.0) { + return texture(array[1], fTexCoords); + } else { + return texture(array[3], fTexCoords); + } +} + vec3 getNormalFromMap() { - vec3 tangentNormal = texture(material.normalMap, fTexCoords).xyz * 2.0 - 1.0; + vec3 tangentNormal = getValueFromSamplerArray(material.normalMap).xyz * 2.0 - 1.0; vec3 q1 = dFdx(fPos); vec3 q2 = dFdy(fPos); @@ -73,10 +86,10 @@ void main() } else { - vec3 result = light.ambient * vec3(texture(material.diffuseMap, fTexCoords)); + vec3 result = light.ambient * vec3(getValueFromSamplerArray(material.diffuseMap)); // diffuse - vec4 diffuse_map = texture(material.diffuseMap, fTexCoords); + vec4 diffuse_map = getValueFromSamplerArray(material.diffuseMap); result += light.diffuse * diff * diffuse_map.rgb; // specular @@ -85,7 +98,7 @@ void main() 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)); + vec3 specular_map = vec3(getValueFromSamplerArray(material.specularMap)); result += specular_map.r * light.specular * (metallic * specular_map.b); result += material.roughness_value * specular_map.g; } diff --git a/FModel/Resources/default.vert b/FModel/Resources/default.vert index e874738a..ff6dd064 100644 --- a/FModel/Resources/default.vert +++ b/FModel/Resources/default.vert @@ -3,11 +3,12 @@ layout (location = 1) in vec3 vPos; layout (location = 2) in vec3 vNormal; layout (location = 3) in vec2 vTexCoords; -layout (location = 4) in vec4 vColor; -layout (location = 5) in ivec4 vBoneIds; -layout (location = 6) in vec4 vWeights; -layout (location = 7) in mat4 vInstanceMatrix; -layout (location = 11) in vec3 vMorphTarget; +layout (location = 4) in float vTexIndex; +layout (location = 5) in vec4 vColor; +layout (location = 6) in ivec4 vBoneIds; +layout (location = 7) in vec4 vWeights; +layout (location = 8) in mat4 vInstanceMatrix; +layout (location = 12) in vec3 vMorphTarget; uniform mat4 uView; uniform mat4 uProjection; @@ -16,6 +17,7 @@ uniform float uMorphTime; out vec3 fPos; out vec3 fNormal; out vec2 fTexCoords; +out float fTexIndex; out vec4 fColor; void main() @@ -26,5 +28,6 @@ void main() fPos = vec3(vInstanceMatrix * vec4(pos, 1.0)); fNormal = mat3(transpose(inverse(vInstanceMatrix))) * vNormal; fTexCoords = vTexCoords; + fTexIndex = vTexIndex; fColor = vColor; } diff --git a/FModel/Resources/outline.vert b/FModel/Resources/outline.vert index 1a6b8360..fe031346 100644 --- a/FModel/Resources/outline.vert +++ b/FModel/Resources/outline.vert @@ -2,8 +2,8 @@ layout (location = 1) in vec3 vPos; layout (location = 2) in vec3 vNormal; -layout (location = 7) in mat4 vInstanceMatrix; -layout (location = 11) in vec3 vMorphTarget; +layout (location = 8) in mat4 vInstanceMatrix; +layout (location = 12) in vec3 vMorphTarget; uniform mat4 uView; uniform mat4 uProjection; diff --git a/FModel/Views/Snooper/Material.cs b/FModel/Views/Snooper/Material.cs index b553e2ab..459cfe79 100644 --- a/FModel/Views/Snooper/Material.cs +++ b/FModel/Views/Snooper/Material.cs @@ -98,19 +98,19 @@ public class Material : IDisposable for (var i = 0; i < Diffuse.Length; i++) { - shader.SetUniform("material.diffuseMap", unit); + shader.SetUniform($"material.diffuseMap[{i}]", unit); Diffuse[i]?.Bind(TextureUnit.Texture0 + unit++); } for (var i = 0; i < Normals.Length; i++) { - shader.SetUniform("material.normalMap", unit); + shader.SetUniform($"material.normalMap[{i}]", unit); Normals[i]?.Bind(TextureUnit.Texture0 + unit++); } for (var i = 0; i < SpecularMasks.Length; i++) { - shader.SetUniform("material.specularMap", unit); + shader.SetUniform($"material.specularMap[{i}]", unit); SpecularMasks[i]?.Bind(TextureUnit.Texture0 + unit++); } diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs index 6862e43f..f9c9f24a 100644 --- a/FModel/Views/Snooper/Model.cs +++ b/FModel/Views/Snooper/Model.cs @@ -21,7 +21,7 @@ public class Model : IDisposable private BufferObject _matrixVbo; private VertexArrayObject _vao; - private readonly int _vertexSize = 9; // VertexIndex + Position + Normal + UV + private readonly int _vertexSize = 10; // VertexIndex + Position + Normal + UV + TextureIndex private readonly uint[] _facesIndex = { 1, 0, 2 }; private const int _faceSize = 3; // just so we don't have to do .Length @@ -79,7 +79,7 @@ public class Model : IDisposable for (int m = 0; m < Materials.Length; m++) { if (materials[m].TryLoad(out var material) && material is UMaterialInterface unrealMaterial) - Materials[m] = new Material(1, unrealMaterial); // lod.NumTexCoords + Materials[m] = new Material(lod.NumTexCoords, unrealMaterial); // lod.NumTexCoords } if (lod.VertexColors is { Length: > 0}) @@ -124,6 +124,7 @@ public class Model : IDisposable Vertices[baseIndex + count++] = vert.Normal.Y; Vertices[baseIndex + count++] = vert.UV.U; Vertices[baseIndex + count++] = vert.UV.V; + Vertices[baseIndex + count++] = lod.ExtraUV.IsValueCreated ? lod.ExtraUV.Value[0][indice].U : .5f; if (HasVertexColors) { @@ -184,9 +185,10 @@ public class Model : IDisposable _vao.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, _vertexSize, 1); // position _vao.VertexAttributePointer(2, 3, VertexAttribPointerType.Float, _vertexSize, 4); // normal _vao.VertexAttributePointer(3, 2, VertexAttribPointerType.Float, _vertexSize, 7); // uv - _vao.VertexAttributePointer(4, 4, VertexAttribPointerType.Float, _vertexSize, 9); // color - _vao.VertexAttributePointer(5, 4, VertexAttribPointerType.Int, _vertexSize, 13); // boneids - _vao.VertexAttributePointer(6, 4, VertexAttribPointerType.Float, _vertexSize, 17); // boneweights + _vao.VertexAttributePointer(4, 1, VertexAttribPointerType.Float, _vertexSize, 9); // texture index + _vao.VertexAttributePointer(5, 4, VertexAttribPointerType.Float, _vertexSize, 10); // color + _vao.VertexAttributePointer(6, 4, VertexAttribPointerType.Int, _vertexSize, 14); // boneids + _vao.VertexAttributePointer(7, 4, VertexAttribPointerType.Float, _vertexSize, 18); // boneweights { // instanced models transform TransformsCount = Transforms.Count; @@ -213,7 +215,7 @@ public class Model : IDisposable _morphVbo = new BufferObject(Morphs[morph].Vertices, BufferTarget.ArrayBuffer); } _vao.Bind(); - _vao.VertexAttributePointer(11, 3, VertexAttribPointerType.Float, 3, 0); // morph position + _vao.VertexAttributePointer(12, 3, VertexAttribPointerType.Float, 3, 0); // morph position _vao.Unbind(); } diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index b23feb89..c28f889b 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -184,15 +184,19 @@ public class Renderer : IDisposable if (textureData[j].Load() is not { } textureDataIdx) continue; + if (textureDataIdx.TryGetValue(out FPackageIndex overrideMaterial, "OverrideMaterial") && + overrideMaterial.TryLoad(out var material) && material is UMaterialInterface unrealMaterial) + unrealMaterial.GetParams(model.Sections[j].Material.Parameters); + if (textureDataIdx.TryGetValue(out FPackageIndex diffuse, "Diffuse") && diffuse.Load() is UTexture2D diffuseTexture) - model.Sections[j].Material.Parameters.Textures[CMaterialParams2.Diffuse[j]] = diffuseTexture; + model.Sections[j].Material.Parameters.Textures[CMaterialParams2.Diffuse[0]] = diffuseTexture; if (textureDataIdx.TryGetValue(out FPackageIndex normal, "Normal") && normal.Load() is UTexture2D normalTexture) - model.Sections[j].Material.Parameters.Textures[CMaterialParams2.Normals[j]] = normalTexture; + model.Sections[j].Material.Parameters.Textures[CMaterialParams2.Normals[0]] = normalTexture; if (textureDataIdx.TryGetValue(out FPackageIndex specular, "Specular") && specular.Load() is UTexture2D specularTexture) - model.Sections[j].Material.Parameters.Textures[CMaterialParams2.SpecularMasks[j]] = specularTexture; + model.Sections[j].Material.Parameters.Textures[CMaterialParams2.SpecularMasks[0]] = specularTexture; } } if (staticMeshComp.TryGetValue(out FPackageIndex[] overrideMaterials, "OverrideMaterials")) diff --git a/FModel/Views/Snooper/Texture.cs b/FModel/Views/Snooper/Texture.cs index d655b928..1df8f377 100644 --- a/FModel/Views/Snooper/Texture.cs +++ b/FModel/Views/Snooper/Texture.cs @@ -144,16 +144,6 @@ public class Texture : IDisposable GL.BindTexture(target, _handle); } - public void SetMinFilter(int filter) - { - GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ref filter); - } - - public void SetMagFilter(int filter) - { - GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ref filter); - } - public IntPtr GetPointer() => (IntPtr) _handle; public void Dispose() diff --git a/FModel/Views/Snooper/VertexArrayObject.cs b/FModel/Views/Snooper/VertexArrayObject.cs index 6f2dc2a6..4c178f7f 100644 --- a/FModel/Views/Snooper/VertexArrayObject.cs +++ b/FModel/Views/Snooper/VertexArrayObject.cs @@ -41,19 +41,19 @@ public class VertexArrayObject : IDisposable where TVer Bind(); var size = sizeof(Vector4); - GL.EnableVertexAttribArray(7); - GL.VertexAttribPointer(7, 4, VertexAttribPointerType.Float, false, 4 * size, 0); GL.EnableVertexAttribArray(8); - GL.VertexAttribPointer(8, 4, VertexAttribPointerType.Float, false, 4 * size, 1 * size); + GL.VertexAttribPointer(8, 4, VertexAttribPointerType.Float, false, 4 * size, 0); GL.EnableVertexAttribArray(9); - GL.VertexAttribPointer(9, 4, VertexAttribPointerType.Float, false, 4 * size, 2 * size); + GL.VertexAttribPointer(9, 4, VertexAttribPointerType.Float, false, 4 * size, 1 * size); GL.EnableVertexAttribArray(10); - GL.VertexAttribPointer(10, 4, VertexAttribPointerType.Float, false, 4 * size, 3 * size); + GL.VertexAttribPointer(10, 4, VertexAttribPointerType.Float, false, 4 * size, 2 * size); + GL.EnableVertexAttribArray(11); + GL.VertexAttribPointer(11, 4, VertexAttribPointerType.Float, false, 4 * size, 3 * size); - GL.VertexAttribDivisor(7, 1); GL.VertexAttribDivisor(8, 1); GL.VertexAttribDivisor(9, 1); GL.VertexAttribDivisor(10, 1); + GL.VertexAttribDivisor(11, 1); Unbind(); }