mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-09-20 22:42:05 +00:00
More material improvements
This commit is contained in:
parent
e0b8ca5e27
commit
11ebded46b
4 changed files with 101 additions and 3 deletions
Binary file not shown.
|
@ -1220,6 +1220,8 @@ namespace FirstPlugin
|
|||
//https://github.com/magcius/noclip.website/blob/9270b9e5022c691703689990f9c536cd9058e5cd/src/oot3d/cmb.ts#L232
|
||||
public class Material
|
||||
{
|
||||
public bool IsTransparent = false;
|
||||
|
||||
public CullMode CullMode;
|
||||
|
||||
public bool IsPolygonOffsetEnabled;
|
||||
|
@ -1243,6 +1245,19 @@ namespace FirstPlugin
|
|||
|
||||
public DepthFunction DepthTestFunction;
|
||||
|
||||
public bool BlendEnaled;
|
||||
|
||||
public BlendingFactor BlendingFactorSrcRGB;
|
||||
public BlendingFactor BlendingFactorDestRGB;
|
||||
|
||||
public BlendingFactor BlendingFactorSrcAlpha;
|
||||
public BlendingFactor BlendingFactorDestAlpha;
|
||||
|
||||
public float BlendColorR;
|
||||
public float BlendColorG;
|
||||
public float BlendColorB;
|
||||
public float BlendColorA;
|
||||
|
||||
public void Read(FileReader reader, Header header, MaterialChunk materialChunkParent)
|
||||
{
|
||||
TextureMaps = new TextureMap[3];
|
||||
|
@ -1362,11 +1377,46 @@ namespace FirstPlugin
|
|||
reader.SeekBegin(pos + 0x130);
|
||||
AlphaTestEnable = reader.ReadBoolean();
|
||||
AlphaTestReference = reader.ReadByte() / 255.0f;
|
||||
AlphaTestFunction = reader.ReadEnum<AlphaFunction>(false);
|
||||
AlphaTestFunction = (AlphaFunction)reader.ReadUInt16();
|
||||
|
||||
DepthTestEnable = reader.ReadBoolean();
|
||||
DepthWriteEnable = reader.ReadBoolean();
|
||||
DepthTestFunction = reader.ReadEnum<DepthFunction>(false);
|
||||
DepthTestFunction = (DepthFunction)reader.ReadUInt16();
|
||||
|
||||
if (!AlphaTestEnable)
|
||||
AlphaTestFunction = AlphaFunction.Always;
|
||||
|
||||
if (!DepthTestEnable)
|
||||
DepthTestFunction = DepthFunction.Always;
|
||||
|
||||
reader.SeekBegin(pos + 0x138);
|
||||
BlendEnaled = reader.ReadBoolean();
|
||||
Console.WriteLine("BlendEnaled " + BlendEnaled);
|
||||
|
||||
//Unknown.
|
||||
reader.ReadByte();
|
||||
reader.ReadUInt16();
|
||||
|
||||
reader.SeekBegin(pos + 0x13C);
|
||||
|
||||
BlendingFactorSrcRGB = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorDestRGB = (BlendingFactor)reader.ReadUInt16();
|
||||
|
||||
reader.SeekBegin(pos + 0x144);
|
||||
|
||||
BlendingFactorSrcAlpha = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorDestAlpha = (BlendingFactor)reader.ReadUInt16();
|
||||
|
||||
// BlendingFunctionAlpha = (AlphaFunction)reader.ReadUInt16();
|
||||
|
||||
reader.SeekBegin(pos + 0x14C);
|
||||
|
||||
BlendColorR = reader.ReadSingle();
|
||||
BlendColorG = reader.ReadSingle();
|
||||
BlendColorB = reader.ReadSingle();
|
||||
BlendColorA = reader.ReadSingle();
|
||||
|
||||
IsTransparent = BlendEnaled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,15 +9,47 @@ using GL_EditorFramework.Interfaces;
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using Toolbox.Library;
|
||||
using Grezzo.CmbEnums;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
//Rendering methods based on noclip
|
||||
//https://github.com/magcius/noclip.website/blob/master/src/oot3d/render.ts
|
||||
public class CMB_Renderer : GenericModelRenderer
|
||||
{
|
||||
public override float PreviewScale { get; set; } = 0.01f;
|
||||
|
||||
public List<CTXB.TextureWrapper> TextureList = new List<CTXB.TextureWrapper>();
|
||||
|
||||
private string FragmentShader()
|
||||
{
|
||||
string frag = "";
|
||||
return frag;
|
||||
}
|
||||
|
||||
private string GenerateAlphaTestCompare(AlphaFunction compare, int reference)
|
||||
{
|
||||
float refSingle = (float)reference;
|
||||
switch (compare)
|
||||
{
|
||||
case AlphaFunction.Never: return "false";
|
||||
case AlphaFunction.Less: return $"t_CmbOut.a < {refSingle}";
|
||||
case AlphaFunction.Lequal: return $"t_CmbOut.a <= {refSingle}";
|
||||
case AlphaFunction.Equal: return $"t_CmbOut.a == {refSingle}";
|
||||
case AlphaFunction.Notequal: return $"t_CmbOut.a != {refSingle}";
|
||||
case AlphaFunction.Greater: return $"t_CmbOut.a > ${refSingle}";
|
||||
case AlphaFunction.Gequal: return $"t_CmbOut.a >= ${refSingle}";
|
||||
case AlphaFunction.Always: return "true";
|
||||
default: throw new Exception("Unsupported alpha function");
|
||||
}
|
||||
}
|
||||
|
||||
private string GenerateTextureEnvironment()
|
||||
{
|
||||
string vale = $"";
|
||||
return vale;
|
||||
}
|
||||
|
||||
public override void OnRender(GLControl control)
|
||||
{
|
||||
|
||||
|
@ -27,8 +59,17 @@ namespace FirstPlugin
|
|||
{
|
||||
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).Material;
|
||||
|
||||
shader.SetBoolToInt("isTransparent", cmbMaterial.IsTransparent);
|
||||
|
||||
//shader.SetBoolToInt("isTransparent", cmbMaterial.isTransparent);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(cmbMaterial.BlendingFactorSrcAlpha, cmbMaterial.BlendingFactorDestAlpha);
|
||||
GL.BlendColor(cmbMaterial.BlendColorR, cmbMaterial.BlendColorG, cmbMaterial.BlendColorB, cmbMaterial.BlendColorA);
|
||||
if (cmbMaterial.AlphaTestEnable)
|
||||
GL.Enable(EnableCap.AlphaTest);
|
||||
else
|
||||
GL.Disable(EnableCap.AlphaTest);
|
||||
|
||||
GL.AlphaFunc(cmbMaterial.AlphaTestFunction, cmbMaterial.AlphaTestReference);
|
||||
}
|
||||
|
||||
public override int BindTexture(STGenericMatTexture tex, ShaderProgram shader)
|
||||
|
|
|
@ -117,6 +117,7 @@ void main()
|
|||
}
|
||||
|
||||
vec3 albedo = vec3(0.5);
|
||||
float alpha = 1.0f;
|
||||
if (HasDiffuse == 1)
|
||||
{
|
||||
vec4 DiffuseTex = pow(texture(DiffuseMap, f_texcoord0).rgba, vec4(gamma));
|
||||
|
@ -125,6 +126,7 @@ void main()
|
|||
albedo.r = GetComponent(RedChannel, DiffuseTex);
|
||||
albedo.g = GetComponent(GreenChannel, DiffuseTex);
|
||||
albedo.b = GetComponent(BlueChannel, DiffuseTex);
|
||||
alpha = GetComponent(AlphaChannel, DiffuseTex);
|
||||
}
|
||||
|
||||
// Diffuse lighting.
|
||||
|
@ -140,6 +142,11 @@ void main()
|
|||
// Global brightness adjustment.
|
||||
// fragColor.rgb *= 1.5;
|
||||
|
||||
if (isTransparent == 1)
|
||||
{
|
||||
fragColor.a = alpha;
|
||||
}
|
||||
|
||||
//Debug Shading
|
||||
vec2 displayTexCoord = f_texcoord0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue