mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-26 14:30:26 +00:00
Load bones the same way
This commit is contained in:
parent
bccb8f3af4
commit
0e72164823
10 changed files with 78 additions and 78 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -29,47 +29,9 @@ namespace Switch_Toolbox.Library
|
||||||
|
|
||||||
public bool IsHovered() => Selected;
|
public bool IsHovered() => Selected;
|
||||||
|
|
||||||
public ShaderProgram solidColorShaderProgram;
|
|
||||||
public override void Prepare(GL_ControlModern control)
|
public override void Prepare(GL_ControlModern control)
|
||||||
{
|
{
|
||||||
/* var solidColorFrag = new FragmentShader(
|
|
||||||
@"#version 330
|
|
||||||
uniform vec4 boneColor;
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
void main(){
|
|
||||||
FragColor = boneColor;
|
|
||||||
}");
|
|
||||||
var solidColorVert = new VertexShader(
|
|
||||||
@"#version 330
|
|
||||||
|
|
||||||
in vec4 point;
|
|
||||||
|
|
||||||
uniform mat4 mtxCam;
|
|
||||||
uniform mat4 mtxMdl;
|
|
||||||
|
|
||||||
uniform mat4 bone;
|
|
||||||
uniform mat4 parent;
|
|
||||||
uniform mat4 rotation;
|
|
||||||
uniform mat4 ModelMatrix;
|
|
||||||
uniform int hasParent;
|
|
||||||
uniform float scale;
|
|
||||||
|
|
||||||
void main(){
|
|
||||||
vec4 position = bone * rotation * vec4(point.xyz * scale, 1);
|
|
||||||
if (hasParent == 1)
|
|
||||||
{
|
|
||||||
if (point.w == 0)
|
|
||||||
position = parent * rotation * vec4(point.xyz * scale, 1);
|
|
||||||
else
|
|
||||||
position = bone * rotation * vec4((point.xyz - vec3(0, 1, 0)) * scale, 1);
|
|
||||||
}
|
|
||||||
gl_Position = mtxCam * ModelMatrix * mtxMdl * vec4(position.xyz, 1);
|
|
||||||
|
|
||||||
}");
|
|
||||||
|
|
||||||
solidColorShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert);*/
|
|
||||||
}
|
}
|
||||||
public override void Prepare(GL_ControlLegacy control)
|
public override void Prepare(GL_ControlLegacy control)
|
||||||
{
|
{
|
||||||
|
@ -212,7 +174,9 @@ namespace Switch_Toolbox.Library
|
||||||
if (!Runtime.OpenTKInitialized || !Runtime.renderBones)
|
if (!Runtime.OpenTKInitialized || !Runtime.renderBones)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GL.UseProgram(0);
|
SF.Shader shader = OpenTKSharedResources.shaders["BONE"];
|
||||||
|
shader.UseProgram();
|
||||||
|
|
||||||
GL.Disable(EnableCap.CullFace);
|
GL.Disable(EnableCap.CullFace);
|
||||||
|
|
||||||
if (Runtime.boneXrayDisplay)
|
if (Runtime.boneXrayDisplay)
|
||||||
|
@ -221,59 +185,65 @@ namespace Switch_Toolbox.Library
|
||||||
if (Runtime.renderBoundingBoxes)
|
if (Runtime.renderBoundingBoxes)
|
||||||
DrawBoundingBoxes();
|
DrawBoundingBoxes();
|
||||||
|
|
||||||
control.CurrentShader = solidColorShaderProgram;
|
|
||||||
|
|
||||||
control.UpdateModelMatrix(
|
control.UpdateModelMatrix(
|
||||||
Matrix4.CreateScale(Runtime.previewScale) *
|
Matrix4.CreateScale(Runtime.previewScale) *
|
||||||
Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(position) : position));
|
Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(position) : position));
|
||||||
|
|
||||||
|
|
||||||
solidColorShaderProgram.EnableVertexAttributes();
|
shader.EnableVertexAttributes();
|
||||||
solidColorShaderProgram.SetMatrix4x4("rotation", ref prismRotation);
|
shader.SetMatrix4x4("rotation", ref prismRotation);
|
||||||
|
|
||||||
|
Matrix4 camMat = control.CameraMatrix;
|
||||||
|
Matrix4 mdlMat = control.ModelMatrix;
|
||||||
|
Matrix4 projMat = control.ProjectionMatrix;
|
||||||
|
Matrix4 computedCamMtx = camMat * projMat;
|
||||||
|
|
||||||
|
shader.SetMatrix4x4("mtxCam", ref computedCamMtx);
|
||||||
|
shader.SetMatrix4x4("mtxMdl", ref mdlMat);
|
||||||
|
|
||||||
foreach (STBone bn in bones)
|
foreach (STBone bn in bones)
|
||||||
{
|
{
|
||||||
if (!bn.Checked)
|
if (!bn.Checked)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
solidColorShaderProgram.SetVector4("boneColor", ColorUtility.ToVector4(boneColor));
|
shader.SetVector4("boneColor", ColorUtility.ToVector4(boneColor));
|
||||||
solidColorShaderProgram.SetFloat("scale", Runtime.bonePointSize);
|
shader.SetFloat("scale", Runtime.bonePointSize);
|
||||||
solidColorShaderProgram.SetMatrix4x4("ModelMatrix", ref bn.ModelMatrix);
|
shader.SetMatrix4x4("ModelMatrix", ref bn.ModelMatrix);
|
||||||
|
|
||||||
|
|
||||||
Matrix4 transform = bn.Transform;
|
Matrix4 transform = bn.Transform;
|
||||||
|
|
||||||
solidColorShaderProgram.SetMatrix4x4("bone", ref transform);
|
shader.SetMatrix4x4("bone", ref transform);
|
||||||
solidColorShaderProgram.SetInt("hasParent", bn.parentIndex != -1 ? 1 : 0);
|
shader.SetInt("hasParent", bn.parentIndex != -1 ? 1 : 0);
|
||||||
|
|
||||||
if (bn.parentIndex != -1)
|
if (bn.parentIndex != -1)
|
||||||
{
|
{
|
||||||
var transformParent = ((STBone)bn.Parent).Transform;
|
var transformParent = ((STBone)bn.Parent).Transform;
|
||||||
solidColorShaderProgram.SetMatrix4x4("parent", ref transformParent);
|
shader.SetMatrix4x4("parent", ref transformParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw(solidColorShaderProgram);
|
Draw(shader);
|
||||||
|
|
||||||
if (Runtime.SelectedBoneIndex == bn.GetIndex())
|
if (Runtime.SelectedBoneIndex == bn.GetIndex())
|
||||||
solidColorShaderProgram.SetVector4("boneColor", ColorUtility.ToVector4(selectedBoneColor));
|
shader.SetVector4("boneColor", ColorUtility.ToVector4(selectedBoneColor));
|
||||||
|
|
||||||
solidColorShaderProgram.SetInt("hasParent", 0);
|
shader.SetInt("hasParent", 0);
|
||||||
Draw(solidColorShaderProgram);
|
Draw(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
solidColorShaderProgram.DisableVertexAttributes();
|
shader.DisableVertexAttributes();
|
||||||
|
|
||||||
GL.UseProgram(0);
|
GL.UseProgram(0);
|
||||||
GL.Enable(EnableCap.CullFace);
|
GL.Enable(EnableCap.CullFace);
|
||||||
GL.Enable(EnableCap.DepthTest);
|
GL.Enable(EnableCap.DepthTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Attributes(ShaderProgram shader)
|
private void Attributes(SF.Shader shader)
|
||||||
{
|
{
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
|
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
|
||||||
GL.VertexAttribPointer(shader.GetAttribute("point"), 4, VertexAttribPointerType.Float, false, 16, 0);
|
GL.VertexAttribPointer(shader.GetAttribLocation("point"), 4, VertexAttribPointerType.Float, false, 16, 0);
|
||||||
}
|
}
|
||||||
private void Draw(ShaderProgram shader)
|
private void Draw(SF.Shader shader)
|
||||||
{
|
{
|
||||||
Attributes(shader);
|
Attributes(shader);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,10 @@ namespace Switch_Toolbox.Library.Rendering
|
||||||
if (Switch_Toolbox.Library.Runtime.UseLegacyGL)
|
if (Switch_Toolbox.Library.Runtime.UseLegacyGL)
|
||||||
SetUpLegacyBfresShaders();
|
SetUpLegacyBfresShaders();
|
||||||
else
|
else
|
||||||
|
{
|
||||||
SetUpBfresShaders();
|
SetUpBfresShaders();
|
||||||
|
SetUBoneShaders();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private static void SetUpLegacyBfresShaders()
|
private static void SetUpLegacyBfresShaders()
|
||||||
{
|
{
|
||||||
|
@ -45,6 +48,18 @@ namespace Switch_Toolbox.Library.Rendering
|
||||||
CreateAndAddShader("BFRES_Debug", bfresSharedShaders.ToArray());
|
CreateAndAddShader("BFRES_Debug", bfresSharedShaders.ToArray());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SetUBoneShaders()
|
||||||
|
{
|
||||||
|
List<string> boneSharedShaders = new List<string>
|
||||||
|
{
|
||||||
|
"Bone.vert",
|
||||||
|
"Bone.frag",
|
||||||
|
};
|
||||||
|
|
||||||
|
CreateAndAddShader("BONE", boneSharedShaders.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
private static void SetUpBfresShaders()
|
private static void SetUpBfresShaders()
|
||||||
{
|
{
|
||||||
List<string> bfresSharedShaders = new List<string>
|
List<string> bfresSharedShaders = new List<string>
|
||||||
|
|
|
@ -1,25 +1,8 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
uniform vec4 boneColor;
|
||||||
|
|
||||||
in vec4 point;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform mat4 mtxCam;
|
|
||||||
uniform mat4 mtxMdl;
|
|
||||||
|
|
||||||
uniform mat4 bone;
|
|
||||||
uniform mat4 parent;
|
|
||||||
uniform mat4 rotation;
|
|
||||||
uniform mat4 ModelMatrix;
|
|
||||||
uniform int hasParent;
|
|
||||||
uniform float scale;
|
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
vec4 position = bone * rotation * vec4(point.xyz * scale, 1);
|
FragColor = boneColor;
|
||||||
if (hasParent == 1)
|
|
||||||
{
|
|
||||||
if (point.w == 0)
|
|
||||||
position = parent * rotation * vec4(point.xyz * scale, 1);
|
|
||||||
else
|
|
||||||
position = bone * rotation * vec4((point.xyz - vec3(0, 1, 0)) * scale, 1);
|
|
||||||
}
|
|
||||||
gl_Position = mtxCam * ModelMatrix * mtxMdl * vec4(position.xyz, 1);
|
|
||||||
}
|
}
|
26
Toolbox/Shader/Bone.vert
Normal file
26
Toolbox/Shader/Bone.vert
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
in vec4 point;
|
||||||
|
|
||||||
|
uniform mat4 mtxCam;
|
||||||
|
uniform mat4 mtxMdl;
|
||||||
|
|
||||||
|
uniform mat4 bone;
|
||||||
|
uniform mat4 parent;
|
||||||
|
uniform mat4 rotation;
|
||||||
|
uniform mat4 ModelMatrix;
|
||||||
|
uniform int hasParent;
|
||||||
|
uniform float scale;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 position = bone * rotation * vec4(point.xyz * scale, 1);
|
||||||
|
if (hasParent == 1)
|
||||||
|
{
|
||||||
|
if (point.w == 0)
|
||||||
|
position = parent * rotation * vec4(point.xyz * scale, 1);
|
||||||
|
else
|
||||||
|
position = bone * rotation * vec4((point.xyz - vec3(0, 1, 0)) * scale, 1);
|
||||||
|
}
|
||||||
|
gl_Position = mtxCam * ModelMatrix * mtxMdl * vec4(position.xyz, 1);
|
||||||
|
}
|
|
@ -196,6 +196,12 @@
|
||||||
<None Include="Shader\Bfres\Normals.vert">
|
<None Include="Shader\Bfres\Normals.vert">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="Shader\Bone.frag">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Shader\Bone.vert">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Include="Shader\HDRSkyBox\HDRSkyBox.frag">
|
<None Include="Shader\HDRSkyBox\HDRSkyBox.frag">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|
Loading…
Reference in a new issue