Optmize model/shader loading for bfres. Save block setting to 1MB for KSA to not crash

This commit is contained in:
KillzXGaming 2019-05-20 16:01:43 -04:00
parent 2cd53cb76d
commit bccb8f3af4
22 changed files with 492 additions and 178 deletions

Binary file not shown.

View file

@ -15,8 +15,7 @@ using Switch_Toolbox.Library.IO;
using Switch_Toolbox.Library.Forms;
using ResU = Syroot.NintenTools.Bfres;
using Bfres.Structs;
using GL_EditorFramework.EditorDrawables;
using static GL_EditorFramework.EditorDrawables.EditorSceneBase;
using SF = SFGraphics.GLObjects.Shaders;
namespace FirstPlugin
{
@ -32,7 +31,6 @@ namespace FirstPlugin
public bool Hovered = false;
public bool IsSelected() => Selected;
// public override bool IsSelected(int partIndex) => Selected;
// gl buffer objects
int vbo_position;
@ -98,16 +96,16 @@ namespace FirstPlugin
#region Rendering
public ShaderProgram BotwShaderProgram;
public ShaderProgram normalsShaderProgram;
public ShaderProgram debugShaderProgram;
public ShaderProgram pbrShaderProgram;
public ShaderProgram defaultShaderProgram;
public ShaderProgram solidColorShaderProgram;
// public ShaderProgram BotwShaderProgram;
// public ShaderProgram normalsShaderProgram;
// public ShaderProgram debugShaderProgram;
// public ShaderProgram pbrShaderProgram;
// public ShaderProgram defaultShaderProgram;
// public ShaderProgram solidColorShaderProgram;
public override void Prepare(GL_ControlModern control)
{
string pathFrag = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Bfres") + "\\BFRES.frag";
/* string pathFrag = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Bfres") + "\\BFRES.frag";
string pathVert = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Bfres") + "\\BFRES.vert";
@ -180,7 +178,7 @@ namespace FirstPlugin
normalsShaderProgram = new ShaderProgram(new Shader[] { normalsFrag, normalsVert, normalsGeom });
debugShaderProgram = new ShaderProgram(new Shader[] { bfresUtiltyFrag, utiltyFrag, debugFrag, defaultVert, utiltyFrag, shadowMapAGL });
pbrShaderProgram = new ShaderProgram(new Shader[] { bfresUtiltyFrag, utiltyFrag, PbrFrag, defaultVert, shadowMapAGL });
solidColorShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert);
solidColorShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert);*/
}
public override void Prepare(GL_ControlLegacy control)
@ -188,35 +186,6 @@ namespace FirstPlugin
}
/* private void DrawBoundingBoxes()
{
var boundings = GetSelectionBox();
DrawableBoundingBox.DrawBoundingBox(
new Vector3(boundings.minX, boundings.minY, boundings.minZ),
new Vector3(boundings.maxX, boundings.maxY, boundings.maxZ),
new Vector3(0)
);
return;
foreach (FMDL mdl in models)
{
foreach (FSHP m in mdl.shapes)
{
if (m.IsSelected)
GL.Color4(Color.GhostWhite);
else
GL.Color4(Color.OrangeRed);
foreach (FSHP.BoundingBox box in m.boundingBoxes)
{
RenderTools.DrawRectangularPrism(box.Center, box.Extend.X, box.Extend.Y, box.Extend.Z, true);
}
}
}
}*/
public override void Draw(GL_ControlLegacy control, Pass pass)
{
bool buffersWereInitialized = ibo_elements != 0 && vbo_position != 0;
@ -324,10 +293,12 @@ namespace FirstPlugin
if (Hovered == true)
throw new Exception("model selected");
ShaderProgram shader = defaultShaderProgram;
//Temporarily revert to using this shader system as it is easy to port back
//This is much quicker. Will change after shaders are handled faster
SF.Shader shader = OpenTKSharedResources.shaders["BFRES"];
if (Runtime.EnablePBR)
shader = pbrShaderProgram;
shader = OpenTKSharedResources.shaders["BFRES_PBR"];
if (models.Count > 0)
{
@ -338,7 +309,7 @@ namespace FirstPlugin
{
if (models[0].shapes[0].GetMaterial().shaderassign.ShaderModel == "uking_mat")
{
shader = BotwShaderProgram;
shader = OpenTKSharedResources.shaders["BFRES_Botw"];
//Botw uses small models so lower the bone size
Runtime.bonePointSize = 0.040f;
@ -347,16 +318,21 @@ namespace FirstPlugin
}
if (Runtime.viewportShading != Runtime.ViewportShading.Default)
shader = debugShaderProgram;
shader = OpenTKSharedResources.shaders["BFRES_Debug"];
if (Runtime.viewportShading == Runtime.ViewportShading.Lighting && Runtime.EnablePBR)
shader = OpenTKSharedResources.shaders["BFRES_PBR"];
control.CurrentShader = shader;
shader.UseProgram();
control.UpdateModelMatrix(Matrix4.CreateScale(Runtime.previewScale) * ModelTransform);
Matrix4 camMat = control.ModelMatrix * control.CameraMatrix * control.ProjectionMatrix;
Matrix4 camMat = control.CameraMatrix;
Matrix4 mdlMat = control.ModelMatrix;
Matrix4 projMat = control.ProjectionMatrix;
Matrix4 computedCamMtx = camMat * projMat;
Matrix4 mvpMat = control.ModelMatrix * control.CameraMatrix * control.ProjectionMatrix;
Matrix4 sphereMatrix = camMat;
Matrix4 sphereMatrix = mvpMat;
if (sphereMatrix.Determinant != 0)
sphereMatrix.Invert();
@ -364,6 +340,9 @@ namespace FirstPlugin
sphereMatrix.Transpose();
shader.SetMatrix4x4("sphereMatrix", ref sphereMatrix);
shader.SetMatrix4x4("mtxCam", ref computedCamMtx);
shader.SetMatrix4x4("mtxMdl", ref mdlMat);
SetRenderSettings(shader);
Vector4 pickingColor = control.NextPickingColor();
@ -373,7 +352,7 @@ namespace FirstPlugin
Matrix4 invertedCamera = Matrix4.Identity;
if (invertedCamera.Determinant != 0)
invertedCamera = camMat.Inverted();
invertedCamera = mvpMat.Inverted();
Vector3 lightDirection = new Vector3(0f, 0f, -1f);
@ -389,17 +368,17 @@ namespace FirstPlugin
if (Runtime.renderNormalsPoints)
{
control.CurrentShader = normalsShaderProgram;
shader = OpenTKSharedResources.shaders["BFRES_Normals"];
shader.UseProgram();
Matrix4 projection = control.ProjectionMatrix;
Matrix4 camMtx = control.CameraMatrix;
normalsShaderProgram.SetMatrix4x4("mtxProj", ref projection);
normalsShaderProgram.SetMatrix4x4("camMtx", ref camMtx);
shader.SetMatrix4x4("mtxProj", ref projection);
shader.SetMatrix4x4("camMtx", ref camMtx);
shader.SetFloat("normalsLength", Runtime.normalsLineLength);
normalsShaderProgram.SetFloat("normalsLength", Runtime.normalsLineLength);
DrawModels(normalsShaderProgram, control);
DrawModels(shader, control);
}
GL.UseProgram(0);
@ -408,7 +387,7 @@ namespace FirstPlugin
GL.Enable(EnableCap.CullFace);
}
private void DrawModels(ShaderProgram shader, GL_ControlModern control)
private void DrawModels(SF.Shader shader, GL_ControlModern control)
{
shader.EnableVertexAttributes();
foreach (FMDL mdl in models)
@ -456,7 +435,7 @@ namespace FirstPlugin
// Positive values are usually closer to camera. Negative values are usually farther away.
}
private void SetRenderSettings(ShaderProgram shader)
private void SetRenderSettings(SF.Shader shader)
{
shader.SetBoolToInt("renderVertColor", Runtime.renderVertColor);
shader.SetBoolToInt("useNormalMap", Runtime.useNormalMap);
@ -474,7 +453,7 @@ namespace FirstPlugin
shader.SetBoolToInt("renderSpecular", Runtime.renderSpecular);
shader.SetBoolToInt("renderFresnel", Runtime.renderFresnel);
}
private static void SetDefaultTextureAttributes(FMAT mat, ShaderProgram shader)
private static void SetDefaultTextureAttributes(FMAT mat, SF.Shader shader)
{
shader.SetBoolToInt("HasDiffuse", mat.HasDiffuseMap);
shader.SetBoolToInt("HasDiffuseLayer", mat.HasDiffuseLayer);
@ -492,18 +471,18 @@ namespace FirstPlugin
shader.SetBoolToInt("HasRoughnessMap", mat.HasRoughnessMap);
shader.SetBoolToInt("HasMRA", mat.HasMRA);
}
private static void SetBoneUniforms(ShaderProgram shader, FMDL fmdl, FSHP fshp)
private static void SetBoneUniforms(SF.Shader shader, FMDL fmdl, FSHP fshp)
{
for (int i = 0; i < fmdl.Skeleton.Node_Array.Length; i++)
{
GL.Uniform1(GL.GetUniformLocation(shader.program, String.Format("boneIds[{0}]", i)), fmdl.Skeleton.Node_Array[i]);
GL.Uniform1(GL.GetUniformLocation(shader.Id, String.Format("boneIds[{0}]", i)), fmdl.Skeleton.Node_Array[i]);
Matrix4 transform = fmdl.Skeleton.bones[fmdl.Skeleton.Node_Array[i]].invert * fmdl.Skeleton.bones[fmdl.Skeleton.Node_Array[i]].Transform;
GL.UniformMatrix4(GL.GetUniformLocation(shader.program, String.Format("bones[{0}]", i)), false, ref transform);
GL.UniformMatrix4(GL.GetUniformLocation(shader.Id, String.Format("bones[{0}]", i)), false, ref transform);
}
}
private static void SetTextureUniforms(FMAT mat, FSHP m, ShaderProgram shader)
private static void SetTextureUniforms(FMAT mat, FSHP m, SF.Shader shader)
{
SetDefaultTextureAttributes(mat, shader);
@ -511,22 +490,22 @@ namespace FirstPlugin
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);
GL.ActiveTexture(TextureUnit.Texture11);
GL.Uniform1(shader["weightRamp1"], 11);
GL.Uniform1(shader.GetUniformLocation("weightRamp1"), 11);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient.Id);
GL.ActiveTexture(TextureUnit.Texture12);
GL.Uniform1(shader["weightRamp2"], 12);
GL.Uniform1(shader.GetUniformLocation("weightRamp2"), 12);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient2.Id);
GL.Uniform1(shader["debugOption"], 2);
GL.Uniform1(shader.GetUniformLocation("debugOption"), 2);
GL.ActiveTexture(TextureUnit.Texture10);
GL.Uniform1(shader["UVTestPattern"], 10);
GL.Uniform1(shader.GetUniformLocation("UVTestPattern"), 10);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID);
GL.Uniform1(shader["normalMap"], 0);
GL.Uniform1(shader["BakeShadowMap"], 0);
GL.Uniform1(shader.GetUniformLocation("normalMap"), 0);
GL.Uniform1(shader.GetUniformLocation("BakeShadowMap"), 0);
LoadPBRMaps(shader);
@ -563,25 +542,25 @@ namespace FirstPlugin
}
}
private static void LoadPBRMaps(ShaderProgram shader)
private static void LoadPBRMaps(SF.Shader shader)
{
GL.ActiveTexture(TextureUnit.Texture0 + 26);
RenderTools.specularPbr.Bind();
GL.Uniform1(shader["specularIbl"], 26);
GL.Uniform1(shader.GetUniformLocation("specularIbl"), 26);
// GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);
// PBR IBL
GL.ActiveTexture(TextureUnit.Texture0 + 25);
RenderTools.diffusePbr.Bind();
GL.Uniform1(shader["irradianceMap"], 25);
GL.Uniform1(shader.GetUniformLocation("irradianceMap"), 25);
GL.ActiveTexture(TextureUnit.Texture0 + 27);
RenderTools.brdfPbr.Bind();
GL.Uniform1(shader["brdfLUT"], 27);
GL.Uniform1(shader.GetUniformLocation("brdfLUT"), 27);
}
private static void TextureUniform(ShaderProgram shader, FMAT mat, bool hasTex, string name, MatTexture mattex)
private static void TextureUniform(SF.Shader shader, FMAT mat, bool hasTex, string name, MatTexture mattex)
{
if (mattex.textureState == STGenericMatTexture.TextureState.Binded)
return;
@ -589,20 +568,14 @@ namespace FirstPlugin
// Bind the texture and create the uniform if the material has the right textures.
if (hasTex)
{
GL.Uniform1(shader[name], BindTexture(shader, mattex, mat.GetResFileU() != null));
GL.Uniform1(shader.GetUniformLocation(name), BindTexture(shader, mattex, mat.GetResFileU() != null));
}
}
public static int BindTexture(ShaderProgram shader, MatTexture tex, bool IsWiiU)
public static int BindTexture(SF.Shader shader, MatTexture tex, bool IsWiiU)
{
GL.ActiveTexture(TextureUnit.Texture0 + tex.textureUnit + 1);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);
GL.Uniform1(shader["RedChannel"], 0);
GL.Uniform1(shader["GreenChannel"], 1);
GL.Uniform1(shader["BlueChannel"], 2);
GL.Uniform1(shader["AlphaChannel"], 3);
string activeTex = tex.Name;
if (tex.animatedTexName != "")
activeTex = tex.animatedTexName;
@ -619,9 +592,6 @@ namespace FirstPlugin
if (ftex.RenderableTex == null || !ftex.RenderableTex.GLInitialized)
ftex.LoadOpenGLTexture();
if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
SetTextureComponents(shader, ftex);
BindGLTexture(tex, ftex.RenderableTex.TexID);
}
}
@ -638,9 +608,6 @@ namespace FirstPlugin
bntx.Textures[activeTex].LoadOpenGLTexture();
}
if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
SetTextureComponents(shader, bntx.Textures[activeTex]);
BindGLTexture(tex, bntx.Textures[activeTex].RenderableTex.TexID);
}
}
@ -648,14 +615,6 @@ namespace FirstPlugin
return tex.textureUnit + 1;
}
private static void SetTextureComponents(ShaderProgram shader, STGenericTexture Texture)
{
GL.Uniform1(shader["RedChannel"], (int)Texture.RedChannel);
GL.Uniform1(shader["GreenChannel"], (int)Texture.GreenChannel);
GL.Uniform1(shader["BlueChannel"], (int)Texture.BlueChannel);
GL.Uniform1(shader["AlphaChannel"], (int)Texture.AlphaChannel);
}
private static void BindGLTexture(MatTexture tex, int texid)
{
// GL.ActiveTexture(TextureUnit.Texture0 + texid);
@ -666,14 +625,14 @@ namespace FirstPlugin
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)MatTexture.magfilter[tex.magFilter]);
GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, 0.0f);
}
private void DrawModel(FSHP m, FMDL mdl, ShaderProgram shader, bool drawSelection)
private void DrawModel(FSHP m, FMDL mdl, SF.Shader shader, bool drawSelection)
{
if (m.lodMeshes[m.DisplayLODIndex].faces.Count <= 3)
return;
var mat = m.GetMaterial();
if (shader != normalsShaderProgram)
if (shader != OpenTKSharedResources.shaders["BFRES_Normals"])
{
SetRenderPass(mat, shader, m, m.DisplayId);
SetUniforms(mat, shader, m, m.DisplayId);
@ -732,7 +691,7 @@ namespace FirstPlugin
}
}
}
private static void ApplyTransformFix(FMDL fmdl, FSHP m, ShaderProgram shader)
private static void ApplyTransformFix(FMDL fmdl, FSHP m, SF.Shader shader)
{
Matrix4 idenity = Matrix4.Identity;
shader.SetInt("NoSkinning", 0);
@ -879,7 +838,7 @@ namespace FirstPlugin
LibraryGUI.Instance.UpdateViewport();
}
private static void SetRenderPass(FMAT mat, ShaderProgram shader, FSHP m, int id)
private static void SetRenderPass(FMAT mat, SF.Shader shader, FSHP m, int id)
{
if (mat.shaderassign.ShaderArchive == "Turbo_UBER")
{
@ -888,15 +847,17 @@ namespace FirstPlugin
foreach (var renderInfo in mat.renderinfo)
aglShader.LoadRenderInfo(renderInfo);
aglShader.LoadRenderPass(mat, shader);
// aglShader.LoadRenderPass(mat, shader);
}
}
private static void SetUniforms(FMAT mat, ShaderProgram shader, FSHP m, int id)
private static void SetUniforms(FMAT mat, SF.Shader shader, FSHP m, int id)
{
shader.SetBoolToInt("isTransparent", mat.isTransparent);
shader.SetFloat("ao_density", 1);
shader.SetFloat("shadow_density", 1);
shader.SetFloat("normal_map_weight", 1);
//Bake map UV coordinate ST
@ -934,6 +895,7 @@ namespace FirstPlugin
SetUniformData(mat, shader, "gsys_bake_st1");
SetUniformData(mat, shader, "ao_density");
SetUniformData(mat, shader, "shadow_density");
SetUniformData(mat, shader, "normal_map_weight");
SetUniformData(mat, shader, "const_color0");
@ -963,7 +925,7 @@ namespace FirstPlugin
SetUniformData(mat, shader, "bake_calc_type");
}
private static void SetUniformData(FMAT mat, ShaderProgram shader, string propertyName)
private static void SetUniformData(FMAT mat, SF.Shader shader, string propertyName)
{
if (mat.shaderassign.options.ContainsKey(propertyName))
{
@ -1084,36 +1046,36 @@ namespace FirstPlugin
}
}
}
private void SetVertexAttributes(FSHP m, ShaderProgram shader)
private void SetVertexAttributes(FSHP m, SF.Shader shader)
{
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
GL.VertexAttribPointer(shader.GetAttribute("vPosition"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 0);
GL.VertexAttribPointer(shader.GetAttribute("vNormal"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 12);
GL.VertexAttribPointer(shader.GetAttribute("vTangent"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 24);
GL.VertexAttribPointer(shader.GetAttribute("vBitangent"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 36);
GL.VertexAttribPointer(shader.GetAttribute("vUV0"), 2, VertexAttribPointerType.Float, false, DisplayVertex.Size, 48);
GL.VertexAttribPointer(shader.GetAttribute("vColor"), 4, VertexAttribPointerType.Float, false, DisplayVertex.Size, 56);
GL.VertexAttribIPointer(shader.GetAttribute("vBone"), 4, VertexAttribIntegerType.Int, DisplayVertex.Size, new IntPtr(72));
GL.VertexAttribPointer(shader.GetAttribute("vWeight"), 4, VertexAttribPointerType.Float, false, DisplayVertex.Size, 88);
GL.VertexAttribPointer(shader.GetAttribute("vUV1"), 2, VertexAttribPointerType.Float, false, DisplayVertex.Size, 104);
GL.VertexAttribPointer(shader.GetAttribute("vUV2"), 2, VertexAttribPointerType.Float, false, DisplayVertex.Size, 112);
GL.VertexAttribPointer(shader.GetAttribute("vPosition2"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 124);
GL.VertexAttribPointer(shader.GetAttribute("vPosition3"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 136);
GL.VertexAttribPointer(shader.GetAttribLocation("vPosition"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 0);
GL.VertexAttribPointer(shader.GetAttribLocation("vNormal"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 12);
GL.VertexAttribPointer(shader.GetAttribLocation("vTangent"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 24);
GL.VertexAttribPointer(shader.GetAttribLocation("vBitangent"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 36);
GL.VertexAttribPointer(shader.GetAttribLocation("vUV0"), 2, VertexAttribPointerType.Float, false, DisplayVertex.Size, 48);
GL.VertexAttribPointer(shader.GetAttribLocation("vColor"), 4, VertexAttribPointerType.Float, false, DisplayVertex.Size, 56);
GL.VertexAttribIPointer(shader.GetAttribLocation("vBone"), 4, VertexAttribIntegerType.Int, DisplayVertex.Size, new IntPtr(72));
GL.VertexAttribPointer(shader.GetAttribLocation("vWeight"), 4, VertexAttribPointerType.Float, false, DisplayVertex.Size, 88);
GL.VertexAttribPointer(shader.GetAttribLocation("vUV1"), 2, VertexAttribPointerType.Float, false, DisplayVertex.Size, 104);
GL.VertexAttribPointer(shader.GetAttribLocation("vUV2"), 2, VertexAttribPointerType.Float, false, DisplayVertex.Size, 112);
GL.VertexAttribPointer(shader.GetAttribLocation("vPosition2"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 124);
GL.VertexAttribPointer(shader.GetAttribLocation("vPosition3"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 136);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements);
}
private static void DrawMdoelHoverSelection(STGenericObject p, ShaderProgram shader,
private static void DrawMdoelHoverSelection(STGenericObject p, SF.Shader shader,
bool IsSelected, bool IsHovered)
{
if (IsHovered && IsSelected)
GL.Uniform4(shader["pickingColor"], hoverColor);
shader.SetVector4("pickingColor", hoverColor);
else if (IsHovered || IsSelected)
GL.Uniform4(shader["pickingColor"], selectColor);
shader.SetVector4("pickingColor", selectColor);
else
GL.Uniform4(shader["pickingColor"], new Vector4(1));
shader.SetVector4("pickingColor", new Vector4(1));
}
private static void DrawModelWireframe(STGenericObject p, ShaderProgram shader)
private static void DrawModelWireframe(STGenericObject p, SF.Shader shader)
{
// use vertex color for wireframe color
shader.SetInt("colorOverride", 1);
@ -1124,7 +1086,7 @@ namespace FirstPlugin
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
shader.SetInt("colorOverride", 0);
}
private static void DrawModelSelection(STGenericObject p, ShaderProgram shader)
private static void DrawModelSelection(STGenericObject p, SF.Shader shader)
{
//This part needs to be reworked for proper outline. Currently would make model disappear
/* GL.Enable(EnableCap.DepthTest);
@ -1156,13 +1118,13 @@ namespace FirstPlugin
// Override the model color with white in the shader.
GL.Uniform1(shader["colorOverride"], 1);
shader.SetInt("colorOverride", 1);
GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
GL.Enable(EnableCap.LineSmooth);
GL.LineWidth(1.3f);
GL.DrawElements(PrimitiveType.Triangles, p.lodMeshes[p.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
GL.Uniform1(shader["colorOverride"], 0);
shader.SetInt("colorOverride", 0);
GL.DrawElements(PrimitiveType.Triangles, p.lodMeshes[p.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
}

View file

@ -185,6 +185,7 @@ namespace FirstPlugin
SetBoneTransform(activeBone);
activeBone.skeletonParent.reset();
activeBone.skeletonParent.update(true);
LibraryGUI.Instance.UpdateViewport();
}

View file

@ -11,6 +11,7 @@ using GL_EditorFramework.GL_Core;
using GL_EditorFramework.Interfaces;
using GL_EditorFramework.EditorDrawables;
using Switch_Toolbox.Library.Rendering;
using SF = SFGraphics.GLObjects.Shaders;
using static GL_EditorFramework.EditorDrawables.EditorSceneBase;
@ -31,7 +32,7 @@ namespace Switch_Toolbox.Library
public ShaderProgram solidColorShaderProgram;
public override void Prepare(GL_ControlModern control)
{
var solidColorFrag = new FragmentShader(
/* var solidColorFrag = new FragmentShader(
@"#version 330
uniform vec4 boneColor;
@ -68,7 +69,7 @@ namespace Switch_Toolbox.Library
}");
solidColorShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert);
solidColorShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert);*/
}
public override void Prepare(GL_ControlLegacy control)
{

View file

@ -230,7 +230,9 @@ namespace Switch_Toolbox.Library.IO
using (var writer = new FileWriter(stream))
{
writer.Write(data.Length);
byte[] buffer = LZ4.Frame.LZ4Frame.Compress(new MemoryStream(data), LZ4.Frame.LZ4MaxBlockSize.Auto, true, true, false, true, false);
byte[] buffer = LZ4.Frame.LZ4Frame.Compress(new MemoryStream(data),
LZ4.Frame.LZ4MaxBlockSize.MB1, true, true, false, true, false);
writer.Write(buffer, 0, buffer.Length);
}
return stream.ToArray();

View file

@ -0,0 +1,107 @@
using System;
using System.Runtime.ExceptionServices;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using SFGraphics.GLObjects.Shaders;
namespace Switch_Toolbox.Library.Rendering
{
public static class OpenTKSharedResources
{
public enum SharedResourceStatus
{
Initialized,
Failed,
Unitialized
}
public static SharedResourceStatus SetupStatus
{
get { return setupStatus; }
}
private static SharedResourceStatus setupStatus = SharedResourceStatus.Unitialized;
// Keep a context around to avoid setting up after making each context.
public static GameWindow dummyResourceWindow;
public static Dictionary<string, Shader> shaders = new Dictionary<string, Shader>();
private static DebugProc debugProc;
[HandleProcessCorruptedStateExceptions]
public static void InitializeSharedResources()
{
// Only setup once. This is checked multiple times to prevent crashes.
if (setupStatus == SharedResourceStatus.Initialized)
return;
try
{
// Make a permanent context to share resources.
GraphicsContext.ShareContexts = true;
dummyResourceWindow = CreateGameWindowContext();
if (Runtime.enableOpenTKDebugOutput)
EnableOpenTKDebugOutput();
RenderTools.LoadTextures();
GetOpenGLSystemInfo();
ShaderTools.SetUpShaders();
setupStatus = SharedResourceStatus.Initialized;
}
catch (AccessViolationException)
{
// Context creation failed.
setupStatus = SharedResourceStatus.Failed;
}
}
public static void EnableOpenTKDebugOutput()
{
#if DEBUG
// This isn't free, so skip this step when not debugging.
// TODO: Only works with Intel integrated.
if (SFGraphics.Tools.OpenGLExtensions.IsAvailable("GL_KHR_debug"))
{
GL.Enable(EnableCap.DebugOutput);
GL.Enable(EnableCap.DebugOutputSynchronous);
debugProc = DebugCallback;
GL.DebugMessageCallback(debugProc, IntPtr.Zero);
int[] ids = { };
GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare,
DebugSeverityControl.DontCare, 0, ids, true);
}
#endif
}
private static void DebugCallback(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam)
{
string debugMessage = Marshal.PtrToStringAnsi(message, length);
Debug.WriteLine(String.Format("{0} {1} {2}", severity, type, debugMessage));
}
public static GameWindow CreateGameWindowContext(int width = 640, int height = 480)
{
GraphicsMode mode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 0, 0, ColorFormat.Empty, 1);
// TODO: Versions higher than 300 do not work for some reason.
GameWindow gameWindow = new GameWindow(width, height, mode, "", OpenTK.GameWindowFlags.Default, OpenTK.DisplayDevice.Default, 3, 0, GraphicsContextFlags.Default);
gameWindow.Visible = false;
gameWindow.MakeCurrent();
return gameWindow;
}
private static void GetOpenGLSystemInfo()
{
Runtime.renderer = GL.GetString(StringName.Renderer);
Runtime.openGLVersion = GL.GetString(StringName.Version);
Runtime.GLSLVersion = GL.GetString(StringName.ShadingLanguageVersion);
}
}
}

View file

@ -190,6 +190,11 @@ namespace Switch_Toolbox.Library
}
}
public static void LoadTextures()
{
}
public static void DisposeTextures()
{
defaultTex = null;

View file

@ -0,0 +1,182 @@
using OpenTK.Graphics.OpenGL;
using SFGraphics.GLObjects.Shaders;
using SFGraphics.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace Switch_Toolbox.Library.Rendering
{
public static class ShaderTools
{
public static string shaderSourceDirectory;
public static string executableDir;
public static void SetUpShaders(bool forceBinaryUpdate = false)
{
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
shaderSourceDirectory = Path.Combine(executableDir, "Shader");
// Reset the shaders first so that shaders can be replaced.
OpenTKSharedResources.shaders.Clear();
SetUpAllShaders();
System.Diagnostics.Debug.WriteLine("Shader Setup: {0} ms", stopwatch.ElapsedMilliseconds);
}
private static void SetUpAllShaders()
{
if (Switch_Toolbox.Library.Runtime.UseLegacyGL)
SetUpLegacyBfresShaders();
else
SetUpBfresShaders();
}
private static void SetUpLegacyBfresShaders()
{
List<string> bfresSharedShaders = new List<string>
{
"Bfres\\Legacy\\BFRES.vert",
"Bfres\\Legacy\\BFRES.frag",
};
CreateAndAddShader("BFRES", bfresSharedShaders.ToArray());
CreateAndAddShader("BFRES_Debug", bfresSharedShaders.ToArray());
}
private static void SetUpBfresShaders()
{
List<string> bfresSharedShaders = new List<string>
{
"Bfres\\BFRES.vert",
"Bfres\\BFRES_utility.frag",
"Utility\\Utility.frag"
};
List<string> NormalsSharedShaders = new List<string>
{
"Bfres\\Normals.frag",
"Bfres\\Normals.vert",
"Bfres\\Normals.geom",
};
List<string> HDRShaders = new List<string>
{
"HDRSkyBox\\HDRSkyBox.vert",
"HDRSkyBox\\HDRSkyBox.frag",
};
List<string> bfresDebugShaders = new List<string>(bfresSharedShaders);
bfresDebugShaders.Add("Bfres\\BFRES_Debug.frag");
bfresDebugShaders.Add("Bfres\\BFRESTurboShadow.frag");
List<string> bfresShaders = new List<string>(bfresSharedShaders);
bfresShaders.Add("Bfres\\BFRES.frag");
bfresShaders.Add("Bfres\\BFRESTurboShadow.frag");
List<string> bfresPBRShaders = new List<string>(bfresSharedShaders);
bfresPBRShaders.Add("Bfres\\BFRES_PBR.frag");
bfresPBRShaders.Add("Bfres\\BFRESTurboShadow.frag");
List<string> bfresBotwShaders = new List<string>(bfresSharedShaders);
bfresBotwShaders.Add("Bfres\\BFRES_Botw.frag");
CreateAndAddShader("BFRES", bfresShaders.ToArray());
CreateAndAddShader("BFRES_PBR", bfresPBRShaders.ToArray());
CreateAndAddShader("BFRES_Debug", bfresDebugShaders.ToArray());
CreateAndAddShader("BFRES_Botw", bfresBotwShaders.ToArray());
CreateAndAddShader("BFRES_Normals", NormalsSharedShaders.ToArray());
CreateAndAddShader("KCL", "KCL.frag", "KCL.vert");
CreateAndAddShader("HDRSkyBox", HDRShaders.ToArray());
}
public static void CreateAndAddShader(string shaderProgramName, params string[] shaderRelativePaths)
{
if (!OpenTKSharedResources.shaders.ContainsKey(shaderProgramName))
{
Shader shader = CreateShader(shaderProgramName, shaderRelativePaths);
OpenTKSharedResources.shaders.Add(shaderProgramName, shader);
}
}
private static Shader CreateShader(string shaderProgramName, string[] shaderRelativePaths)
{
Shader shader = new Shader();
LoadShaderFiles(shader, shaderRelativePaths);
return shader;
}
private static void LoadShaderFiles(Shader shader, string[] shaderRelativePaths)
{
var shaders = new List<Tuple<string, ShaderType, string>>();
foreach (string file in shaderRelativePaths)
{
// The input paths are relative to the main shader directory.
string shaderPath = shaderSourceDirectory + "\\" + file;
if (!File.Exists(shaderPath))
continue;
// Read the shader file.
string shaderName = Path.GetFileNameWithoutExtension(shaderPath);
string shaderSource = File.ReadAllText(shaderPath);
// Determine the shader type based on the file extension.
ShaderType shaderType = ShaderType.FragmentShader;
if (file.EndsWith(".vert"))
shaderType = ShaderType.VertexShader;
else if (file.EndsWith(".frag"))
shaderType = ShaderType.FragmentShader;
else if (file.EndsWith(".geom"))
shaderType = ShaderType.GeometryShader;
shaders.Add(new Tuple<string, ShaderType, string>(shaderSource, shaderType, shaderName));
}
shader.LoadShaders(shaders);
}
public static void SystemColorVector3Uniform(Shader shader, System.Drawing.Color color, string name)
{
shader.SetVector3(name, ColorUtils.GetVector4(color).Xyz);
}
public static void SaveErrorLogs()
{
// Export error logs for all the shaders.
List<String> compileErrorList = new List<String>();
int successfulCompilations = OpenTKSharedResources.shaders.Count;
foreach (string shaderName in OpenTKSharedResources.shaders.Keys)
{
if (!OpenTKSharedResources.shaders[shaderName].LinkStatusIsOk)
{
compileErrorList.Add(shaderName);
successfulCompilations -= 1;
}
// Create the error logs directory if not found.
string errorLogDirectory = executableDir + "\\Shader Error Logs\\";
if (!Directory.Exists(errorLogDirectory))
Directory.CreateDirectory(errorLogDirectory);
// Export the error log.
string logExport = OpenTKSharedResources.shaders[shaderName].GetErrorLog();
File.WriteAllText(errorLogDirectory + shaderName + " Error Log.txt", logExport.Replace("\n", Environment.NewLine));
}
// Display how many shaders correctly compiled.
string message = String.Format("{0} of {1} shaders compiled successfully. Error logs have been saved to the Shader Error Logs directory.\n",
successfulCompilations, OpenTKSharedResources.shaders.Count);
// Display the shaders that didn't compile.
if (compileErrorList.Count > 0)
{
message += "The following shaders failed to compile:\n";
foreach (String shader in compileErrorList)
message += shader + "\n";
}
MessageBox.Show(message, "GLSL Shader Error Logs Exported");
}
}
}

View file

@ -624,12 +624,14 @@
<Compile Include="Rendering\DrawableSkybox.cs" />
<Compile Include="Rendering\DrawableFloor.cs" />
<Compile Include="Rendering\DrawableXyzLines.cs" />
<Compile Include="Rendering\OpenTKSharedResources.cs" />
<Compile Include="Rendering\PBRMapGenerator.cs" />
<Compile Include="Rendering\ProbeLighting.cs" />
<Compile Include="Rendering\RenderTools.cs" />
<Compile Include="Rendering\ScreenTriangle.cs" />
<Compile Include="Generics\STSkeleton.cs" />
<Compile Include="Rendering\RenderLib.cs" />
<Compile Include="Rendering\SetUpShaders.cs" />
<Compile Include="Runtime.cs" />
<Compile Include="FormThemes.cs" />
<Compile Include="STToolStipMenuItem.cs">

View file

@ -55,6 +55,7 @@
this.consoleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.requestFeatureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.tutorialToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportBugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.requestFeatureToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.githubToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -69,7 +70,6 @@
this.stToolStrip1 = new Switch_Toolbox.Library.Forms.STToolStrip();
this.saveToolStripButton = new System.Windows.Forms.ToolStripButton();
this.updateToolstrip = new System.Windows.Forms.ToolStripButton();
this.tutorialToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.stPanel1.SuspendLayout();
this.tabControlContextMenuStrip.SuspendLayout();
@ -117,33 +117,33 @@
// newToolStripMenuItem
//
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
this.newToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
this.newToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.newToolStripMenuItem.Text = "New";
//
// newFromFileToolStripMenuItem
//
this.newFromFileToolStripMenuItem.Name = "newFromFileToolStripMenuItem";
this.newFromFileToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
this.newFromFileToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.newFromFileToolStripMenuItem.Text = "New From File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.openToolStripMenuItem.Text = "Open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
//
// recentToolStripMenuItem
//
this.recentToolStripMenuItem.Name = "recentToolStripMenuItem";
this.recentToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
this.recentToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.recentToolStripMenuItem.Text = "Recent";
//
// saveToolStripMenuItem
//
this.saveToolStripMenuItem.Enabled = false;
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveToolStripMenuItem.Text = "Save";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
//
@ -151,14 +151,14 @@
//
this.saveAsToolStripMenuItem.Enabled = false;
this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveAsToolStripMenuItem.Text = "Save As";
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
@ -179,7 +179,7 @@
// compressionToolStripMenuItem
//
this.compressionToolStripMenuItem.Name = "compressionToolStripMenuItem";
this.compressionToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
this.compressionToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.compressionToolStripMenuItem.Text = "Compression";
//
// experimentalToolStripMenuItem
@ -248,7 +248,7 @@
// mainSettingsToolStripMenuItem
//
this.mainSettingsToolStripMenuItem.Name = "mainSettingsToolStripMenuItem";
this.mainSettingsToolStripMenuItem.Size = new System.Drawing.Size(161, 22);
this.mainSettingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.mainSettingsToolStripMenuItem.Text = "Main Settings";
this.mainSettingsToolStripMenuItem.Click += new System.EventHandler(this.mainSettingsToolStripMenuItem_Click);
//
@ -256,7 +256,7 @@
//
this.fileAssociationsToolStripMenuItem.Enabled = false;
this.fileAssociationsToolStripMenuItem.Name = "fileAssociationsToolStripMenuItem";
this.fileAssociationsToolStripMenuItem.Size = new System.Drawing.Size(161, 22);
this.fileAssociationsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.fileAssociationsToolStripMenuItem.Text = "File Associations";
this.fileAssociationsToolStripMenuItem.Click += new System.EventHandler(this.fileAssociationsToolStripMenuItem_Click);
//
@ -282,28 +282,35 @@
// aboutToolStripMenuItem1
//
this.aboutToolStripMenuItem1.Name = "aboutToolStripMenuItem1";
this.aboutToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
this.aboutToolStripMenuItem1.Size = new System.Drawing.Size(158, 22);
this.aboutToolStripMenuItem1.Text = "About";
this.aboutToolStripMenuItem1.Click += new System.EventHandler(this.aboutToolStripMenuItem1_Click);
//
// tutorialToolStripMenuItem
//
this.tutorialToolStripMenuItem.Name = "tutorialToolStripMenuItem";
this.tutorialToolStripMenuItem.Size = new System.Drawing.Size(158, 22);
this.tutorialToolStripMenuItem.Text = "Tutorials";
this.tutorialToolStripMenuItem.Click += new System.EventHandler(this.tutorialToolStripMenuItem_Click);
//
// reportBugToolStripMenuItem
//
this.reportBugToolStripMenuItem.Name = "reportBugToolStripMenuItem";
this.reportBugToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.reportBugToolStripMenuItem.Size = new System.Drawing.Size(158, 22);
this.reportBugToolStripMenuItem.Text = "Report Bug";
this.reportBugToolStripMenuItem.Click += new System.EventHandler(this.reportBugToolStripMenuItem_Click);
//
// requestFeatureToolStripMenuItem1
//
this.requestFeatureToolStripMenuItem1.Name = "requestFeatureToolStripMenuItem1";
this.requestFeatureToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
this.requestFeatureToolStripMenuItem1.Size = new System.Drawing.Size(158, 22);
this.requestFeatureToolStripMenuItem1.Text = "Request Feature";
this.requestFeatureToolStripMenuItem1.Click += new System.EventHandler(this.requestFeatureToolStripMenuItem1_Click);
//
// githubToolStripMenuItem
//
this.githubToolStripMenuItem.Name = "githubToolStripMenuItem";
this.githubToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.githubToolStripMenuItem.Size = new System.Drawing.Size(158, 22);
this.githubToolStripMenuItem.Text = "Github";
this.githubToolStripMenuItem.Click += new System.EventHandler(this.githubToolStripMenuItem_Click);
//
@ -436,13 +443,6 @@
this.updateToolstrip.ToolTipText = "Update Tool";
this.updateToolstrip.Click += new System.EventHandler(this.updateToolstrip_Click);
//
// tutorialToolStripMenuItem
//
this.tutorialToolStripMenuItem.Name = "tutorialToolStripMenuItem";
this.tutorialToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.tutorialToolStripMenuItem.Text = "Tutorials";
this.tutorialToolStripMenuItem.Click += new System.EventHandler(this.tutorialToolStripMenuItem_Click);
//
// MainForm
//
this.AllowDrop = true;

View file

@ -16,6 +16,7 @@ using System.Runtime.InteropServices;
using System.Reflection;
using OpenTK.Graphics.OpenGL;
using Switch_Toolbox.Library.NodeWrappers;
using Switch_Toolbox.Library.Rendering;
namespace Toolbox
{
@ -99,8 +100,11 @@ namespace Toolbox
//Create an instance of this to help load open gl data easier and quicker after boot
var viewport = new Viewport(false);
ShaderTools.executableDir = Runtime.ExecutableDir;
if (OpenTK.Graphics.GraphicsContext.CurrentContext != null)
{
OpenTKSharedResources.InitializeSharedResources();
Runtime.OpenTKInitialized = true;
Runtime.renderer = GL.GetString(StringName.Renderer);
@ -1177,5 +1181,11 @@ namespace Toolbox
private void tutorialToolStripMenuItem_Click(object sender, EventArgs e) {
System.Diagnostics.Process.Start("https://github.com/KillzXGaming/Switch-Toolbox/wiki/Tutorial-Home-Page");
}
private void checkShaderErrorsToolStripMenuItem_Click(object sender, EventArgs e)
{
ShaderTools.SaveErrorLogs();
}
}
}

View file

@ -57,6 +57,7 @@ uniform vec3 materialSelectColor;
// Shader Params
uniform float normal_map_weight;
uniform float ao_density;
uniform float shadow_density;
uniform float emission_intensity;
uniform vec4 fresnelParams;
uniform vec4 base_color_mul_color;
@ -219,12 +220,6 @@ void main()
vec4 diffuseMapColor = vec4(texture(DiffuseMap, f_texcoord0).rgb, 1);
//vec4 diffuseMapColor = vec4(1);
//diffuseMapColor.r = ParseComponent(RedChannel, diffuseMapTex);
//diffuseMapColor.g = ParseComponent(BlueChannel, diffuseMapTex);
// diffuseMapColor.b = ParseComponent(GreenChannel, diffuseMapTex);
// diffuseMapColor.a = ParseComponent(AlphaChannel, diffuseMapTex);
diffuseMapColor *= halfLambert;
vec3 LightingDiffuse = vec3(0);
@ -233,34 +228,34 @@ void main()
vec3 LightIntensity = vec3(0.1);
LightingDiffuse += ShadowBake.indirectLighting.rgb * LightIntensity;
}
float ShadowPass = 1;
float AoPass = 1;
if (HasShadowMap == 1)
{
float aoBlend = 0;
aoBlend += 1.0 - ShadowBake.aoIntensity;
float shadowBlend = 0;
shadowBlend += 1.0 - ShadowBake.shadowIntensity;
ShadowPass *= 1.0 - shadowBlend * shadow_density * 0.5;
AoPass *= 1.0 - aoBlend * ao_density * 0.6;
}
diffuseMapColor.rgb += LightingDiffuse;
vec3 LightDiffuse = vec3(0.03);
//diffuseMapColor.rgb += mix(LightingDiffuse, diffuseMapColor.rgb, vec3(ShadowBake.shadowIntensity) );
fragColor.rgb += diffuseMapColor.rgb;
fragColor.rgb *= ShadowPass;
fragColor.rgb *= AoPass;
vec3 color = vec3(1);
vec3 normal = texture(NormalMap, f_texcoord0).rgb;
vec3 specular = texture(SpecularMap, f_texcoord0).rgb;
float aoBlend = 1;
if (HasShadowMap == 1)
{
if (bake_shadow_type == 0)
{
aoBlend = texture(BakeShadowMap, f_texcoord1).r;
fragColor.rgb *= aoBlend;
}
if (bake_shadow_type == 2)
{
aoBlend = texture(BakeShadowMap, f_texcoord1).r;
// fragColor *= aoBlend;
//For this it will need a frame buffer to be used
vec4 ShadowTex = vec4(texture(BakeShadowMap, f_texcoord1).ggg, 1);
}
}
float SpecularAmount = 0;
@ -275,7 +270,7 @@ void main()
if (HasEmissionMap == 1 || enable_emission == 1) //Can be without texture map
fragColor.rgb += EmissionPass(EmissionMap, emission_intensity, vert, 0, emission_color);
fragColor.rgb += SpecularPass(I, N, HasSpecularMap, SpecularMap, specular_color, vert, 0);
fragColor.rgb += ReflectionPass(N, I, diffuseMapColor,SpecularAmount, aoBlend, tintColor, vert);
fragColor.rgb += ReflectionPass(N, I, diffuseMapColor,SpecularAmount, AoPass, tintColor, vert);
fragColor.rgb *= pickingColor.rgb;

View file

@ -31,8 +31,10 @@ BakedData ShadowMapBaked(sampler2D ShadowMap, sampler2D LightMap, vec2 texCoordB
BakedData bake0;
bake0.indirectLighting = vec3(0);
bake0.aoIntensity = 1;
bake0.shadowIntensity = 1;
if (CalcType != -1)
if (CalcType == 222)
{
vec4 bakeTex0 = texture(ShadowMap, texCoordBake0);

View file

@ -209,6 +209,8 @@ vec3 saturation(vec3 rgb, float adjustment)
void main()
{
bool RenderAsLighting = renderType == 2;
fragColor = vec4(1);
// Create a struct for passing all the vertex attributes to other functions.
@ -265,6 +267,12 @@ void main()
lightMapIntensity = texture(BakeLightMap, f_texcoord1).a;
}
if (RenderAsLighting)
{
metallic = 0;
roughness = 1;
}
float specIntensity = 1;
if (HasMRA == 1) //Kirby Star Allies PBR map
@ -304,6 +312,9 @@ void main()
LightingDiffuse += ShadowBake.indirectLighting.rgb * LightIntensity;
}
// shadow *= ShadowBake.shadowIntensity;
// ao *= ShadowBake.aoIntensity;
// Diffuse pass
vec3 diffuseIblColor = texture(irradianceMap, N).rgb;
vec3 diffuseTerm = diffuseIblColor * albedo;
@ -351,6 +362,15 @@ void main()
float alpha = texture(DiffuseMap, f_texcoord0).a;
fragColor.a = alpha;
if (RenderAsLighting)
{
fragColor.rgb = specularTerm;
fragColor.rgb += emissionTerm;
fragColor.rgb *= 2.5;
fragColor.rgb = fragColor.rgb / (fragColor.rgb + vec3(1.0));
fragColor.rgb = pow(fragColor.rgb, vec3(1 / gamma));
}
// Toggles rendering of individual color channels for all render modes.
fragColor.rgb *= vec3(renderR, renderG, renderB);
if (renderR == 1 && renderG == 0 && renderB == 0)

25
Toolbox/Shader/Bone.frag Normal file
View file

@ -0,0 +1,25 @@
#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);
}