Add more bmd material conversion. Reorder bmd object draw, and check transparency
This commit is contained in:
parent
97dbb145ad
commit
5fc6522449
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -15,6 +15,14 @@ namespace FirstPlugin
|
||||
public Material Material;
|
||||
SuperBMDLib.Model ParentModel;
|
||||
|
||||
public bool isTransparent
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Material.Flag & 3) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public BMDMaterialWrapper(Material mat, SuperBMDLib.Model model)
|
||||
{
|
||||
Material = mat;
|
||||
|
@ -22,25 +22,54 @@ namespace FirstPlugin
|
||||
|
||||
}
|
||||
|
||||
public override void DrawModels(ShaderProgram shader, GL_ControlModern control)
|
||||
{
|
||||
shader.EnableVertexAttributes();
|
||||
|
||||
List<STGenericObject> opaque = new List<STGenericObject>();
|
||||
List<STGenericObject> transparent = new List<STGenericObject>();
|
||||
|
||||
for (int m = 0; m < Meshes.Count; m++)
|
||||
{
|
||||
if (((BMDMaterialWrapper)Meshes[m].GetMaterial()).isTransparent)
|
||||
transparent.Add(Meshes[m]);
|
||||
else
|
||||
opaque.Add(Meshes[m]);
|
||||
}
|
||||
|
||||
for (int m = 0; m < transparent.Count; m++)
|
||||
{
|
||||
DrawModel(control, Skeleton, transparent[m].GetMaterial(), transparent[m], shader);
|
||||
}
|
||||
|
||||
for (int m = 0; m < opaque.Count; m++)
|
||||
{
|
||||
DrawModel(control, Skeleton, opaque[m].GetMaterial(), opaque[m], shader);
|
||||
}
|
||||
shader.DisableVertexAttributes();
|
||||
}
|
||||
|
||||
public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m)
|
||||
{
|
||||
var bmdMaterial = (BMDMaterialWrapper)mat;
|
||||
|
||||
switch (bmdMaterial.Material.CullMode)
|
||||
shader.SetBoolToInt("isTransparent", bmdMaterial.isTransparent);
|
||||
|
||||
GXToOpenGL.SetBlendState(bmdMaterial.Material.BMode);
|
||||
GXToOpenGL.SetCullState(bmdMaterial.Material.CullMode);
|
||||
GXToOpenGL.SetDepthState(bmdMaterial.Material.ZMode, false);
|
||||
GXToOpenGL.SetDitherEnabled(bmdMaterial.Material.Dither);
|
||||
}
|
||||
|
||||
public static TextureMagFilter GetMagFilter(SuperBMDLib.Materials.BinaryTextureImage.FilterMode fromMode)
|
||||
{
|
||||
switch (fromMode)
|
||||
{
|
||||
case CullMode.None:
|
||||
GL.Disable(EnableCap.CullFace);
|
||||
break;
|
||||
case CullMode.Back:
|
||||
GL.CullFace(CullFaceMode.Back);
|
||||
break;
|
||||
case CullMode.Front:
|
||||
GL.CullFace(CullFaceMode.Front);
|
||||
break;
|
||||
case CullMode.All:
|
||||
GL.CullFace(CullFaceMode.FrontAndBack);
|
||||
break;
|
||||
case SuperBMDLib.Materials.BinaryTextureImage.FilterMode.Nearest: return TextureMagFilter.Nearest;
|
||||
case SuperBMDLib.Materials.BinaryTextureImage.FilterMode.Linear: return TextureMagFilter.Linear;
|
||||
}
|
||||
|
||||
return TextureMagFilter.Nearest;
|
||||
}
|
||||
|
||||
public override int BindTexture(STGenericMatTexture tex, ShaderProgram shader)
|
||||
|
154
Switch_FileFormatsMain/GL/GXToOpenGL.cs
Normal file
154
Switch_FileFormatsMain/GL/GXToOpenGL.cs
Normal file
@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK;
|
||||
using SuperBMDLib.Materials;
|
||||
using SuperBMDLib.Materials.Enums;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
//From https://github.com/LordNed/JStudio/blob/b9c4eabb1c7e80a8da7f63f8d5003df704de369c/JStudio/GXToOpenGL.cs
|
||||
public static class GXToOpenGL
|
||||
{
|
||||
public static TextureWrapMode GetWrapMode(BinaryTextureImage.WrapModes fromMode)
|
||||
{
|
||||
switch (fromMode)
|
||||
{
|
||||
case BinaryTextureImage.WrapModes.ClampToEdge: return TextureWrapMode.ClampToEdge;
|
||||
case BinaryTextureImage.WrapModes.Repeat: return TextureWrapMode.Repeat;
|
||||
case BinaryTextureImage.WrapModes.MirroredRepeat: return TextureWrapMode.MirroredRepeat;
|
||||
}
|
||||
|
||||
return TextureWrapMode.Repeat;
|
||||
}
|
||||
|
||||
public static TextureMinFilter GetMinFilter(BinaryTextureImage.FilterMode fromMode)
|
||||
{
|
||||
switch (fromMode)
|
||||
{
|
||||
case BinaryTextureImage.FilterMode.Nearest: return TextureMinFilter.Nearest;
|
||||
case BinaryTextureImage.FilterMode.Linear: return TextureMinFilter.Linear;
|
||||
case BinaryTextureImage.FilterMode.NearestMipmapNearest: return TextureMinFilter.NearestMipmapNearest;
|
||||
case BinaryTextureImage.FilterMode.NearestMipmapLinear: return TextureMinFilter.NearestMipmapLinear;
|
||||
case BinaryTextureImage.FilterMode.LinearMipmapNearest: return TextureMinFilter.LinearMipmapNearest;
|
||||
case BinaryTextureImage.FilterMode.LinearMipmapLinear: return TextureMinFilter.LinearMipmapLinear;
|
||||
}
|
||||
|
||||
return TextureMinFilter.Nearest;
|
||||
}
|
||||
|
||||
public static TextureMagFilter GetMagFilter(BinaryTextureImage.FilterMode fromMode)
|
||||
{
|
||||
switch (fromMode)
|
||||
{
|
||||
case BinaryTextureImage.FilterMode.Nearest: return TextureMagFilter.Nearest;
|
||||
case BinaryTextureImage.FilterMode.Linear: return TextureMagFilter.Linear;
|
||||
}
|
||||
|
||||
return TextureMagFilter.Nearest;
|
||||
}
|
||||
|
||||
public static void SetBlendState(SuperBMDLib.Materials.BlendMode blendMode)
|
||||
{
|
||||
if (blendMode.Type == SuperBMDLib.Materials.Enums.BlendMode.Blend)
|
||||
{
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(GetBlendFactorSrc(blendMode.SourceFact), GetBlendFactorDest(blendMode.DestinationFact));
|
||||
}
|
||||
else if (blendMode.Type == SuperBMDLib.Materials.Enums.BlendMode.None)
|
||||
{
|
||||
GL.Disable(EnableCap.Blend);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Logic, Subtract?
|
||||
}
|
||||
}
|
||||
|
||||
public static BlendingFactor GetBlendFactorSrc(BlendModeControl sourceFactor)
|
||||
{
|
||||
switch (sourceFactor)
|
||||
{
|
||||
case BlendModeControl.Zero: return BlendingFactor.Zero;
|
||||
case BlendModeControl.One: return BlendingFactor.One;
|
||||
case BlendModeControl.SrcColor: return BlendingFactor.SrcColor;
|
||||
case BlendModeControl.InverseSrcColor: return BlendingFactor.OneMinusSrcColor;
|
||||
case BlendModeControl.SrcAlpha: return BlendingFactor.SrcAlpha;
|
||||
case BlendModeControl.InverseSrcAlpha: return BlendingFactor.OneMinusSrcAlpha;
|
||||
case BlendModeControl.DstAlpha: return BlendingFactor.DstAlpha;
|
||||
case BlendModeControl.InverseDstAlpha: return BlendingFactor.OneMinusDstAlpha;
|
||||
default:
|
||||
Console.WriteLine("Unsupported GXBlendModeControl: \"{0}\" in GetOpenGLBlendSrc!", sourceFactor);
|
||||
return BlendingFactor.SrcAlpha;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static BlendingFactor GetBlendFactorDest(BlendModeControl destinationFactor)
|
||||
{
|
||||
switch (destinationFactor)
|
||||
{
|
||||
case BlendModeControl.Zero: return BlendingFactor.Zero;
|
||||
case BlendModeControl.One: return BlendingFactor.One;
|
||||
case BlendModeControl.SrcColor: return BlendingFactor.SrcColor;
|
||||
case BlendModeControl.InverseSrcColor: return BlendingFactor.OneMinusSrcColor;
|
||||
case BlendModeControl.SrcAlpha: return BlendingFactor.SrcAlpha;
|
||||
case BlendModeControl.InverseSrcAlpha: return BlendingFactor.OneMinusSrcAlpha;
|
||||
case BlendModeControl.DstAlpha: return BlendingFactor.DstAlpha;
|
||||
case BlendModeControl.InverseDstAlpha: return BlendingFactor.OneMinusDstAlpha;
|
||||
default:
|
||||
Console.WriteLine("Unsupported GXBlendModeControl: \"{0}\" in GetOpenGLBlendDest!", destinationFactor);
|
||||
return BlendingFactor.OneMinusSrcAlpha;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetCullState(CullMode cullState)
|
||||
{
|
||||
GL.Enable(EnableCap.CullFace);
|
||||
switch (cullState)
|
||||
{
|
||||
case CullMode.None: GL.Disable(EnableCap.CullFace); break;
|
||||
case CullMode.Front: GL.CullFace(CullFaceMode.Front); break;
|
||||
case CullMode.Back: GL.CullFace(CullFaceMode.Back); break;
|
||||
case CullMode.All: GL.CullFace(CullFaceMode.FrontAndBack); break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDepthState(ZMode depthState, bool bDepthOnlyPrePass)
|
||||
{
|
||||
if (depthState.Enable || bDepthOnlyPrePass)
|
||||
{
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
GL.DepthMask(depthState.UpdateEnable || bDepthOnlyPrePass);
|
||||
switch (depthState.Function)
|
||||
{
|
||||
case CompareType.Never: GL.DepthFunc(DepthFunction.Never); break;
|
||||
case CompareType.Less: GL.DepthFunc(DepthFunction.Less); break;
|
||||
case CompareType.Equal: GL.DepthFunc(DepthFunction.Equal); break;
|
||||
case CompareType.LEqual: GL.DepthFunc(DepthFunction.Lequal); break;
|
||||
case CompareType.Greater: GL.DepthFunc(DepthFunction.Greater); break;
|
||||
case CompareType.NEqual: GL.DepthFunc(DepthFunction.Notequal); break;
|
||||
case CompareType.GEqual: GL.DepthFunc(DepthFunction.Gequal); break;
|
||||
case CompareType.Always: GL.DepthFunc(DepthFunction.Always); break;
|
||||
default: Console.WriteLine("Unsupported GXCompareType: \"{0}\" in GetOpenGLDepthFunc!", depthState.Function); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
GL.DepthMask(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDitherEnabled(bool ditherEnabled)
|
||||
{
|
||||
if (ditherEnabled)
|
||||
GL.Enable(EnableCap.Dither);
|
||||
else
|
||||
GL.Disable(EnableCap.Dither);
|
||||
}
|
||||
}
|
||||
}
|
@ -173,6 +173,7 @@ namespace FirstPlugin.Forms
|
||||
public List<int> KeyFrames = new List<int>(); //Used for getting the frame of the list item
|
||||
|
||||
public bool IsLoading = false;
|
||||
private Thread Thread;
|
||||
private void LoadAniamtion(MaterialAnimation anim, MaterialAnimation.SamplerKeyGroup activeSampler)
|
||||
{
|
||||
if (activeSampler == null || IsLoading)
|
||||
@ -200,7 +201,7 @@ namespace FirstPlugin.Forms
|
||||
}
|
||||
}
|
||||
|
||||
Thread Thread = new Thread((ThreadStart)(() =>
|
||||
Thread = new Thread((ThreadStart)(() =>
|
||||
{
|
||||
for (int Frame = 0; Frame <= anim.FrameCount; Frame++)
|
||||
{
|
||||
|
@ -256,6 +256,7 @@
|
||||
<Compile Include="FileFormats\Texture\TPL.cs" />
|
||||
<Compile Include="FileFormats\Rom\GCDisk.cs" />
|
||||
<Compile Include="GL\BMD_Renderer.cs" />
|
||||
<Compile Include="GL\GXToOpenGL.cs" />
|
||||
<Compile Include="GUI\BMD\BMDModelImportSettings.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
Binary file not shown.
Binary file not shown.
@ -378,7 +378,7 @@ namespace Switch_Toolbox.Library.Rendering
|
||||
shader.SetBoolToInt("renderVertColor", Runtime.renderVertColor);
|
||||
}
|
||||
|
||||
private void DrawModels(ShaderProgram shader, GL_ControlModern control)
|
||||
public virtual void DrawModels(ShaderProgram shader, GL_ControlModern control)
|
||||
{
|
||||
shader.EnableVertexAttributes();
|
||||
foreach (STGenericObject shp in Meshes)
|
||||
@ -405,7 +405,7 @@ namespace Switch_Toolbox.Library.Rendering
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements);
|
||||
}
|
||||
|
||||
private void DrawModel(GLControl control, STSkeleton Skeleton, STGenericMaterial Material, STGenericObject m, ShaderProgram shader)
|
||||
public void DrawModel(GLControl control, STSkeleton Skeleton, STGenericMaterial Material, STGenericObject m, ShaderProgram shader)
|
||||
{
|
||||
if (m.PolygonGroups.Count > 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user