Skip to content

Commit

Permalink
Light range (?), couple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaDesigns committed Dec 22, 2023
1 parent 828d930 commit 521258d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
16 changes: 11 additions & 5 deletions Tiger/Exporters/MetadataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public MetadataScene(ExporterScene scene)
mapLight.Unk10.TagData.Unk40[i].Translation,
mapLight.Unk10.TagData.Unk40[i].Rotation,
new Vector2(1,1), //new Vector2(mapLight.Unk10.TagData.Unk30[i].UnkA0.W, mapLight.Unk10.TagData.Unk30[i].UnkB0.W), //Not right
(data.TagData.Unk40.Count > 0 ? data.TagData.Unk40[0].Vec : data.TagData.Unk60[0].Vec));
(data.TagData.Unk40.Count > 0 ? data.TagData.Unk40[0].Vec : data.TagData.Unk60[0].Vec),
mapLight.Unk10.TagData.Unk58.TagData.InstanceBounds[i].Corner2.X - mapLight.Unk10.TagData.Unk58.TagData.InstanceBounds[i].Corner1.X);
}
}
foreach(SMapDecalsResource decal in scene.Decals)
Expand Down Expand Up @@ -134,13 +135,15 @@ public MetadataScene(ExporterScene scene)
{
foreach(var entry in mapLight.Value)
{
var data = FileResourcer.Get().GetSchemaTag<D2Class_716C8080>(mapLight.Key);
AddLight(
mapLight.Key,
"Spot",
new Vector4(entry.Position.X, entry.Position.Y, entry.Position.Z, 1),
entry.Quaternion,
new Vector2(1.0, 1.0),
new Vector4(1.0,1.0,1.0,1.0));
new Vector2(1, 1),
data.TagData.UnkE8.TagData.Unk40.Count > 0 ? data.TagData.UnkE8.TagData.Unk40[0].Vec : data.TagData.UnkE8.TagData.Unk60[0].Vec);

}
}

Expand Down Expand Up @@ -240,7 +243,7 @@ public void AddCubemap(string name, Vector3 scale, Vector4 quatRotation, Vector3
});
}

public void AddLight(string name, string type, Vector4 translation, Vector4 quatRotation, Vector2 size, Vector4 color)
public void AddLight(string name, string type, Vector4 translation, Vector4 quatRotation, Vector2 size, Vector4 color, float range = 13)
{
//Idk how color/intensity is handled, so if its above 1 just bring it down
float R = color.X > 1 ? color.X / 100 : color.X;
Expand All @@ -257,7 +260,8 @@ public void AddLight(string name, string type, Vector4 translation, Vector4 quat
Translation = new[] { translation.X, translation.Y, translation.Z },
Rotation = new[] { quatRotation.X, quatRotation.Y, quatRotation.Z, quatRotation.W },
Size = new[] { size.X, size.Y },
Color = new[] { R, G, B }
Color = new[] { R, G, B },
Range = range
});
}

