mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-10 07:04:36 +00:00
Keep the same depend index for shader params (Fix WWHD crashing)
This commit is contained in:
parent
d4419ec67a
commit
827e02892a
19 changed files with 365 additions and 7 deletions
|
@ -40,11 +40,13 @@ namespace FirstPlugin
|
|||
}
|
||||
|
||||
public BcresFile BcresFile;
|
||||
public BCRES_Render RenderedBcres;
|
||||
|
||||
public void Load(System.IO.Stream stream)
|
||||
{
|
||||
Text = FileName;
|
||||
BcresFile = new BcresFile(stream);
|
||||
RenderedBcres = new BCRES_Render();
|
||||
|
||||
AddNodeGroup(BcresFile.Data.Models, new BCRESGroupNode(BCRESGroupType.Models));
|
||||
AddNodeGroup(BcresFile.Data.Textures, new BCRESGroupNode(BCRESGroupType.Textures));
|
||||
|
@ -75,7 +77,9 @@ namespace FirstPlugin
|
|||
switch (Folder.Type)
|
||||
{
|
||||
case BCRESGroupType.Models:
|
||||
Folder.AddNode(new CMDLWrapper((Model)section, this));
|
||||
var CMDLWrapper = new CMDLWrapper((Model)section, this);
|
||||
Folder.AddNode(CMDLWrapper);
|
||||
RenderedBcres.Models.Add(CMDLWrapper);
|
||||
break;
|
||||
case BCRESGroupType.Textures:
|
||||
Folder.AddNode(new TXOBWrapper((Texture)section, this));
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace FirstPlugin
|
|||
internal BCRES BcresParent;
|
||||
internal Model Model;
|
||||
|
||||
public List<SOBJWrapper> Shapes = new List<SOBJWrapper>();
|
||||
|
||||
public CMDLWrapper()
|
||||
{
|
||||
ImageKey = "Model";
|
||||
|
@ -44,13 +46,26 @@ namespace FirstPlugin
|
|||
Text = model.Name;
|
||||
|
||||
var MaterialFolder = new TreeNode("Materials");
|
||||
var MeshFolder = new TreeNode("Meshes");
|
||||
|
||||
Nodes.Add(MeshFolder);
|
||||
Nodes.Add(MaterialFolder);
|
||||
|
||||
foreach (var material in model.Materials.Values)
|
||||
{
|
||||
var matWrapper = new MTOBWrapper() { BcresParent = bcres };
|
||||
matWrapper.Load(material);
|
||||
MaterialFolder.Nodes.Add(matWrapper);
|
||||
}
|
||||
foreach (var mesh in model.Meshes)
|
||||
{
|
||||
var meshWrapper = new SOBJWrapper() { BcresParent = bcres };
|
||||
meshWrapper.Load(mesh);
|
||||
MeshFolder.Nodes.Add(meshWrapper);
|
||||
Shapes.Add(meshWrapper);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Switch_Toolbox.Library;
|
||||
using Switch_Toolbox.Library.Rendering;
|
||||
using BcresLibrary;
|
||||
using OpenTK;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class SOBJWrapper : STGenericObject
|
||||
{
|
||||
internal Model ParentModel;
|
||||
internal BCRES BcresParent;
|
||||
internal Mesh Mesh;
|
||||
|
||||
public int[] Faces;
|
||||
public int[] display;
|
||||
public int DisplayId;
|
||||
|
||||
public int ShapeIndex
|
||||
{
|
||||
get { return (int)Mesh.ShapeIndex; }
|
||||
set { Mesh.ShapeIndex = (uint)value; }
|
||||
}
|
||||
|
||||
public Shape Shape
|
||||
{
|
||||
get { return ParentModel.Shapes[ShapeIndex]; }
|
||||
set { ParentModel.Shapes[ShapeIndex] = value; }
|
||||
}
|
||||
|
||||
public SOBJWrapper()
|
||||
{
|
||||
ImageKey = "Material";
|
||||
SelectedImageKey = "Material";
|
||||
}
|
||||
public SOBJWrapper(Model model, Mesh mesh) : base()
|
||||
{
|
||||
ParentModel = model;
|
||||
Load(mesh);
|
||||
}
|
||||
|
||||
public List<DisplayVertex> CreateDisplayVertices()
|
||||
{
|
||||
display = lodMeshes[DisplayLODIndex].getDisplayFace().ToArray();
|
||||
|
||||
List<DisplayVertex> displayVertList = new List<DisplayVertex>();
|
||||
|
||||
if (faces.Count <= 3)
|
||||
return displayVertList;
|
||||
|
||||
foreach (Vertex v in vertices)
|
||||
{
|
||||
DisplayVertex displayVert = new DisplayVertex()
|
||||
{
|
||||
pos = v.pos,
|
||||
nrm = v.nrm,
|
||||
col = v.col.Xyz,
|
||||
};
|
||||
|
||||
displayVertList.Add(displayVert);
|
||||
}
|
||||
|
||||
return displayVertList;
|
||||
}
|
||||
|
||||
public struct DisplayVertex
|
||||
{
|
||||
// Used for rendering.
|
||||
public Vector3 pos;
|
||||
public Vector3 nrm;
|
||||
public Vector3 col;
|
||||
|
||||
public static int Size = 4 * (3 + 3 + 3);
|
||||
}
|
||||
|
||||
public override void OnClick(TreeView treeview)
|
||||
{
|
||||
BcresParent.LoadEditors(this, OnPropertyChanged);
|
||||
}
|
||||
|
||||
private void OnPropertyChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Load(Mesh mesh)
|
||||
{
|
||||
Mesh = mesh;
|
||||
|
||||
Text = mesh.Name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -388,6 +388,9 @@ namespace Bfres.Structs
|
|||
}
|
||||
public class BfresShaderParam
|
||||
{
|
||||
public ushort DependedIndex;
|
||||
public ushort DependIndex;
|
||||
|
||||
public ShaderParamType Type;
|
||||
public string Name { get; set; }
|
||||
|
||||
|
|
|
@ -881,6 +881,8 @@ namespace FirstPlugin
|
|||
BfresShaderParam shaderParam = new BfresShaderParam();
|
||||
shaderParam.Type = param.Type;
|
||||
shaderParam.Name = param.Name;
|
||||
shaderParam.DependedIndex = param.DependedIndex;
|
||||
shaderParam.DependIndex = param.DependIndex;
|
||||
|
||||
reader.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
|
||||
shaderParam.ReadValue(reader, (int)param.DataSize);
|
||||
|
@ -909,6 +911,8 @@ namespace FirstPlugin
|
|||
param.DataOffset = (ushort)Offset;
|
||||
param.DependedIndex = (ushort)index;
|
||||
param.DependIndex = (ushort)index;
|
||||
param.DependedIndex = shaderParam.DependedIndex;
|
||||
param.DependIndex = shaderParam.DependIndex;
|
||||
|
||||
writer.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
|
||||
shaderParam.WriteValue(writer);
|
||||
|
|
|
@ -681,6 +681,8 @@ namespace FirstPlugin
|
|||
shaderParam.Name = param.Name;
|
||||
shaderParam.HasPadding = param.UsePadding;
|
||||
shaderParam.PaddingLength = param.PaddingLength;
|
||||
shaderParam.DependedIndex = param.DependedIndex;
|
||||
shaderParam.DependIndex = param.DependIndex;
|
||||
|
||||
reader.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
|
||||
shaderParam.ReadValue(reader, (int)param.DataSize);
|
||||
|
@ -710,8 +712,8 @@ namespace FirstPlugin
|
|||
param.callbackPointer = 0;
|
||||
param.PaddingLength = shaderParam.PaddingLength;
|
||||
|
||||
param.DependedIndex = (ushort)index;
|
||||
param.DependIndex = (ushort)index;
|
||||
param.DependedIndex = shaderParam.DependedIndex;
|
||||
param.DependIndex = shaderParam.DependIndex;
|
||||
|
||||
writer.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
|
||||
shaderParam.WriteValue(writer);
|
||||
|
@ -751,7 +753,6 @@ namespace FirstPlugin
|
|||
int index = 0;
|
||||
foreach (MatTexture textu in m.TextureMaps)
|
||||
{
|
||||
|
||||
TextureRef texref = new TextureRef();
|
||||
texref.Name = textu.Name;
|
||||
|
||||
|
|
124
Switch_FileFormatsMain/GL/BCRES_Render.cs
Normal file
124
Switch_FileFormatsMain/GL/BCRES_Render.cs
Normal file
|
@ -0,0 +1,124 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GL_EditorFramework.GL_Core;
|
||||
using GL_EditorFramework.Interfaces;
|
||||
using Switch_Toolbox.Library.IO;
|
||||
using Switch_Toolbox.Library;
|
||||
using Switch_Toolbox.Library.Rendering;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using BcresLibrary;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class BCRES_Render : AbstractGlDrawable
|
||||
{
|
||||
public List<CMDLWrapper> Models = new List<CMDLWrapper>();
|
||||
|
||||
// gl buffer objects
|
||||
int vbo_position;
|
||||
int ibo_elements;
|
||||
|
||||
private void GenerateBuffers()
|
||||
{
|
||||
GL.GenBuffers(1, out vbo_position);
|
||||
GL.GenBuffers(1, out ibo_elements);
|
||||
|
||||
UpdateVertexData();
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
GL.DeleteBuffer(vbo_position);
|
||||
GL.DeleteBuffer(ibo_elements);
|
||||
}
|
||||
|
||||
public void UpdateVertexData()
|
||||
{
|
||||
if (!Runtime.OpenTKInitialized)
|
||||
return;
|
||||
|
||||
SOBJWrapper.DisplayVertex[] Vertices;
|
||||
int[] Faces;
|
||||
|
||||
int poffset = 0;
|
||||
int voffset = 0;
|
||||
List<SOBJWrapper.DisplayVertex> Vs = new List<SOBJWrapper.DisplayVertex>();
|
||||
List<int> Ds = new List<int>();
|
||||
foreach (CMDLWrapper m in Models)
|
||||
{
|
||||
foreach (SOBJWrapper shape in m.Shapes)
|
||||
{
|
||||
shape.Offset = poffset * 4;
|
||||
List<SOBJWrapper.DisplayVertex> pv = shape.CreateDisplayVertices();
|
||||
Vs.AddRange(pv);
|
||||
|
||||
for (int i = 0; i < shape.lodMeshes[shape.DisplayLODIndex].displayFaceSize; i++)
|
||||
{
|
||||
Ds.Add(shape.display[i] + voffset);
|
||||
}
|
||||
poffset += shape.lodMeshes[shape.DisplayLODIndex].displayFaceSize;
|
||||
voffset += pv.Count;
|
||||
}
|
||||
}
|
||||
|
||||
// Binds
|
||||
Vertices = Vs.ToArray();
|
||||
Faces = Ds.ToArray();
|
||||
|
||||
// Bind only once!
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
|
||||
GL.BufferData<SOBJWrapper.DisplayVertex>(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * SOBJWrapper.DisplayVertex.Size), Vertices, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements);
|
||||
GL.BufferData<int>(BufferTarget.ElementArrayBuffer, (IntPtr)(Faces.Length * sizeof(int)), Faces, BufferUsageHint.StaticDraw);
|
||||
|
||||
LibraryGUI.Instance.UpdateViewport();
|
||||
}
|
||||
|
||||
public ShaderProgram defaultShaderProgram;
|
||||
|
||||
public override void Prepare(GL_ControlModern control)
|
||||
{
|
||||
string pathFrag = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Bcres") + "\\BCRES.frag";
|
||||
string pathVert = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Bcres") + "\\BCRES.vert";
|
||||
|
||||
var defaultFrag = new FragmentShader(File.ReadAllText(pathFrag));
|
||||
var defaultVert = new VertexShader(File.ReadAllText(pathVert));
|
||||
|
||||
defaultShaderProgram = new ShaderProgram(defaultFrag, defaultVert);
|
||||
}
|
||||
|
||||
public override void Prepare(GL_ControlLegacy control)
|
||||
{
|
||||
string pathFrag = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Bcres") + "\\BCRES.frag";
|
||||
string pathVert = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Bcres") + "\\BCRES.vert";
|
||||
|
||||
var defaultFrag = new FragmentShader(File.ReadAllText(pathFrag));
|
||||
var defaultVert = new VertexShader(File.ReadAllText(pathVert));
|
||||
|
||||
defaultShaderProgram = new ShaderProgram(defaultFrag, defaultVert);
|
||||
}
|
||||
|
||||
public override void Draw(GL_ControlLegacy control, Pass pass)
|
||||
{
|
||||
if (!Runtime.OpenTKInitialized)
|
||||
return;
|
||||
}
|
||||
|
||||
public override void Draw(GL_ControlModern control, Pass pass)
|
||||
{
|
||||
if (!Runtime.OpenTKInitialized)
|
||||
return;
|
||||
|
||||
bool buffersWereInitialized = ibo_elements != 0 && vbo_position != 0;
|
||||
if (!buffersWereInitialized)
|
||||
GenerateBuffers();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -210,6 +210,7 @@
|
|||
<Compile Include="FileFormats\BCRES\Wrappers\BCRESGroupNode.cs" />
|
||||
<Compile Include="FileFormats\BCRES\Wrappers\CMDL\CMDLWrapper.cs" />
|
||||
<Compile Include="FileFormats\BCRES\Wrappers\CMDL\MTOBWrapper.cs" />
|
||||
<Compile Include="FileFormats\BCRES\Wrappers\CMDL\SOBJWrapper.cs" />
|
||||
<Compile Include="FileFormats\BCRES\Wrappers\TXOBWrapper.cs" />
|
||||
<Compile Include="FileFormats\BFRES\BFRESGroupNode.cs" />
|
||||
<Compile Include="FileFormats\BFRES\BFRESAnimFolder.cs" />
|
||||
|
@ -233,6 +234,7 @@
|
|||
<Compile Include="FileFormats\BFRES\BFRES.cs" />
|
||||
<Compile Include="FileFormats\Texture\NUT.cs" />
|
||||
<Compile Include="FileFormats\XLINK\XLINK.cs" />
|
||||
<Compile Include="GL\BCRES_Render.cs" />
|
||||
<Compile Include="GL\Helpers\DepthGLControl.cs" />
|
||||
<Compile Include="GL\ShaderData\AglShaderOdyssey.cs" />
|
||||
<Compile Include="GL\ShaderData\AglShaderTurbo.cs" />
|
||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
|||
928f89f7f6dfc0b9d93b0d3492830143335df5e0
|
||||
4d5e73277106e1aec8f32776e14883abfe56435f
|
||||
|
|
Binary file not shown.
|
@ -94,8 +94,6 @@ namespace Switch_Toolbox.Library
|
|||
int Increment = FmtBPP[(int)ConvertToPICAFormat(Format)] / 8;
|
||||
if (Increment == 0) Increment = 1;
|
||||
|
||||
// int Increment = (int)STGenericTexture.GetBytesPerPixel(Format);
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
75
Toolbox/Shader/Bcres/BCRES.frag
Normal file
75
Toolbox/Shader/Bcres/BCRES.frag
Normal file
|
@ -0,0 +1,75 @@
|
|||
#version 330
|
||||
in vec3 normal;
|
||||
in vec3 color;
|
||||
in vec3 position;
|
||||
|
||||
uniform vec3 difLightDirection;
|
||||
uniform vec3 difLightColor;
|
||||
uniform vec3 ambLightColor;
|
||||
|
||||
|
||||
uniform int colorOverride;
|
||||
uniform int renderType;
|
||||
uniform int renderVertColor;
|
||||
uniform mat4 modelview;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
//inspired by blender checker texture node
|
||||
float checker(vec3 p)
|
||||
{
|
||||
p.x = (p.x + 0.000001) * 0.999999;
|
||||
p.y = (p.y + 0.000001) * 0.999999;
|
||||
p.z = (p.z + 0.000001) * 0.999999;
|
||||
|
||||
int xi = int(round(abs(p.x)));
|
||||
int yi = int(round(abs(p.y)));
|
||||
int zi = int(round(abs(p.z)));
|
||||
|
||||
if (mod(yi,2)==0) {
|
||||
if(mod(xi,2) != mod(zi,2))
|
||||
return 1;
|
||||
else
|
||||
return 0.5;
|
||||
}
|
||||
else {
|
||||
if (mod(xi,2) == mod(zi,2))
|
||||
return 1;
|
||||
else
|
||||
return 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
if (colorOverride == 1)
|
||||
{
|
||||
// Wireframe color.
|
||||
|
||||
if (renderVertColor == 1)
|
||||
{
|
||||
FragColor = vec4(color, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
FragColor = vec4(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 displayNormal = (normal.xyz * 0.5) + 0.5;
|
||||
|
||||
if(renderType == 0){ //default
|
||||
float shading = max(displayNormal.y,0.5);
|
||||
FragColor = vec4(vec3(1,1,1)*shading*checker(position*0.015625), 1);
|
||||
}
|
||||
else if (renderType == 1) // normals color
|
||||
FragColor = vec4(displayNormal.rgb,1);
|
||||
else if (renderType == 2) // shading
|
||||
FragColor = vec4(vec3(1,1,1) * max(displayNormal.y,0.5), 1);
|
||||
else if (renderType == 3) // diffuse
|
||||
FragColor = vec4(vec3(1,1,1)*checker(position*0.015625), 1);
|
||||
else
|
||||
FragColor = vec4 (0,0,0,1);
|
||||
}
|
27
Toolbox/Shader/Bcres/BCRES.vert
Normal file
27
Toolbox/Shader/Bcres/BCRES.vert
Normal file
|
@ -0,0 +1,27 @@
|
|||
#version 330
|
||||
|
||||
const int MY_ARRAY_SIZE = 200;
|
||||
|
||||
in vec3 vPosition;
|
||||
in vec3 vNormal;
|
||||
in vec3 vColor;
|
||||
|
||||
out vec3 normal;
|
||||
out vec3 color;
|
||||
out vec3 position;
|
||||
|
||||
uniform mat4 mtxCam;
|
||||
uniform mat4 mtxMdl;
|
||||
uniform mat4 previewScale;
|
||||
|
||||
void main()
|
||||
{
|
||||
normal = vNormal;
|
||||
color = vColor;
|
||||
position = vPosition;
|
||||
|
||||
gl_Position = mtxCam * mtxMdl * vec4(vPosition.xyz, 1.0);
|
||||
|
||||
vec3 distance = (vPosition.xyz + vec3(5, 5, 5))/2;
|
||||
|
||||
}
|
|
@ -160,6 +160,12 @@
|
|||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<None Include="Shader\Bcres\BCRES.frag">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Shader\Bcres\BCRES.vert">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Shader\Bfres\BFRES.frag">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
Loading…
Reference in a new issue