Skip to content

Commit

Permalink
Trying to simplify material transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaDesigns committed Dec 21, 2023
1 parent 8e65f41 commit 828d930
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 65 deletions.
5 changes: 3 additions & 2 deletions Charm/ActivityMapEntityView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Tiger.Schema.Activity.DESTINY2_SHADOWKEEP_2601;
using Tiger.Schema.Activity.DESTINY2_WITCHQUEEN_6307;
using Tiger.Schema.Entity;
using Tiger.Schema.Shaders;
using Tiger.Schema.Static;

namespace Charm;
Expand Down Expand Up @@ -394,7 +395,7 @@ private static void ExtractDataTables(List<FileHash> dataTables, string hash, st
foreach (DynamicMeshPart part in element.Unk60.TagData.Unk08.Load(ExportDetailLevel.MostDetailed, null))
{
if (part.Material == null) continue;
skyScene.Materials.Add(new ExportMaterial(part.Material));
skyScene.Materials.Add(new ExportMaterial(part.Material, MaterialType.Transparent));
}
}
break;
Expand All @@ -420,7 +421,7 @@ private static void ExtractDataTables(List<FileHash> dataTables, string hash, st
{
for (int i = item.StartIndex; i < item.StartIndex + item.Count && i < decals.MapDecals.TagData.Locations.Count; i++)
{
dynamicScene.Materials.Add(new ExportMaterial(item.Material));
dynamicScene.Materials.Add(new ExportMaterial(item.Material, MaterialType.Transparent));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Charm/DevView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void AddWindow(FileHash hash)
foreach (DynamicMeshPart part in parts)
{
if (part.Material == null) continue;
scene.Materials.Add(new ExportMaterial(part.Material));
scene.Materials.Add(new ExportMaterial(part.Material, MaterialType.Opaque));
}
Exporter.Get().Export();
break;
Expand Down
4 changes: 3 additions & 1 deletion Tiger/Exporters/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public void Export()
public struct ExportMaterial
{
public readonly IMaterial Material;
public readonly MaterialType Type;
public readonly bool IsTerrain;

public ExportMaterial(IMaterial material, bool isTerrain = false)
public ExportMaterial(IMaterial material, MaterialType type, bool isTerrain = false)
{
Material = material;
IsTerrain = isTerrain;
Type = type;
}

public override int GetHashCode()
Expand Down
5 changes: 2 additions & 3 deletions Tiger/Exporters/MaterialExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void Export(Exporter.ExportEventArgs args)
if (saveShaders)
{
string shaderSaveDirectory = $"{args.OutputDirectory}/{scene.Name}";
material.Material.SaveShaders(shaderSaveDirectory, material.IsTerrain);
material.Material.SaveShaders(shaderSaveDirectory, material.Type, material.IsTerrain);
material.Material.SaveVertexShader(shaderSaveDirectory);
}
}
Expand Down Expand Up @@ -94,8 +94,7 @@ public override void Export(Exporter.ExportEventArgs args)
Directory.CreateDirectory(shaderSaveDirectory);
foreach (ExportMaterial material in mapMaterials)
{
material.Material.SaveShaders(shaderSaveDirectory, material.IsTerrain);
material.Material.SaveVertexShader(shaderSaveDirectory);
material.Material.SaveShaders(shaderSaveDirectory, material.Type, material.IsTerrain);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Tiger/Exporters/Source2Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,17 @@ public static void SaveVMAT(string savePath, string hash, IMaterial materialHead
{
vmat.AppendLine($"\t\tcb0_{entry.Key} \"{entry.Value}\"");
}

vmat.AppendLine($"\t\tcb2_0 \"float4(0,1,1,1)\"");
vmat.AppendLine($"\t\tcb2_1 \"float4(0,1,1,1)\"");

vmat.AppendLine($"\t\tcb12_4 \"float4(1,0,0,0)\"");
vmat.AppendLine($"\t\tcb12_5 \"float4(0,1,0,0)\"");
vmat.AppendLine($"\t\tcb12_6 \"float4(0,0,1,0)\"");

vmat.AppendLine($"\t\tcb13_0 \"Time\"");
vmat.AppendLine($"\t\tcb13_1 \"float4(1,1,1,1)\"");

vmat.AppendLine($"\t}}");
}

Expand Down
3 changes: 2 additions & 1 deletion Tiger/Schema/Entity/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using Tiger.Exporters;
using Tiger.Schema.Shaders;

namespace Tiger.Schema.Entity;

Expand Down Expand Up @@ -90,7 +91,7 @@ public void SaveMaterialsFromParts(ExporterScene scene, List<DynamicMeshPart> dy
foreach (var dynamicPart in dynamicParts)
{
if (dynamicPart.Material == null) continue;
scene.Materials.Add(new ExportMaterial(dynamicPart.Material));
scene.Materials.Add(new ExportMaterial(dynamicPart.Material, MaterialType.Opaque));
}
}

Expand Down
13 changes: 10 additions & 3 deletions Tiger/Schema/Shaders/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public struct Output
public string Semantic;
}

public enum MaterialType
{
Opaque,
Transparent
}

public interface IMaterial : ISchema
{
public FileHash FileHash { get; }
Expand Down Expand Up @@ -124,14 +130,14 @@ public string Decompile(byte[] shaderBytecode, string name, string savePath = "h
return hlsl;
}

public void SaveShaders(string saveDirectory, bool isTerrain = false)
public void SaveShaders(string saveDirectory, MaterialType type, bool isTerrain = false)
{
Directory.CreateDirectory($"{saveDirectory}/Shaders");
if (PixelShader != null && PixelShader.Hash.IsValid())
{
string pixel = Decompile(PixelShader.GetBytecode(), $"ps{PixelShader.Hash}");
string vertex = Decompile(VertexShader.GetBytecode(), $"vs{VertexShader.Hash}");
string vfx = new S2ShaderConverter().HlslToVfx(this, pixel, vertex, isTerrain);
string vfx = new S2ShaderConverter().HlslToVfx(this, pixel, vertex, type, isTerrain);

try
{
Expand Down Expand Up @@ -178,7 +184,7 @@ public void SaveMaterial(string saveDirectory)
if (PixelShader != null)
{
Decompile(PixelShader.GetBytecode(), $"ps{PixelShader.Hash}", hlslPath);
SaveShaders($"{saveDirectory}");
SaveShaders($"{saveDirectory}", MaterialType.Opaque);
}
if (VertexShader != null)
{
Expand Down Expand Up @@ -409,3 +415,4 @@ public Material(FileHash fileHash) : base(fileHash)
// }
}
}

Loading

0 comments on commit 828d930

Please sign in to comment.