Expand Down Expand Up @@ -373,6 +377,8 @@ private struct JsonLight
public float[] Rotation;
public float[] Size;
public float[] Color;
public float Range;
public bool Shadowing;
}
private struct JsonDecal
{
Expand Down
5 changes: 5 additions & 0 deletions Tiger/Exporters/Source2Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ public static void SaveVMAT(string savePath, string hash, IMaterial materialHead
vmat.AppendLine($"\t\tcb2_0 \"float4(0,1,1,1)\"");
vmat.AppendLine($"\t\tcb2_1 \"float4(0,1,1,1)\"");

for(int i = 0; i < 37; i++)
{
vmat.AppendLine($"\t\tcb8_{i} \"float4(1,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)\"");
Expand Down
22 changes: 11 additions & 11 deletions Tiger/Schema/Shaders/S2ShaderConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class S2ShaderConverter
private readonly List<Output> outputs = new List<Output>();
private static bool isTerrain = false;
private bool bRT0 = true;
private static bool bTranslucent = false;
private bool bTranslucent = false;
private bool bUsesFrontFace = false;
private bool bFixRoughness = false;

Expand Down Expand Up @@ -57,7 +57,7 @@ public class S2ShaderConverter
COMMON
{{
{(bTranslucent ? $"#ifndef S_ALPHA_TEST\r\n\t#define S_ALPHA_TEST 0\r\n\t#endif\r\n\t#ifndef S_TRANSLUCENT\r\n\t#define S_TRANSLUCENT 1\r\n\t#endif" : "")}
//alpha
//frontface
#include ""common/shared.hlsl""
#define CUSTOM_MATERIAL_INPUTS
Expand Down Expand Up @@ -164,12 +164,12 @@ public string HlslToVfx(IMaterial material, string pixel, string vertex, Materia
vfxStructure = vfxStructure.Replace("//ps_Function", instructions.ToString());
vfxStructure = vfxStructure.Replace("//ps_Inputs", WriteFunctionDefinition(material, false).ToString());

//if (bOpacityEnabled) //This way is stupid but it works
//{
// bool a = bUsesNormalBuffer || bTranslucent || bUsesFrameBuffer || bUsesDepthBuffer;

// vfxStructure = vfxStructure.Replace("//alpha", $"#ifndef S_ALPHA_TEST\r\n\t#define S_ALPHA_TEST {(a ? "0" : "1")}\r\n\t#endif\r\n\t#ifndef S_TRANSLUCENT\r\n\t#define S_TRANSLUCENT {(a ? "1" : "0")}\r\n\t#endif");
//}
if (bTranslucent) //This way is stupid but it works
{
//bool a = bUsesNormalBuffer || bTranslucent || bUsesFrameBuffer || bUsesDepthBuffer;
//vfxStructure = vfxStructure.Replace("//alpha", $"#ifndef S_ALPHA_TEST\r\n\t#define S_ALPHA_TEST {(a ? "0" : "1")}\r\n\t#endif\r\n\t#ifndef S_TRANSLUCENT\r\n\t#define S_TRANSLUCENT {(a ? "1" : "0")}\r\n\t#endif");
vfxStructure = vfxStructure.Replace("//alpha", $"#ifndef S_ALPHA_TEST\r\n\t#define S_ALPHA_TEST 0\r\n\t#endif\r\n\t#ifndef S_TRANSLUCENT\r\n\t#define S_TRANSLUCENT 1\r\n\t#endif");
}

vfxStructure = vfxStructure.Replace("//ps_output", AddOutput(material).ToString());

Expand Down Expand Up @@ -564,12 +564,12 @@ private StringBuilder ConvertInstructions(IMaterial material, bool isVertexShade
funcDef.AppendLine($"\t\t{line.TrimStart()
.Replace("cb12[7].xyz", "vCameraToPositionDirWs")
.Replace("v4.xyz", "float3(0,0,0)")
.Replace("cb12[14].xyz", "-vCameraToPositionDirWs")}");
.Replace("cb12[14].xyz", "vCameraToPositionDirWs")}");
}
else if (line.Contains("cb12[12]"))
{
funcDef.AppendLine($"\t\t{line.TrimStart()
.Replace("cb12[12].zw", "g_vFrameBufferCopyInvSizeAndUvScale.xy")
.Replace("cb12[12].zw", "(1/g_vFrameBufferCopyInvSizeAndUvScale.xy)")
.Replace("cb12[12].xy", "g_vFrameBufferCopyInvSizeAndUvScale.xy")}");
}
else if (line.Contains("cb"))
Expand Down Expand Up @@ -651,7 +651,7 @@ private StringBuilder ConvertInstructions(IMaterial material, bool isVertexShade
{
case 10:
bUsesDepthBuffer = true;
funcDef.AppendLine($"\t\t{equal.TrimStart()}= Depth::Get({sampleUv}).{dotAfter} //t{texIndex}");
funcDef.AppendLine($"\t\t{equal.TrimStart()}= 1-Depth::GetNormalized({sampleUv}).{dotAfter} //t{texIndex}");
break;
case 20: //Usually uses SampleLevel but shouldnt be an issue?
bUsesFrameBuffer = true;
Expand Down
11 changes: 10 additions & 1 deletion Tiger/Schema/Static/StaticMapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,20 @@ public struct D2Class_BA6C8080
public struct SMapSpotLightResource
{
[SchemaField(0x10)]
public Tag Unk10; // D2Class_716C8080, might be related to lights for entities?
public Tag<D2Class_716C8080> Unk10; // D2Class_716C8080, might be related to lights for entities?
[SchemaField(0x1C)]
public TigerHash Unk1C;
}

[SchemaStruct(TigerStrategy.DESTINY2_WITCHQUEEN_6307, "716C8080", 0x110)]
public struct D2Class_716C8080
{
[SchemaField(0xE8, TigerStrategy.DESTINY2_WITCHQUEEN_6307)]
public Tag<D2Class_A16D8080> UnkE8;
[SchemaField(0xEC, TigerStrategy.DESTINY2_WITCHQUEEN_6307)]
public Tag<D2Class_A16D8080> UnkEC;
}

// /// <summary>
// /// Boss entity data resource?
// /// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Tiger/Schema/Static/StaticMeshData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private List<StaticPart> GenerateParts(Dictionary<int, SStaticMeshPart> staticPa
{
StaticPart part = new(staticPartEntry);
part.Material = materialMap[i];
part.MaterialType = MaterialType.Opaque;
part.GetAllData(_tag.Buffers[staticPartEntry.BufferIndex], parent);
parts.Add(part);
}
Expand Down Expand Up @@ -221,6 +222,7 @@ private List<StaticPart> GenerateParts(Dictionary<int, SStaticMeshPart> staticPa
{
StaticPart part = new StaticPart(staticPartEntry);
part.Material = materialMap[i];
part.MaterialType = MaterialType.Opaque;
part.GetAllData(mesh, parent);
parts.Add(part);
}
Expand Down
3 changes: 3 additions & 0 deletions Tiger/Schema/Static/StaticPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ public StaticPart(SStaticPart terrainPartEntry) : base()
IndexOffset = terrainPartEntry.IndexOffset;
IndexCount = terrainPartEntry.IndexCount;
PrimitiveType = PrimitiveType.TriangleStrip;
MaterialType = Shaders.MaterialType.Opaque;
}

public StaticPart(SStaticMeshPart staticPartEntry) : base()
{
IndexOffset = staticPartEntry.IndexOffset;
IndexCount = staticPartEntry.IndexCount;
PrimitiveType = (PrimitiveType)staticPartEntry.PrimitiveType;
MaterialType = Shaders.MaterialType.Opaque;
}

public StaticPart(SStaticMeshDecal decalPartEntry) : base()
{
IndexOffset = decalPartEntry.IndexOffset;
IndexCount = decalPartEntry.IndexCount;
PrimitiveType = (PrimitiveType)decalPartEntry.PrimitiveType;
MaterialType = Shaders.MaterialType.Transparent;
}

public void GetAllData(SStaticMeshBuffers buffers, SStaticMesh container)
Expand Down

0 comments on commit 521258d

Please sign in to comment.