mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 20:43:09 +00:00
Add support for channel components for bfres shaders,
This commit is contained in:
parent
cce69d12e2
commit
b2f48fa8e9
12 changed files with 80 additions and 30 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -526,6 +526,11 @@ namespace FirstPlugin
|
|||
GL.Uniform1(shader.GetUniformLocation("normalMap"), 0);
|
||||
GL.Uniform1(shader.GetUniformLocation("BakeShadowMap"), 0);
|
||||
|
||||
shader.SetInt("RedChannel", 0);
|
||||
shader.SetInt("GreenChannel", 1);
|
||||
shader.SetInt("BlueChannel", 2);
|
||||
shader.SetInt("AlphaChannel", 3);
|
||||
|
||||
LoadPBRMaps(shader);
|
||||
|
||||
for (int t = 0; t < mat.TextureMaps.Count; t++)
|
||||
|
@ -589,10 +594,10 @@ namespace FirstPlugin
|
|||
// Bind the texture and create the uniform if the material has the right textures.
|
||||
if (hasTex)
|
||||
{
|
||||
GL.Uniform1(shader.GetUniformLocation(name), BindTexture(mattex, mat, mat.GetResFileU() != null));
|
||||
GL.Uniform1(shader.GetUniformLocation(name), BindTexture(mattex, mat, shader, mat.GetResFileU() != null));
|
||||
}
|
||||
}
|
||||
public static int BindTexture(MatTexture tex, FMAT material, bool IsWiiU)
|
||||
public static int BindTexture(MatTexture tex, FMAT material, SF.Shader shader, bool IsWiiU)
|
||||
{
|
||||
BFRES bfres = (BFRES)material.Parent.Parent.Parent.Parent;
|
||||
|
||||
|
@ -612,7 +617,7 @@ namespace FirstPlugin
|
|||
{
|
||||
if (ftexCont.ResourceNodes.ContainsKey(activeTex))
|
||||
{
|
||||
BindFTEX(ftexCont, tex, activeTex);
|
||||
BindFTEX(ftexCont, tex, shader, activeTex);
|
||||
return tex.textureUnit + 1;
|
||||
}
|
||||
}
|
||||
|
@ -622,7 +627,7 @@ namespace FirstPlugin
|
|||
{
|
||||
if (ftexContainer.ResourceNodes.ContainsKey(activeTex))
|
||||
{
|
||||
BindFTEX(ftexContainer, tex, activeTex);
|
||||
BindFTEX(ftexContainer, tex, shader, activeTex);
|
||||
return tex.textureUnit + 1;
|
||||
}
|
||||
}
|
||||
|
@ -636,7 +641,7 @@ namespace FirstPlugin
|
|||
{
|
||||
if (bntx.Textures.ContainsKey(activeTex))
|
||||
{
|
||||
BindBNTX(bntx, tex, activeTex);
|
||||
BindBNTX(bntx, tex, shader, activeTex);
|
||||
return tex.textureUnit + 1;
|
||||
}
|
||||
}
|
||||
|
@ -646,7 +651,7 @@ namespace FirstPlugin
|
|||
{
|
||||
if (bntx.Textures.ContainsKey(activeTex))
|
||||
{
|
||||
BindBNTX(bntx, tex, activeTex);
|
||||
BindBNTX(bntx, tex, shader, activeTex);
|
||||
return tex.textureUnit + 1;
|
||||
}
|
||||
}
|
||||
|
@ -654,17 +659,17 @@ namespace FirstPlugin
|
|||
return tex.textureUnit + 1;
|
||||
}
|
||||
|
||||
private static void BindFTEX(BFRESGroupNode ftexContainer, MatTexture tex, string activeTex)
|
||||
private static void BindFTEX(BFRESGroupNode ftexContainer, MatTexture tex, SF.Shader shader, string activeTex)
|
||||
{
|
||||
FTEX ftex = (FTEX)ftexContainer.ResourceNodes[activeTex];
|
||||
|
||||
if (ftex.RenderableTex == null || !ftex.RenderableTex.GLInitialized)
|
||||
ftex.LoadOpenGLTexture();
|
||||
|
||||
BindGLTexture(tex, ftex.RenderableTex.TexID);
|
||||
BindGLTexture(tex, shader, ftex);
|
||||
}
|
||||
|
||||
private static void BindBNTX(BNTX bntx, MatTexture tex, string activeTex)
|
||||
private static void BindBNTX(BNTX bntx, MatTexture tex, SF.Shader shader, string activeTex)
|
||||
{
|
||||
if (bntx.Textures[activeTex].RenderableTex == null ||
|
||||
!bntx.Textures[activeTex].RenderableTex.GLInitialized)
|
||||
|
@ -672,13 +677,22 @@ namespace FirstPlugin
|
|||
bntx.Textures[activeTex].LoadOpenGLTexture();
|
||||
}
|
||||
|
||||
BindGLTexture(tex, bntx.Textures[activeTex].RenderableTex.TexID);
|
||||
BindGLTexture(tex, shader, bntx.Textures[activeTex]);
|
||||
}
|
||||
|
||||
private static void BindGLTexture(MatTexture tex, int texid)
|
||||
private static void BindGLTexture(MatTexture tex, SF.Shader shader, STGenericTexture texture)
|
||||
{
|
||||
// GL.ActiveTexture(TextureUnit.Texture0 + texid);
|
||||
GL.BindTexture(TextureTarget.Texture2D, texid);
|
||||
if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
|
||||
{
|
||||
shader.SetInt("RedChannel", (int)texture.RedChannel);
|
||||
shader.SetInt("GreenChannel", (int)texture.GreenChannel);
|
||||
shader.SetInt("BlueChannel", (int)texture.BlueChannel);
|
||||
shader.SetInt("AlphaChannel", (int)texture.AlphaChannel);
|
||||
}
|
||||
|
||||
|
||||
// GL.ActiveTexture(TextureUnit.Texture0 + texid);
|
||||
GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)MatTexture.wrapmode[tex.wrapModeS]);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)MatTexture.wrapmode[tex.wrapModeT]);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)MatTexture.minfilter[tex.minFilter]);
|
||||
|
|
|
@ -272,7 +272,7 @@ namespace FirstPlugin
|
|||
Formats.Add(typeof(KCL));
|
||||
Formats.Add(typeof(BFFNT));
|
||||
Formats.Add(typeof(MSBT));
|
||||
Formats.Add(typeof(XLINK));
|
||||
// Formats.Add(typeof(XLINK));
|
||||
|
||||
// Formats.Add(typeof(BFSAR));
|
||||
Formats.Add(typeof(BARS));
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -236,7 +236,7 @@ namespace Switch_Toolbox.Library.Forms
|
|||
}
|
||||
public void Maximize()
|
||||
{
|
||||
MaximumSize = Screen.FromControl(this).WorkingArea.Size;
|
||||
// MaximumSize = Screen.FromControl(this).WorkingArea.Size;
|
||||
WindowState = FormWindowState.Maximized;
|
||||
|
||||
if (IsMdiChild)
|
||||
|
|
|
@ -145,19 +145,7 @@ vec3 EmissionPass(sampler2D EmissionMap, float emission_intensity, VertexAttribu
|
|||
vec3 SpecularPass(vec3 I, vec3 normal, int HasSpecularMap, sampler2D SpecularMap, vec3 specular_color, VertexAttributes vert, float texCoordIndex, int UseSpecularColor);
|
||||
vec3 ReflectionPass(vec3 N, vec3 I, vec4 diffuseMap, vec3 Specular, float aoBlend, vec3 tintColor, VertexAttributes vert);
|
||||
|
||||
float ParseComponent(int Type, vec4 Texture)
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case 0: return Texture.r;
|
||||
case 1: return Texture.g;
|
||||
case 2: return Texture.b;
|
||||
case 3: return Texture.a;
|
||||
case 4: return 1;
|
||||
case 5: return 0;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
float GetComponent(int Type, vec4 Texture);
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -206,6 +194,11 @@ void main()
|
|||
float halfLambert = dot(difLightDirection, N) * 0.5 + 0.5;
|
||||
|
||||
vec4 diffuseMapColor = vec4(texture(DiffuseMap, f_texcoord0).rgba);
|
||||
//Comp Selectors
|
||||
diffuseMapColor.r = GetComponent(RedChannel, diffuseMapColor);
|
||||
diffuseMapColor.g = GetComponent(GreenChannel, diffuseMapColor);
|
||||
diffuseMapColor.b = GetComponent(BlueChannel, diffuseMapColor);
|
||||
diffuseMapColor.a = GetComponent(AlphaChannel, diffuseMapColor);
|
||||
|
||||
//Texture Overlay (Like an emblem in mk8)
|
||||
if (UseMultiTexture == 1 && HasDiffuseLayer == 1)
|
||||
|
|
|
@ -114,6 +114,12 @@ uniform int UseCavityMap;
|
|||
uniform int UseMetalnessMap;
|
||||
uniform int UseRoughnessMap;
|
||||
|
||||
// Diffuse Channel Toggles
|
||||
uniform int RedChannel;
|
||||
uniform int GreenChannel;
|
||||
uniform int BlueChannel;
|
||||
uniform int AlphaChannel;
|
||||
|
||||
int isTransparent;
|
||||
|
||||
struct VertexAttributes {
|
||||
|
@ -142,6 +148,8 @@ vec3 CalcBumpedNormal(vec3 normal, sampler2D normalMap, VertexAttributes vert, f
|
|||
|
||||
vec2 displayTexCoord = f_texcoord0;
|
||||
|
||||
float GetComponent(int Type, vec4 Texture);
|
||||
|
||||
void main()
|
||||
{
|
||||
if (uvChannel == 1)
|
||||
|
@ -230,7 +238,15 @@ void main()
|
|||
fragColor.rgb = texture(NormalMap, displayTexCoord).rgb;
|
||||
}
|
||||
else if (renderType == 3) //DiffuseColor
|
||||
fragColor = vec4(texture(DiffuseMap, displayTexCoord).rgb, 1);
|
||||
{
|
||||
//Comp Selectors
|
||||
vec4 diffuseMapColor = vec4(texture(DiffuseMap, displayTexCoord).rgb, 1);
|
||||
diffuseMapColor.r = GetComponent(RedChannel, diffuseMapColor);
|
||||
diffuseMapColor.g = GetComponent(GreenChannel, diffuseMapColor);
|
||||
diffuseMapColor.b = GetComponent(BlueChannel, diffuseMapColor);
|
||||
|
||||
fragColor = vec4(diffuseMapColor.rgb, 1);
|
||||
}
|
||||
else if (renderType == 5) // vertexColor
|
||||
fragColor = vertexColor;
|
||||
else if (renderType == 6) //Display Ambient Occlusion
|
||||
|
|
|
@ -120,6 +120,12 @@ uniform int UseRoughnessMap;
|
|||
|
||||
int isTransparent;
|
||||
|
||||
// Diffuse Channel Toggles
|
||||
uniform int RedChannel;
|
||||
uniform int GreenChannel;
|
||||
uniform int BlueChannel;
|
||||
uniform int AlphaChannel;
|
||||
|
||||
struct VertexAttributes {
|
||||
vec3 objectPosition;
|
||||
vec2 texCoord;
|
||||
|
@ -207,6 +213,8 @@ vec3 saturation(vec3 rgb, float adjustment)
|
|||
return mix(intensity, rgb, adjustment);
|
||||
}
|
||||
|
||||
float GetComponent(int Type, vec4 Texture);
|
||||
|
||||
void main()
|
||||
{
|
||||
bool RenderAsLighting = renderType == 2;
|
||||
|
@ -237,6 +245,11 @@ void main()
|
|||
if (HasDiffuse == 1)
|
||||
albedo = pow(texture(DiffuseMap , f_texcoord0).rgb, vec3(gamma));
|
||||
|
||||
//Comp Selectors
|
||||
albedo.r = GetComponent(RedChannel, texture(DiffuseMap, f_texcoord0));
|
||||
albedo.g = GetComponent(GreenChannel, texture(DiffuseMap, f_texcoord0));
|
||||
albedo.b = GetComponent(BlueChannel, texture(DiffuseMap, f_texcoord0));
|
||||
|
||||
float metallic = 0;
|
||||
if (HasMetalnessMap == 1)
|
||||
metallic = texture(MetalnessMap, f_texcoord0).r;
|
||||
|
@ -359,7 +372,7 @@ void main()
|
|||
fragColor.rgb = pow(fragColor.rgb, vec3(1 / gamma));
|
||||
|
||||
// Alpha calculations.
|
||||
float alpha = texture(DiffuseMap, f_texcoord0).a;
|
||||
float alpha = GetComponent(AlphaChannel, texture(DiffuseMap, f_texcoord0));
|
||||
fragColor.a = alpha;
|
||||
|
||||
if (RenderAsLighting)
|
||||
|
|
|
@ -54,6 +54,20 @@ vec3 SpecularPass(vec3 I, vec3 normal, int HasSpecularMap, sampler2D SpecularMap
|
|||
return result * intensity;
|
||||
}
|
||||
|
||||
float GetComponent(int Type, vec4 Texture)
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case 0: return Texture.r;
|
||||
case 1: return Texture.g;
|
||||
case 2: return Texture.b;
|
||||
case 3: return Texture.a;
|
||||
case 4: return 1;
|
||||
case 5: return 0;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 EmissionPass(sampler2D EmissionMap, float emission_intensity, VertexAttributes vert, float texCoordIndex, vec3 emission_color)
|
||||
{
|
||||
vec3 result = vec3(0);
|
||||
|
|
Loading…
Reference in a new issue