Improve load times significantly for layout files.

Shaders are now compiled only once and load statically instead of being per material.
This commit is contained in:
KillzXGaming 2019-10-20 19:30:58 -04:00
parent 0da677980f
commit a8016a2868
12 changed files with 204 additions and 196 deletions

View file

@ -22,7 +22,7 @@ namespace LayoutBXLYT
public void LoadShaders()
{
program = CompileShaders();
Compile();
}
public void Enable()

View file

@ -73,14 +73,9 @@ namespace LayoutBXLYT
};
var mat = pic1Pane.Material as BFLYT.Material;
if (mat.Shader == null)
{
mat.Shader = new BflytShader(mat);
mat.Shader.Compile();
}
mat.Shader.Enable();
((BflytShader)mat.Shader).SetMaterials(pic1Pane,Textures);
ShaderLoader.CafeShader.Enable();
BflytShader.SetMaterials(ShaderLoader.CafeShader, mat, pane, Textures);
if (pic1Pane.TexCoords.Length > 0)
{
@ -94,7 +89,7 @@ namespace LayoutBXLYT
DrawRectangle(pane, gameWindow, pane.Rectangle, TexCoords, Colors, false, effectiveAlpha, isSelected);
mat.Shader.Disable();
ShaderLoader.CafeShader.Disable();
}
else if (pane is BCLYT.PIC1)
{
@ -108,14 +103,9 @@ namespace LayoutBXLYT
};
var mat = pic1Pane.Material as BCLYT.Material;
if (mat.Shader == null)
{
mat.Shader = new BclytShader(mat);
mat.Shader.Compile();
}
mat.Shader.Enable();
((BclytShader)mat.Shader).SetMaterials(pane,Textures);
ShaderLoader.CtrShader.Enable();
BclytShader.SetMaterials(ShaderLoader.CtrShader, (BCLYT.Material)mat, pane, Textures);
if (pic1Pane.TexCoords.Length > 0)
{
@ -129,7 +119,7 @@ namespace LayoutBXLYT
DrawRectangle(pane, gameWindow, pane.Rectangle, TexCoords, Colors, false, effectiveAlpha, isSelected);
mat.Shader.Disable();
ShaderLoader.CtrShader.Disable();
}
else if (pane is BRLYT.PIC1)
{
@ -143,14 +133,9 @@ namespace LayoutBXLYT
};
var mat = pic1Pane.Material as BRLYT.Material;
if (mat.Shader == null)
{
mat.Shader = new BrlytShader(mat);
mat.Shader.Compile();
}
mat.Shader.Enable();
((BrlytShader)mat.Shader).SetMaterials(pane, Textures);
ShaderLoader.RevShader.Enable();
BrlytShader.SetMaterials(ShaderLoader.RevShader, (BRLYT.Material)mat, pane, Textures);
if (pic1Pane.TexCoords.Length > 0)
{
@ -164,7 +149,7 @@ namespace LayoutBXLYT
DrawRectangle(pane, gameWindow, pane.Rectangle, TexCoords, Colors, false, effectiveAlpha, isSelected);
mat.Shader.Disable();
ShaderLoader.RevShader.Disable();
}
GL.Disable(EnableCap.Texture2D);
@ -270,19 +255,16 @@ namespace LayoutBXLYT
BindFontBitmap(pane, fontBitmap);
var mat = textBox.Material as BFLYT.Material;
if (mat.Shader == null)
{
mat.Shader = new BflytShader(mat);
mat.Shader.Compile();
}
mat.Shader.Enable();
((BflytShader)mat.Shader).SetMaterials(pane, Textures);
BxlytShader shader = ShaderLoader.CafeShader;
ShaderLoader.CafeShader.Enable();
BflytShader.SetMaterials(ShaderLoader.CafeShader, mat, pane, Textures);
GL.ActiveTexture(TextureUnit.Texture0 + 1);
mat.Shader.SetInt($"numTextureMaps", 1);
mat.Shader.SetInt($"textures0", 1);
mat.Shader.SetInt($"hasTexture0", 1);
shader.SetInt($"numTextureMaps", 1);
shader.SetInt($"textures0", 1);
shader.SetInt($"hasTexture0", 1);
GL.BindTexture(TextureTarget.Texture2D, textBox.RenderableFont.TexID);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, ConvertChannel(STChannelType.Red));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, ConvertChannel(STChannelType.Green));
@ -309,7 +291,7 @@ namespace LayoutBXLYT
DrawRectangle(pane, gameWindow, pane.Rectangle, texCoords, Colors, false, effectiveAlpha, isSelected);
// mat.Shader.Disable();
ShaderLoader.CafeShader.Disable();
GL.Disable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, 0);
@ -422,6 +404,14 @@ namespace LayoutBXLYT
if (!Runtime.LayoutEditor.DisplayWindowPane)
return;
BxlytShader shader = null;
if (pane is BFLYT.PAN1)
shader = ShaderLoader.CafeShader;
if (pane is BCLYT.PAN1)
shader = ShaderLoader.CtrShader;
if (pane is BRLYT.PAN1)
shader = ShaderLoader.RevShader;
var window = (IWindowPane)pane;
float dX = DrawnVertexX(pane.Width, pane.originX);
@ -531,7 +521,8 @@ namespace LayoutBXLYT
var windowFrame = window.WindowFrames[0];
SetupShaders(pane, windowFrame.Material, Textures);
windowFrame.Material.Shader.SetInt("flipTexture", (int)window.WindowFrames[0].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[0].TextureFlip);
hasTextures = windowFrame.Material.TextureMaps?.Length > 0;
@ -734,7 +725,7 @@ namespace LayoutBXLYT
{
SetupShaders(pane, matTL, Textures);
matTL.Shader.SetInt("flipTexture", (int)window.WindowFrames[0].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[0].TextureFlip);
float pieceWidth = pane.Width - frameRight;
float pieceHeight = frameTop;
@ -753,7 +744,7 @@ namespace LayoutBXLYT
{
SetupShaders(pane, matTR, Textures);
matTR.Shader.SetInt("flipTexture", (int)window.WindowFrames[1].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[1].TextureFlip);
float pieceWidth = frameRight;
float pieceHeight = pane.Height - frameBottom;
@ -772,7 +763,7 @@ namespace LayoutBXLYT
{
SetupShaders(pane, matBL, Textures);
matBL.Shader.SetInt("flipTexture", (int)window.WindowFrames[2].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[2].TextureFlip);
float pieceWidth = frameLeft;
float pieceHeight = pane.Height - frameTop;
@ -791,7 +782,7 @@ namespace LayoutBXLYT
{
SetupShaders(pane, matBR, Textures);
matBR.Shader.SetInt("flipTexture", (int)window.WindowFrames[3].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[3].TextureFlip);
float pieceWidth = pane.Width - frameLeft;
float pieceHeight = frameBottom;
@ -835,7 +826,7 @@ namespace LayoutBXLYT
if (matTL.TextureMaps.Length > 0)
{
SetupShaders(pane, matTL, Textures);
matTL.Shader.SetInt("flipTexture", (int)window.WindowFrames[0].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[0].TextureFlip);
texCoords = new Vector2[]
{
@ -851,7 +842,7 @@ namespace LayoutBXLYT
if (matTR.TextureMaps.Length > 0)
{
SetupShaders(pane, matTR, Textures);
matTR.Shader.SetInt("flipTexture", (int)window.WindowFrames[1].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[1].TextureFlip);
texCoords = new Vector2[]
{
@ -867,7 +858,7 @@ namespace LayoutBXLYT
if (matBL.TextureMaps.Length > 0)
{
SetupShaders(pane, matBL, Textures);
matBL.Shader.SetInt("flipTexture", (int)window.WindowFrames[2].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[2].TextureFlip);
texCoords = new Vector2[]
{
@ -883,7 +874,7 @@ namespace LayoutBXLYT
if (matBR.TextureMaps.Length > 0)
{
SetupShaders(pane, matBR, Textures);
matBR.Shader.SetInt("flipTexture", (int)window.WindowFrames[3].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[3].TextureFlip);
texCoords = new Vector2[]
{
@ -899,7 +890,7 @@ namespace LayoutBXLYT
if (matT.TextureMaps.Length > 0)
{
SetupShaders(pane, matT, Textures);
matT.Shader.SetInt("flipTexture", (int)window.WindowFrames[4].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[4].TextureFlip);
texCoords = new Vector2[]
{
@ -915,7 +906,7 @@ namespace LayoutBXLYT
if (matB.TextureMaps.Length > 0)
{
SetupShaders(pane, matB, Textures);
matB.Shader.SetInt("flipTexture", (int)window.WindowFrames[5].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[5].TextureFlip);
texCoords = new Vector2[]
{
@ -931,7 +922,7 @@ namespace LayoutBXLYT
if (matL.TextureMaps.Length > 0)
{
SetupShaders(pane, matL, Textures);
matL.Shader.SetInt("flipTexture", (int)window.WindowFrames[6].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[6].TextureFlip);
texCoords = new Vector2[]
{
@ -947,7 +938,7 @@ namespace LayoutBXLYT
if (matR.TextureMaps.Length > 0)
{
SetupShaders(pane, matR, Textures);
matR.Shader.SetInt("flipTexture", (int)window.WindowFrames[7].TextureFlip);
shader.SetInt("flipTexture", (int)window.WindowFrames[7].TextureFlip);
texCoords = new Vector2[]
{
@ -1081,35 +1072,24 @@ namespace LayoutBXLYT
}
private static void SetupShaders(BasePane pane, BxlytMaterial mat, Dictionary<string, STGenericTexture> textures)
{
if (mat.Shader == null)
{
if (mat is Cafe.BFLYT.Material)
{
mat.Shader = new BflytShader((Cafe.BFLYT.Material)mat);
mat.Shader.Compile();
ShaderLoader.CafeShader.Enable();
BflytShader.SetMaterials(ShaderLoader.CafeShader, (Cafe.BFLYT.Material)mat, pane, textures);
}
else if (mat is BRLYT.Material)
{
mat.Shader = new BrlytShader((BRLYT.Material)mat);
mat.Shader.Compile();
ShaderLoader.RevShader.Enable();
BrlytShader.SetMaterials(ShaderLoader.RevShader, (BRLYT.Material)mat, pane, textures);
}
else if (mat is BCLYT.Material)
{
mat.Shader = new BclytShader((BCLYT.Material)mat);
mat.Shader.Compile();
ShaderLoader.CtrShader.Enable();
BclytShader.SetMaterials(ShaderLoader.CtrShader, (BCLYT.Material)mat, pane, textures);
}
}
mat.Shader.Enable();
if (mat is Cafe.BFLYT.Material)
((BflytShader)mat.Shader).SetMaterials(pane, textures);
else if (mat is BRLYT.Material)
((BrlytShader)mat.Shader).SetMaterials(pane, textures);
else if (mat is BCLYT.Material)
((BclytShader)mat.Shader).SetMaterials(pane, textures);
}
private static void RenderWindowContent(BasePane pane, uint sizeX, uint sizeY, BxlytWindowContent content,
byte effectiveAlpha, Dictionary<string, STGenericTexture> Textures)
{

View file

@ -1631,12 +1631,14 @@ namespace LayoutBXLYT.Cafe
if (ExternalLayout == null)
return;
var textureList = ExternalLayout.GetTextures();
ExternalLayout.header.TextureManager = layoutFile.TextureManager;
/* var textureList = ExternalLayout.GetTextures();
foreach (var tex in textureList)
if (!textures.ContainsKey(tex.Key))
textures.Add(tex.Key, tex.Value);
textureList.Clear();
textureList.Clear();*/
}
}

View file

@ -12,11 +12,7 @@ namespace LayoutBXLYT
{
public class BflytShader : BxlytShader
{
public BFLYT.Material material;
public BflytShader(BFLYT.Material mat) : base()
{
material = mat;
public BflytShader() : base() {
LoadShaders();
}
@ -45,10 +41,10 @@ namespace LayoutBXLYT
SetInt($"texCoords0Source", 0);
}
public void SetMaterials(BasePane pane, Dictionary<string, STGenericTexture> textures)
public static void SetMaterials(BxlytShader shader, BFLYT.Material material, BasePane pane, Dictionary<string, STGenericTexture> textures)
{
var rotationMatrix = pane.GetRotationMatrix();
SetMatrix("rotationMatrix", ref rotationMatrix);
shader.SetMatrix("rotationMatrix", ref rotationMatrix);
STColor8 WhiteColor = material.WhiteColor;
STColor8 BlackColor = material.BlackColor;
@ -76,29 +72,29 @@ namespace LayoutBXLYT
}
}
SetColor("whiteColor", WhiteColor.Color);
SetColor("blackColor", BlackColor.Color);
SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
SetInt("numTextureMaps", material.TextureMaps.Length);
SetVec2("uvScale0", new Vector2(1, 1));
SetFloat("uvRotate0", 0);
SetVec2("uvTranslate0", new Vector2(0, 0));
SetInt("flipTexture", 0);
SetInt("numTevStages", material.TevStages.Length);
SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0));
SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0));
SetInt("tevTexMode", 0);
SetInt($"texCoords0GenType", 0);
SetInt($"texCoords0Source", 0);
SetInt("hasTexture0", 0);
SetInt("hasTexture1", 0);
SetInt("hasTexture2", 0);
SetInt("textures0", 0);
SetInt("textures1", 0);
SetInt("textures2", 0);
shader.SetColor("whiteColor", WhiteColor.Color);
shader.SetColor("blackColor", BlackColor.Color);
shader.SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
shader.SetInt("numTextureMaps", material.TextureMaps.Length);
shader.SetVec2("uvScale0", new Vector2(1, 1));
shader.SetFloat("uvRotate0", 0);
shader.SetVec2("uvTranslate0", new Vector2(0, 0));
shader.SetInt("flipTexture", 0);
shader.SetInt("numTevStages", material.TevStages.Length);
shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
shader.SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0));
shader.SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0));
shader.SetInt("tevTexMode", 0);
shader.SetInt($"texCoords0GenType", 0);
shader.SetInt($"texCoords0Source", 0);
shader.SetInt("hasTexture0", 0);
shader.SetInt("hasTexture1", 0);
shader.SetInt("hasTexture2", 0);
shader.SetInt("textures0", 0);
shader.SetInt("textures1", 0);
shader.SetInt("textures2", 0);
BindTextureUniforms();
BindTextureUniforms(shader, material);
if (material.TextureMaps.Length > 0 || Runtime.LayoutEditor.Shading == Runtime.LayoutEditor.DebugShading.UVTestPattern)
GL.Enable(EnableCap.Texture2D);
@ -114,10 +110,10 @@ namespace LayoutBXLYT
if (textures.ContainsKey(TexName))
{
GL.ActiveTexture(TextureUnit.Texture0 + id);
SetInt($"textures{i}", id);
shader.SetInt($"textures{i}", id);
bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[i], textures[TexName]);
if (isBinded)
SetInt($"hasTexture{i}", 1);
shader.SetInt($"hasTexture{i}", 1);
id++;
}
@ -125,14 +121,14 @@ namespace LayoutBXLYT
for (int i = 0; i < material.TexCoords?.Length; i++)
{
SetInt($"texCoords{i}GenType", (int)material.TexCoords[i].GenType);
SetInt($"texCoords{i}Source", (int)material.TexCoords[i].Source);
shader.SetInt($"texCoords{i}GenType", (int)material.TexCoords[i].GenType);
shader.SetInt($"texCoords{i}Source", (int)material.TexCoords[i].Source);
}
for (int i = 0; i < material.TevStages?.Length; i++)
{
SetInt($"tevStage{i}RGB", (int)material.TevStages[i].ColorMode);
SetInt($"tevStage{i}A", (int)material.TevStages[i].AlphaMode);
shader.SetInt($"tevStage{i}RGB", (int)material.TevStages[i].ColorMode);
shader.SetInt($"tevStage{i}A", (int)material.TevStages[i].AlphaMode);
}
if (material.TextureTransforms.Length > 0)
@ -154,9 +150,9 @@ namespace LayoutBXLYT
}
}
SetVec2("uvScale0", new Vector2(scale.X, scale.Y));
SetFloat("uvRotate0", rotate);
SetVec2("uvTranslate0", new Vector2(translate.X, translate.Y));
shader.SetVec2("uvScale0", new Vector2(scale.X, scale.Y));
shader.SetFloat("uvRotate0", rotate);
shader.SetVec2("uvTranslate0", new Vector2(translate.X, translate.Y));
}
@ -202,11 +198,11 @@ namespace LayoutBXLYT
}
}
private void BindTextureUniforms()
private static void BindTextureUniforms(BxlytShader shader, BxlytMaterial material)
{
//Do uv test pattern
GL.ActiveTexture(TextureUnit.Texture10);
GL.Uniform1(GL.GetUniformLocation(program, "uvTestPattern"), 10);
GL.Uniform1(GL.GetUniformLocation(shader.program, "uvTestPattern"), 10);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID);
if (material.TextureMaps.Length > 0)

View file

@ -892,9 +892,6 @@ namespace LayoutBXLYT
public STColor8 TevColor { get; set; }
public STColor8[] TevConstantColors { get; set; }
public List<TextureRef> TextureMaps { get; set; }
public List<TextureTransform> TextureTransforms { get; set; }
private uint flags;
private BCLYT.Header ParentLayout;
@ -908,17 +905,14 @@ namespace LayoutBXLYT
public Material()
{
TextureMaps = new List<TextureRef>();
TextureTransforms = new List<TextureTransform>();
TextureMaps = new TextureRef[0];
TextureTransforms = new TextureTransform[0];
}
public Material(FileReader reader, Header header) : base()
{
ParentLayout = header;
TextureMaps = new List<TextureRef>();
TextureTransforms = new List<TextureTransform>();
Name = reader.ReadString(20, true);
TevColor = reader.ReadColor8RGBA();
TevConstantColors = reader.ReadColor8sRGBA(6);
@ -929,11 +923,14 @@ namespace LayoutBXLYT
uint texCoordGens = (flags >> 4) & 3;
uint tevStages = (flags >> 6) & 7;
TextureMaps = new TextureRef[texCount];
TextureTransforms = new TextureTransform[mtxCount];
for (int i = 0; i < texCount; i++)
TextureMaps.Add(new TextureRef(reader, header));
TextureMaps[i] = new TextureRef(reader, header);
for (int i = 0; i < mtxCount; i++)
TextureTransforms.Add(new TextureTransform(reader));
TextureTransforms[i] = new TextureTransform(reader);
}
public void Write(FileWriter writer, Header header)
@ -943,20 +940,16 @@ namespace LayoutBXLYT
writer.Write(TevConstantColors);
writer.Write(flags);
for (int i = 0; i < TextureMaps.Count; i++)
TextureMaps[i].Write(writer);
for (int i = 0; i < TextureMaps.Length; i++)
((TextureRef)TextureMaps[i]).Write(writer);
for (int i = 0; i < TextureTransforms.Count; i++)
TextureTransforms[i].Write(writer);
for (int i = 0; i < TextureTransforms.Length; i++)
((TextureTransform)TextureTransforms[i]).Write(writer);
}
}
public class TextureTransform
public class TextureTransform : BxlytTextureTransform
{
public Vector2F Translate;
public float Rotate;
public Vector2F Scale;
public TextureTransform() { }
public TextureTransform(FileReader reader)

View file

@ -11,11 +11,8 @@ namespace LayoutBXLYT
{
public class BclytShader : BxlytShader
{
public BCLYT.Material material;
public BclytShader(BCLYT.Material mat) : base()
public BclytShader() : base()
{
material = mat;
LoadShaders();
}
@ -42,59 +39,59 @@ namespace LayoutBXLYT
SetInt($"texCoords0Source", 0);
}
public void SetMaterials(BasePane pane, Dictionary<string, STGenericTexture> textures)
public static void SetMaterials(BxlytShader shader, BCLYT.Material material, BasePane pane, Dictionary<string, STGenericTexture> textures)
{
Matrix4 rotationX = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(pane.Rotate.X));
Matrix4 rotationY = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(pane.Rotate.Y));
Matrix4 rotationZ = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(pane.Rotate.Z));
var rotationMatrix = rotationX * rotationY * rotationZ;
SetMatrix("rotationMatrix", ref rotationMatrix);
shader.SetMatrix("rotationMatrix", ref rotationMatrix);
SetColor("whiteColor", material.TevConstantColors[0].Color);
SetColor("blackColor", material.TevColor.Color);
SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
SetInt("numTextureMaps", material.TextureMaps.Count);
SetVec2("uvScale0", new Vector2(1, 1));
SetFloat("uvRotate0", 0);
SetVec2("uvTranslate0", new Vector2(0, 0));
SetInt("flipTexture", 0);
SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
SetInt($"texCoords0GenType", 0);
SetInt($"texCoords0Source", 0);
shader.SetColor("whiteColor", material.TevConstantColors[0].Color);
shader.SetColor("blackColor", material.TevColor.Color);
shader.SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
shader.SetInt("numTextureMaps", material.TextureMaps.Length);
shader.SetVec2("uvScale0", new Vector2(1, 1));
shader.SetFloat("uvRotate0", 0);
shader.SetVec2("uvTranslate0", new Vector2(0, 0));
shader.SetInt("flipTexture", 0);
shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
shader.SetInt($"texCoords0GenType", 0);
shader.SetInt($"texCoords0Source", 0);
BindTextureUniforms();
BindTextureUniforms(shader, material);
string textureMap0 = "";
if (material.TextureMaps.Count > 0)
if (material.TextureMaps.Length > 0)
textureMap0 = material.GetTexture(0);
if (textures.ContainsKey(textureMap0))
{
GL.ActiveTexture(TextureUnit.Texture0);
SetInt("textures0", 0);
shader.SetInt("textures0", 0);
bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[0], textures[textureMap0]);
if (isBinded)
SetInt("hasTexture0", 1);
shader.SetInt("hasTexture0", 1);
}
if (material.TextureTransforms.Count > 0)
if (material.TextureTransforms.Length > 0)
{
var transform = material.TextureTransforms[0];
SetVec2("uvScale0", new Vector2(transform.Scale.X, transform.Scale.Y));
SetFloat("uvRotate0", transform.Rotate);
SetVec2("uvTranslate0", new Vector2(transform.Translate.X, transform.Translate.Y));
shader.SetVec2("uvScale0", new Vector2(transform.Scale.X, transform.Scale.Y));
shader.SetFloat("uvRotate0", transform.Rotate);
shader.SetVec2("uvTranslate0", new Vector2(transform.Translate.X, transform.Translate.Y));
}
}
private void BindTextureUniforms()
private static void BindTextureUniforms(BxlytShader shader, BxlytMaterial material)
{
//Do uv test pattern
GL.ActiveTexture(TextureUnit.Texture10);
GL.Uniform1(GL.GetUniformLocation(program, "uvTestPattern"), 10);
GL.Uniform1(GL.GetUniformLocation(shader.program, "uvTestPattern"), 10);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID);
if (material.TextureMaps.Count > 0)
if (material.TextureMaps.Length > 0)
{
var tex = material.TextureMaps[0];
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, BxlytToGL.ConvertTextureWrap(tex.WrapModeU));

View file

@ -2065,9 +2065,6 @@ namespace LayoutBXLYT
[DisplayName("Thresholding Alpha Interpolation"), CategoryAttribute("Alpha")]
public virtual bool ThresholdingAlphaInterpolation { get; set; }
[Browsable(false)]
public virtual BxlytShader Shader { get; set; }
[DisplayName("Texture Maps"), CategoryAttribute("Texture")]
public BxlytTextureRef[] TextureMaps { get; set; }

View file

@ -11,11 +11,8 @@ namespace LayoutBXLYT
{
public class BrlytShader : BxlytShader
{
public BRLYT.Material material;
public BrlytShader(BRLYT.Material mat) : base()
public BrlytShader() : base()
{
material = mat;
LoadShaders();
}
@ -44,7 +41,7 @@ namespace LayoutBXLYT
SetInt($"texCoords0Source", 0);
}
public void SetMaterials(BasePane pane, Dictionary<string, STGenericTexture> textures)
public static void SetMaterials(BxlytShader shader, BRLYT.Material material, BasePane pane, Dictionary<string, STGenericTexture> textures)
{
var paneRotate = pane.Rotate;
if (pane.animController.PaneSRT?.Count > 0)
@ -68,7 +65,7 @@ namespace LayoutBXLYT
Matrix4 rotationZ = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(paneRotate.Z));
var rotationMatrix = rotationX * rotationY * rotationZ;
SetMatrix("rotationMatrix", ref rotationMatrix);
shader.SetMatrix("rotationMatrix", ref rotationMatrix);
var WhiteColor = material.WhiteColor;
var BlackColor = material.BlackColor;
@ -96,23 +93,23 @@ namespace LayoutBXLYT
}
}
SetColor("whiteColor", Color.FromArgb(255, WhiteColor.R, WhiteColor.G, WhiteColor.B));
SetColor("blackColor", BlackColor.Color);
SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
SetInt("numTextureMaps", material.TextureMaps.Length);
SetVec2("uvScale0", new Vector2(1, 1));
SetFloat("uvRotate0", 0);
SetVec2("uvTranslate0", new Vector2(0, 0));
SetInt("flipTexture", 0);
SetInt("numTevStages", 0);
SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0));
SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0));
SetInt("tevTexMode", 0);
SetInt($"texCoords0GenType", 0);
SetInt($"texCoords0Source", 0);
shader.SetColor("whiteColor", Color.FromArgb(255, WhiteColor.R, WhiteColor.G, WhiteColor.B));
shader.SetColor("blackColor", BlackColor.Color);
shader.SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
shader.SetInt("numTextureMaps", material.TextureMaps.Length);
shader.SetVec2("uvScale0", new Vector2(1, 1));
shader.SetFloat("uvRotate0", 0);
shader.SetVec2("uvTranslate0", new Vector2(0, 0));
shader.SetInt("flipTexture", 0);
shader.SetInt("numTevStages", 0);
shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
shader.SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0));
shader.SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0));
shader.SetInt("tevTexMode", 0);
shader.SetInt($"texCoords0GenType", 0);
shader.SetInt($"texCoords0Source", 0);
BindTextureUniforms();
BindTextureUniforms(shader, material);
int id = 1;
for (int i = 0; i < material.TextureMaps.Length; i++)
@ -125,10 +122,10 @@ namespace LayoutBXLYT
if (textures.ContainsKey(TexName))
{
GL.ActiveTexture(TextureUnit.Texture0 + id);
SetInt($"textures{i}", id);
shader.SetInt($"textures{i}", id);
bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[i], textures[TexName]);
if (isBinded)
SetInt($"hasTexture{i}", 1);
shader.SetInt($"hasTexture{i}", 1);
id++;
}
@ -153,9 +150,9 @@ namespace LayoutBXLYT
}
}
SetVec2("uvScale0", new Vector2(scale.X, scale.Y));
SetFloat("uvRotate0", rotate);
SetVec2("uvTranslate0", new Vector2(translate.X, translate.Y));
shader.SetVec2("uvScale0", new Vector2(scale.X, scale.Y));
shader.SetFloat("uvRotate0", rotate);
shader.SetVec2("uvTranslate0", new Vector2(translate.X, translate.Y));
}
GL.Enable(EnableCap.Blend);
@ -167,11 +164,11 @@ namespace LayoutBXLYT
GL.LogicOp(LogicOp.Noop);
}
private void BindTextureUniforms()
private static void BindTextureUniforms(BxlytShader shader, BxlytMaterial material)
{
//Do uv test pattern
GL.ActiveTexture(TextureUnit.Texture10);
GL.Uniform1(GL.GetUniformLocation(program, "uvTestPattern"), 10);
GL.Uniform1(GL.GetUniformLocation(shader.program, "uvTestPattern"), 10);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID);
if (material.TextureMaps.Length > 0)

