Load textures in viewport for bcres
This commit is contained in:
parent
9714556c3b
commit
032e09d5a6
@ -85,6 +85,7 @@ namespace FirstPlugin
|
||||
break;
|
||||
case BCRESGroupType.Textures:
|
||||
Folder.AddNode(new TXOBWrapper((Texture)section, this));
|
||||
PluginRuntime.bcresTexContainers.Add(Folder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace FirstPlugin
|
||||
public CRESSkeletonWrapper Skeleton;
|
||||
|
||||
public List<SOBJWrapper> Shapes = new List<SOBJWrapper>();
|
||||
public List<MTOBWrapper> Materials = new List<MTOBWrapper>();
|
||||
|
||||
public CMDLWrapper()
|
||||
{
|
||||
@ -70,6 +71,7 @@ namespace FirstPlugin
|
||||
if (matWrapper.Text == string.Empty)
|
||||
matWrapper.Text = $"Material {Index++}";
|
||||
MaterialFolder.Nodes.Add(matWrapper);
|
||||
Materials.Add(matWrapper);
|
||||
}
|
||||
|
||||
Index = 0;
|
||||
|
@ -35,7 +35,20 @@ namespace FirstPlugin
|
||||
{
|
||||
Material = material;
|
||||
|
||||
Text = material.Name;
|
||||
Text = material.Name;
|
||||
|
||||
int textureUnit = 1;
|
||||
if (material.TextureMapInfo1 != null)
|
||||
{
|
||||
STGenericMatTexture tex1 = new STGenericMatTexture();
|
||||
var TexRef = material.TextureMapInfo1.TextureRef;
|
||||
var Sampler = material.TextureMapInfo1.Sampler;
|
||||
|
||||
tex1.textureUnit = textureUnit++;
|
||||
tex1.Name = TexRef.Reference.Name;
|
||||
tex1.Type = STGenericMatTexture.TextureType.Diffuse;
|
||||
TextureMaps.Add(tex1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,12 @@ namespace FirstPlugin
|
||||
set { ParentModelWrapper.Model.Shapes[ShapeIndex] = value; }
|
||||
}
|
||||
|
||||
public MTOBWrapper MaterialWrapper
|
||||
{
|
||||
get { return ParentModelWrapper.Materials[ShapeIndex]; }
|
||||
set { ParentModelWrapper.Materials[ShapeIndex] = value; }
|
||||
}
|
||||
|
||||
public SOBJWrapper()
|
||||
{
|
||||
ImageKey = "Material";
|
||||
@ -80,7 +86,7 @@ namespace FirstPlugin
|
||||
|
||||
displayVertList.Add(displayVert);
|
||||
|
||||
Console.WriteLine($"---------------------------------------------------------------------------------------");
|
||||
/* Console.WriteLine($"---------------------------------------------------------------------------------------");
|
||||
Console.WriteLine($"Position {displayVert.pos.X} {displayVert.pos.Y} {displayVert.pos.Z}");
|
||||
Console.WriteLine($"Normal {displayVert.nrm.X} {displayVert.nrm.Y} {displayVert.nrm.Z}");
|
||||
Console.WriteLine($"Tanget {displayVert.tan.X} {displayVert.tan.Y} {displayVert.tan.Z}");
|
||||
@ -90,7 +96,7 @@ namespace FirstPlugin
|
||||
Console.WriteLine($"UV Layer 3 {displayVert.uv3.X} {displayVert.uv3.Y}");
|
||||
Console.WriteLine($"Bone Index {displayVert.node.X} {displayVert.node.Y} {displayVert.node.Z} {displayVert.node.W}");
|
||||
Console.WriteLine($"Weights {displayVert.weight.X} {displayVert.weight.Y} {displayVert.weight.Z} {displayVert.weight.W}");
|
||||
Console.WriteLine($"---------------------------------------------------------------------------------------");
|
||||
Console.WriteLine($"---------------------------------------------------------------------------------------");*/
|
||||
}
|
||||
|
||||
return displayVertList;
|
||||
@ -131,11 +137,12 @@ namespace FirstPlugin
|
||||
lodMeshes = new List<LOD_Mesh>();
|
||||
foreach (var group in Shape.FaceGroups)
|
||||
{
|
||||
LOD_Mesh msh = new LOD_Mesh();
|
||||
|
||||
foreach (var faceDescriptors in group.FaceDescriptors)
|
||||
{
|
||||
foreach (var buffer in faceDescriptors.Buffers)
|
||||
{
|
||||
LOD_Mesh msh = new LOD_Mesh();
|
||||
msh.PrimitiveType = STPolygonType.Triangle;
|
||||
msh.FirstVertex = 0;
|
||||
|
||||
@ -144,10 +151,10 @@ namespace FirstPlugin
|
||||
{
|
||||
msh.faces.Add((int)indicesArray[face] + (int)msh.FirstVertex);
|
||||
}
|
||||
|
||||
lodMeshes.Add(msh);
|
||||
}
|
||||
}
|
||||
|
||||
lodMeshes.Add(msh);
|
||||
}
|
||||
|
||||
for (int vtxGrp = 0; vtxGrp < Shape.VertexGroups.Count; vtxGrp++)
|
||||
|
@ -30,6 +30,7 @@ namespace FirstPlugin
|
||||
GL.GenBuffers(1, out ibo_elements);
|
||||
|
||||
UpdateVertexData();
|
||||
UpdateTextureMaps();
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
@ -81,6 +82,23 @@ namespace FirstPlugin
|
||||
LibraryGUI.Instance.UpdateViewport();
|
||||
}
|
||||
|
||||
public void UpdateTextureMaps()
|
||||
{
|
||||
if (!Runtime.OpenTKInitialized)
|
||||
return;
|
||||
|
||||
foreach (BCRESGroupNode bcresTexGroup in PluginRuntime.bcresTexContainers)
|
||||
{
|
||||
foreach (var tex in bcresTexGroup.ResourceNodes)
|
||||
{
|
||||
if (!((TXOBWrapper)tex.Value).RenderableTex.GLInitialized)
|
||||
((TXOBWrapper)tex.Value).LoadOpenGLTexture();
|
||||
}
|
||||
}
|
||||
|
||||
LibraryGUI.Instance.UpdateViewport();
|
||||
}
|
||||
|
||||
public ShaderProgram defaultShaderProgram;
|
||||
|
||||
public override void Prepare(GL_ControlModern control)
|
||||
@ -139,6 +157,69 @@ namespace FirstPlugin
|
||||
DrawModels(shader, control);
|
||||
}
|
||||
|
||||
private static void SetTextureUniforms(MTOBWrapper mat, SOBJWrapper m, ShaderProgram shader)
|
||||
{
|
||||
SetDefaultTextureAttributes(mat, shader);
|
||||
|
||||
GL.ActiveTexture(TextureUnit.Texture0 + 1);
|
||||
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id);
|
||||
|
||||
foreach (STGenericMatTexture matex in mat.TextureMaps)
|
||||
{
|
||||
if (matex.Type == STGenericMatTexture.TextureType.Diffuse)
|
||||
TextureUniform(shader, mat, true, "DiffuseMap", matex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TextureUniform(ShaderProgram shader, MTOBWrapper mat, bool hasTex, string name, STGenericMatTexture mattex)
|
||||
{
|
||||
if (mattex.textureState == STGenericMatTexture.TextureState.Binded)
|
||||
return;
|
||||
|
||||
// Bind the texture and create the uniform if the material has the right textures.
|
||||
if (hasTex)
|
||||
{
|
||||
GL.Uniform1(shader[name], BindTexture(mattex));
|
||||
}
|
||||
}
|
||||
|
||||
public static int BindTexture(STGenericMatTexture tex)
|
||||
{
|
||||
GL.ActiveTexture(TextureUnit.Texture0 + tex.textureUnit + 1);
|
||||
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id);
|
||||
|
||||
string activeTex = tex.Name;
|
||||
|
||||
foreach (var bcresTexContainer in PluginRuntime.bcresTexContainers)
|
||||
{
|
||||
|
||||
if (bcresTexContainer.ResourceNodes.ContainsKey(activeTex))
|
||||
{
|
||||
TXOBWrapper txob = (TXOBWrapper)bcresTexContainer.ResourceNodes[activeTex];
|
||||
|
||||
if (txob.RenderableTex == null || !txob.RenderableTex.GLInitialized)
|
||||
txob.LoadOpenGLTexture();
|
||||
|
||||
BindGLTexture(tex, txob.RenderableTex.TexID);
|
||||
}
|
||||
}
|
||||
return tex.textureUnit + 1;
|
||||
}
|
||||
private static void BindGLTexture(STGenericMatTexture tex, int texid)
|
||||
{
|
||||
// GL.ActiveTexture(TextureUnit.Texture0 + texid);
|
||||
GL.BindTexture(TextureTarget.Texture2D, texid);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)STGenericMatTexture.wrapmode[tex.wrapModeS]);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)STGenericMatTexture.wrapmode[tex.wrapModeT]);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)STGenericMatTexture.minfilter[tex.minFilter]);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)STGenericMatTexture.magfilter[tex.magFilter]);
|
||||
GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, 0.0f);
|
||||
}
|
||||
|
||||
private static void SetDefaultTextureAttributes(MTOBWrapper mat, ShaderProgram shader)
|
||||
{
|
||||
}
|
||||
|
||||
private void SetRenderSettings(ShaderProgram shader)
|
||||
{
|
||||
shader.SetInt("renderType", (int)Runtime.viewportShading);
|
||||
@ -183,6 +264,7 @@ namespace FirstPlugin
|
||||
return;
|
||||
|
||||
SetVertexAttributes(m, shader);
|
||||
SetTextureUniforms(m.MaterialWrapper, m, shader);
|
||||
|
||||
if ((m.IsSelected))
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ namespace FirstPlugin
|
||||
public static Dictionary<string, BFLIM> bflimTextures = new Dictionary<string, BFLIM>();
|
||||
public static List<BNTX> bntxContainers = new List<BNTX>();
|
||||
public static List<BFRESGroupNode> ftexContainers = new List<BFRESGroupNode>();
|
||||
public static List<BCRESGroupNode> bcresTexContainers = new List<BCRESGroupNode>();
|
||||
public static string ExternalFMATPath = "";
|
||||
public static string OdysseyGamePath = "";
|
||||
public static string Mk8GamePath = "";
|
||||
|
Binary file not shown.
Binary file not shown.
@ -405,23 +405,8 @@ namespace Switch_Toolbox.Library
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* try
|
||||
{
|
||||
Bitmap bitmap = BitmapExtension.GetBitmap(DecodeBlock(data, width, height, Format),
|
||||
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Failed to texture {Text} \n{DebugInfo()}\n {ex.ToString()}");
|
||||
return null;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
public static Bitmap DecodeBlockGetBitmap(byte[] data, uint Width, uint Height, TEX_FORMAT Format)
|
||||
{
|
||||
Bitmap bitmap = BitmapExtension.GetBitmap(DecodeBlock(data, Width, Height, Format),
|
||||
@ -438,7 +423,7 @@ namespace Switch_Toolbox.Library
|
||||
/// <param name="Height">The height of the image in pixels.</param>
|
||||
/// <param name=" DDS.DXGI_FORMAT">The image format.</param>
|
||||
/// <returns>Returns a byte array of decoded data. </returns>
|
||||
public static byte[] DecodeBlock(byte[] data, uint Width, uint Height, TEX_FORMAT Format)
|
||||
public static byte[] DecodeBlock(byte[] data, uint Width, uint Height, TEX_FORMAT Format, PlatformSwizzle PlatformSwizzle = PlatformSwizzle.None)
|
||||
{
|
||||
if (data == null) throw new Exception($"Data is null!");
|
||||
if (Format <= 0) throw new Exception($"Invalid Format!");
|
||||
@ -446,10 +431,14 @@ namespace Switch_Toolbox.Library
|
||||
if (Width <= 0) throw new Exception($"Invalid width size {Width}!");
|
||||
if (Height <= 0) throw new Exception($"Invalid height size {Height}!");
|
||||
|
||||
if (PlatformSwizzle == PlatformSwizzle.Platform_3DS && !IsCompressed(Format))
|
||||
{
|
||||
return ConvertBgraToRgba(CTR_3DS.DecodeBlock(data, (int)Width, (int)Height, Format));
|
||||
}
|
||||
|
||||
if (Format == TEX_FORMAT.R32G8X24_FLOAT)
|
||||
return ConvertBgraToRgba(DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, DDS.DXGI_FORMAT.DXGI_FORMAT_R32G8X24_TYPELESS));
|
||||
|
||||
|
||||
if (Format == TEX_FORMAT.BC5_SNORM)
|
||||
return ConvertBgraToRgba(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true, true));
|
||||
|
||||
|
@ -96,6 +96,16 @@ namespace Switch_Toolbox.Library.Rendering
|
||||
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
||||
break;
|
||||
case TEX_FORMAT.R8G8B8A8_UNORM_SRGB:
|
||||
pixelInternalFormat = PixelInternalFormat.Rgba;
|
||||
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
||||
break;
|
||||
default:
|
||||
data = STGenericTexture.DecodeBlock(data,
|
||||
GenericTexture.Width,
|
||||
GenericTexture.Height,
|
||||
GenericTexture.Format,
|
||||
GenericTexture.PlatformSwizzle);
|
||||
|
||||
pixelInternalFormat = PixelInternalFormat.Rgba;
|
||||
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
||||
break;
|
||||
|
Binary file not shown.
Binary file not shown.
@ -3,6 +3,12 @@ in vec3 normal;
|
||||
in vec4 color;
|
||||
in vec3 position;
|
||||
|
||||
|
||||
in vec2 f_texcoord0;
|
||||
in vec2 f_texcoord1;
|
||||
in vec2 f_texcoord2;
|
||||
in vec2 f_texcoord3;
|
||||
|
||||
uniform vec3 difLightDirection;
|
||||
uniform vec3 difLightColor;
|
||||
uniform vec3 ambLightColor;
|
||||
@ -13,6 +19,10 @@ uniform int renderType;
|
||||
uniform int renderVertColor;
|
||||
uniform mat4 modelview;
|
||||
|
||||
uniform int HasDiffuse;
|
||||
|
||||
uniform sampler2D DiffuseMap;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
@ -36,7 +46,7 @@ void main()
|
||||
// Diffuse lighting.
|
||||
float halfLambert = dot(difLightDirection, normal) * 0.5 + 0.5;
|
||||
|
||||
vec4 diffuseMapColor = vec4(0.6);
|
||||
vec4 diffuseMapColor = vec4(texture(DiffuseMap, f_texcoord0).rgb, 1);
|
||||
diffuseMapColor *= halfLambert;
|
||||
|
||||
FragColor = vec4(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user