mirror of
https://github.com/4sval/FModel.git
synced 2026-03-31 22:25:38 -05:00
increased texture count for custom uv-ed models
This commit is contained in:
parent
857de890e9
commit
2fee3c6ffa
|
|
@ -89,7 +89,7 @@ struct Light {
|
|||
uniform Parameters uParameters;
|
||||
uniform Light uLights[MAX_LIGHT_COUNT];
|
||||
uniform int uNumLights;
|
||||
uniform int uNumTexCoords;
|
||||
uniform int uUvCount;
|
||||
uniform bool uHasVertexColors;
|
||||
uniform bool bVertexColors[6];
|
||||
uniform vec3 uViewPos;
|
||||
|
|
@ -98,7 +98,7 @@ out vec4 FragColor;
|
|||
|
||||
int LayerToIndex()
|
||||
{
|
||||
return clamp(int(fTexLayer), 0, uNumTexCoords - 1);
|
||||
return clamp(int(fTexLayer), 0, uUvCount - 1);
|
||||
}
|
||||
|
||||
vec2 ScaledTexCoords()
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ public class Material : IDisposable
|
|||
unrealMaterial.GetParams(Parameters);
|
||||
}
|
||||
|
||||
public void Setup(Options options, int numTexCoords)
|
||||
public void Setup(Options options, int uvCount)
|
||||
{
|
||||
_handle = GL.CreateProgram();
|
||||
|
||||
if (numTexCoords < 1 || Parameters.IsNull)
|
||||
if (uvCount < 1 || Parameters.IsNull)
|
||||
{
|
||||
Diffuse = new[] { new Texture(new FLinearColor(1f, 0f, 0f, 1f)) };
|
||||
Normals = new[] { new Texture(new FLinearColor(0.498f, 0.498f, 0.996f, 1f))};
|
||||
|
|
@ -81,15 +81,15 @@ public class Material : IDisposable
|
|||
else
|
||||
{
|
||||
{ // textures
|
||||
Diffuse = FillTextures(options, numTexCoords, Parameters.HasTopDiffuse, CMaterialParams2.Diffuse, CMaterialParams2.FallbackDiffuse, true);
|
||||
Normals = FillTextures(options, numTexCoords, Parameters.HasTopNormals, CMaterialParams2.Normals, CMaterialParams2.FallbackNormals);
|
||||
SpecularMasks = FillTextures(options, numTexCoords, Parameters.HasTopSpecularMasks, CMaterialParams2.SpecularMasks, CMaterialParams2.FallbackSpecularMasks);
|
||||
Emissive = FillTextures(options, numTexCoords, true, CMaterialParams2.Emissive, CMaterialParams2.FallbackEmissive);
|
||||
Diffuse = FillTextures(options, uvCount, Parameters.HasTopDiffuse, CMaterialParams2.Diffuse, CMaterialParams2.FallbackDiffuse, true);
|
||||
Normals = FillTextures(options, uvCount, Parameters.HasTopNormals, CMaterialParams2.Normals, CMaterialParams2.FallbackNormals);
|
||||
SpecularMasks = FillTextures(options, uvCount, Parameters.HasTopSpecularMasks, CMaterialParams2.SpecularMasks, CMaterialParams2.FallbackSpecularMasks);
|
||||
Emissive = FillTextures(options, uvCount, true, CMaterialParams2.Emissive, CMaterialParams2.FallbackEmissive);
|
||||
}
|
||||
|
||||
{ // colors
|
||||
DiffuseColor = FillColors(numTexCoords, Diffuse, CMaterialParams2.DiffuseColors, Vector4.One);
|
||||
EmissiveColor = FillColors(numTexCoords, Emissive, CMaterialParams2.EmissiveColors, Vector4.One);
|
||||
DiffuseColor = FillColors(uvCount, Diffuse, CMaterialParams2.DiffuseColors, Vector4.One);
|
||||
EmissiveColor = FillColors(uvCount, Emissive, CMaterialParams2.EmissiveColors, Vector4.One);
|
||||
}
|
||||
|
||||
{ // scalars
|
||||
|
|
@ -133,17 +133,17 @@ public class Material : IDisposable
|
|||
}
|
||||
|
||||
/// <param name="options">just the cache object</param>
|
||||
/// <param name="numTexCoords">number of item in the array</param>
|
||||
/// <param name="uvCount">number of item in the array</param>
|
||||
/// <param name="top">has at least 1 clearly defined texture, else will go straight to fallback</param>
|
||||
/// <param name="triggers">list of texture parameter names by uv channel</param>
|
||||
/// <param name="fallback">fallback texture name to use if no top texture found</param>
|
||||
/// <param name="first">if no top texture, no fallback texture, then use the first texture found</param>
|
||||
private Texture[] FillTextures(Options options, int numTexCoords, bool top, IReadOnlyList<string[]> triggers, string fallback, bool first = false)
|
||||
private Texture[] FillTextures(Options options, int uvCount, bool top, IReadOnlyList<string[]> triggers, string fallback, bool first = false)
|
||||
{
|
||||
UTexture2D original;
|
||||
Texture transformed;
|
||||
var fix = fallback == CMaterialParams2.FallbackSpecularMasks;
|
||||
var textures = new Texture[numTexCoords];
|
||||
var textures = new Texture[uvCount];
|
||||
|
||||
if (top)
|
||||
{
|
||||
|
|
@ -168,13 +168,13 @@ public class Material : IDisposable
|
|||
return textures;
|
||||
}
|
||||
|
||||
/// <param name="numTexCoords">number of item in the array</param>
|
||||
/// <param name="uvCount">number of item in the array</param>
|
||||
/// <param name="textures">reference array</param>
|
||||
/// <param name="triggers">list of color parameter names by uv channel</param>
|
||||
/// <param name="fallback">fallback color to use if no trigger was found</param>
|
||||
private Vector4[] FillColors(int numTexCoords, IReadOnlyList<Texture> textures, IReadOnlyList<string[]> triggers, Vector4 fallback)
|
||||
private Vector4[] FillColors(int uvCount, IReadOnlyList<Texture> textures, IReadOnlyList<string[]> triggers, Vector4 fallback)
|
||||
{
|
||||
var colors = new Vector4[numTexCoords];
|
||||
var colors = new Vector4[uvCount];
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
{
|
||||
if (textures[i] == null) continue;
|
||||
|
|
@ -297,8 +297,8 @@ public class Material : IDisposable
|
|||
{
|
||||
if (ImGui.BeginTable("material_textures", 2))
|
||||
{
|
||||
SnimGui.Layout("Channel");ImGui.PushID(1); ImGui.BeginDisabled(model.NumTexCoords < 2);
|
||||
ImGui.DragInt("", ref SelectedChannel, _step, 0, model.NumTexCoords - 1, "UV %i", ImGuiSliderFlags.AlwaysClamp);
|
||||
SnimGui.Layout("Channel");ImGui.PushID(1); ImGui.BeginDisabled(model.UvCount < 2);
|
||||
ImGui.DragInt("", ref SelectedChannel, _step, 0, model.UvCount - 1, "UV %i", ImGuiSliderFlags.AlwaysClamp);
|
||||
ImGui.EndDisabled();ImGui.PopID();SnimGui.Layout("Type");ImGui.PushID(2);
|
||||
ImGui.Combo("texture_type", ref SelectedTexture, "Diffuse\0Normals\0Specular\0Ambient Occlusion\0Emissive\0");
|
||||
ImGui.PopID();
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class Model : IDisposable
|
|||
public readonly string Type;
|
||||
public readonly bool HasVertexColors;
|
||||
public readonly bool HasMorphTargets;
|
||||
public readonly int NumTexCoords;
|
||||
public readonly int UvCount;
|
||||
public uint[] Indices;
|
||||
public float[] Vertices;
|
||||
public Section[] Sections;
|
||||
|
|
@ -64,13 +64,13 @@ public class Model : IDisposable
|
|||
Path = _export.GetPathName();
|
||||
Name = Path.SubstringAfterLast('/').SubstringBefore('.');
|
||||
Type = export.ExportType;
|
||||
NumTexCoords = 1;
|
||||
UvCount = 1;
|
||||
Transforms = new List<Transform>();
|
||||
}
|
||||
|
||||
public Model(UStaticMesh export, CStaticMesh staticMesh) : this(export, staticMesh, Transform.Identity) {}
|
||||
public Model(UStaticMesh export, CStaticMesh staticMesh, Transform transform) : this(export, export.Materials, null, staticMesh.LODs[0], staticMesh.LODs[0].Verts, transform) {}
|
||||
private Model(USkeletalMesh export, CSkeletalMesh skeletalMesh, Transform transform) : this(export, export.Materials, export.Skeleton, skeletalMesh.LODs[0], skeletalMesh.LODs[0].Verts, transform) {}
|
||||
public Model(UStaticMesh export, CStaticMesh staticMesh, Transform transform) : this(export, export.Materials, null, staticMesh.LODs.Count, staticMesh.LODs[0], staticMesh.LODs[0].Verts, transform) {}
|
||||
private Model(USkeletalMesh export, CSkeletalMesh skeletalMesh, Transform transform) : this(export, export.Materials, export.Skeleton, skeletalMesh.LODs.Count, skeletalMesh.LODs[0], skeletalMesh.LODs[0].Verts, transform) {}
|
||||
public Model(USkeletalMesh export, CSkeletalMesh skeletalMesh) : this(export, skeletalMesh, Transform.Identity)
|
||||
{
|
||||
var morphTargets = export.MorphTargets;
|
||||
|
|
@ -89,9 +89,10 @@ public class Model : IDisposable
|
|||
ApplicationService.ApplicationView.Status.UpdateStatusLabel("");
|
||||
}
|
||||
|
||||
private Model(UObject export, ResolvedObject[] materials, FPackageIndex skeleton, CBaseMeshLod lod, CMeshVertex[] vertices, Transform transform = null) : this(export)
|
||||
private Model(UObject export, ResolvedObject[] materials, FPackageIndex skeleton, int numLods, CBaseMeshLod lod, CMeshVertex[] vertices, Transform transform = null) : this(export)
|
||||
{
|
||||
NumTexCoords = lod.NumTexCoords;
|
||||
var hasCustomUvs = lod.ExtraUV.IsValueCreated;
|
||||
UvCount = hasCustomUvs ? Math.Max(lod.NumTexCoords, numLods) : lod.NumTexCoords;
|
||||
|
||||
Materials = new Material[materials.Length];
|
||||
for (int m = 0; m < Materials.Length; m++)
|
||||
|
|
@ -136,7 +137,7 @@ public class Model : IDisposable
|
|||
Vertices[baseIndex + count++] = vert.Tangent.Y;
|
||||
Vertices[baseIndex + count++] = vert.UV.U;
|
||||
Vertices[baseIndex + count++] = vert.UV.V;
|
||||
Vertices[baseIndex + count++] = lod.ExtraUV.IsValueCreated ? lod.ExtraUV.Value[0][i].U : .5f;
|
||||
Vertices[baseIndex + count++] = hasCustomUvs ? lod.ExtraUV.Value[0][i].U : .5f;
|
||||
|
||||
if (HasVertexColors)
|
||||
{
|
||||
|
|
@ -226,7 +227,7 @@ public class Model : IDisposable
|
|||
for (var i = 0; i < Materials.Length; i++)
|
||||
{
|
||||
if (!Materials[i].IsUsed) continue;
|
||||
Materials[i].Setup(options, broken ? 1 : NumTexCoords);
|
||||
Materials[i].Setup(options, broken ? 1 : UvCount);
|
||||
}
|
||||
|
||||
if (HasMorphTargets)
|
||||
|
|
@ -261,7 +262,7 @@ public class Model : IDisposable
|
|||
|
||||
_vao.Bind();
|
||||
shader.SetUniform("uMorphTime", MorphTime);
|
||||
shader.SetUniform("uNumTexCoords", NumTexCoords);
|
||||
shader.SetUniform("uUvCount", UvCount);
|
||||
shader.SetUniform("uHasVertexColors", HasVertexColors);
|
||||
|
||||
GL.PolygonMode(MaterialFace.FrontAndBack, Wireframe ? PolygonMode.Line : PolygonMode.Fill);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class Renderer : IDisposable
|
|||
if (!Options.TryGetModel(out var model) || !Options.TryGetSection(model, out var section)) return;
|
||||
|
||||
model.Materials[section.MaterialIndex].SwapMaterial(unrealMaterial);
|
||||
Application.Current.Dispatcher.Invoke(() => model.Materials[section.MaterialIndex].Setup(Options, model.NumTexCoords));
|
||||
Application.Current.Dispatcher.Invoke(() => model.Materials[section.MaterialIndex].Setup(Options, model.UvCount));
|
||||
Options.SwapMaterial(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -321,7 +321,7 @@ hello world!
|
|||
|
||||
ImGui.Text(model.TransformsCount.ToString("D"));
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text(model.NumTexCoords.ToString("D"));
|
||||
ImGui.Text(model.UvCount.ToString("D"));
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGui.Selectable(model.Name, s.Renderer.Options.SelectedModel == guid, ImGuiSelectableFlags.SpanAllColumns))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user