View file

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LayoutBXLYT
{
public class ShaderLoader
{
private static BflytShader cafeShader;
private static BrlytShader revShader;
private static BclytShader ctrShader;
public static BflytShader CafeShader
{
get
{
if (cafeShader == null)
cafeShader = new BflytShader();
return cafeShader;
}
}
public static BrlytShader RevShader
{
get
{
if (revShader == null)
revShader = new BrlytShader();
return revShader;
}
}
public static BclytShader CtrShader
{
get
{
if (ctrShader == null)
ctrShader = new BclytShader();
return ctrShader;
}
}
}
}

View file

@ -312,6 +312,7 @@
<Compile Include="FileFormats\Layout\CAFE\Materials\TexCoordGen.cs" />
<Compile Include="FileFormats\Layout\CAFE\Materials\TextureRef.cs" />
<Compile Include="FileFormats\Layout\CAFE\Materials\TextureTransform.cs" />
<Compile Include="FileFormats\Layout\ShaderLoader.cs" />
<Compile Include="FileFormats\Layout\CTR\BCLYT.cs" />
<Compile Include="FileFormats\Layout\CAFE\FLYT.cs" />
<Compile Include="FileFormats\Layout\CTR\BclytShader.cs" />

View file

@ -89,6 +89,7 @@ namespace LayoutBXLYT
displayGridToolStripMenuItem.Checked = Runtime.LayoutEditor.DisplayGrid;
displayTextPanesToolStripMenuItem.Checked = Runtime.LayoutEditor.DisplayTextPane;
transformChildrenToolStripMenuItem.Checked = Runtime.LayoutEditor.TransformChidlren;
viewPartsAsNullPanesToolStripMenuItem.Checked = Runtime.LayoutEditor.PartsAsNullPanes;
ObjectSelected += OnObjectSelected;
ObjectChanged += OnObjectChanged;

View file

@ -1385,6 +1385,7 @@
<Folder Include="FileFormats\Compression\" />
<Folder Include="FileFormats\DAE\COLLADA\" />
<Folder Include="FileFormats\DAE\Custom\" />
<Folder Include="Rendering\Shaders\" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\boneWeightGradient.png" />