Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/010 Templates/pssg.bt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct NODE {
case "SHADERINPUT":
case "TEXTUREIMAGEBLOCKDATA":
case "TRANSFORM":
case "SHADERPROGRAMCODEBLOCK":
char data[end - FTell()] <bgcolor=cRed>;
break;
default:
Expand Down
46 changes: 30 additions & 16 deletions src/EgoEngineLibrary/Formats/Pssg/RenderDataSourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public Vector3 GetNormal(uint index)
return ReadVector3(data);
case "half4": // just read Vec3, pretty sure 4th item is just 1.0
return ReadVectorHalf3(data);
case "hend3n":
return ReadHend3N(data);
default:
throw new NotImplementedException($"Support for {attribute.Name} data type {attribute.DataType} is not implemented.");
}
Expand All @@ -256,6 +258,8 @@ public Vector4 GetTangent(uint index)
return ReadVectorHalf4(data);
case "float3":
return new Vector4(ReadVector3(data), 0);
case "hend3n":
return new Vector4(ReadHend3N(data), 0);
default:
throw new NotImplementedException($"Support for {attribute.Name} data type {attribute.DataType} is not implemented.");
}
Expand All @@ -281,6 +285,8 @@ public Vector4 GetBinormal(uint index)
return ReadVectorHalf4(data);
case "float3":
return new Vector4(ReadVector3(data), 0);
case "hend3n":
return new Vector4(ReadHend3N(data), 0);
default:
throw new NotImplementedException($"Support for {attribute.Name} data type {attribute.DataType} is not implemented.");
}
Expand Down Expand Up @@ -378,37 +384,45 @@ private static Vector2 ReadVector2(ReadOnlySpan<byte> data)
private static Vector4 ReadVectorHalf4(ReadOnlySpan<byte> data)
{
var vec = new Vector4();
vec.X = (float)BigToHalf(data);
vec.Y = (float)BigToHalf(data.Slice(2));
vec.Z = (float)BigToHalf(data.Slice(4));
vec.W = (float)BigToHalf(data.Slice(6));
vec.X = (float)BinaryPrimitives.ReadHalfBigEndian(data);
vec.Y = (float)BinaryPrimitives.ReadHalfBigEndian(data[2..]);
vec.Z = (float)BinaryPrimitives.ReadHalfBigEndian(data[4..]);
vec.W = (float)BinaryPrimitives.ReadHalfBigEndian(data[6..]);
return vec;
}

private static Vector3 ReadVectorHalf3(ReadOnlySpan<byte> data)
{
var vec = new Vector3();
vec.X = (float)BigToHalf(data);
vec.Y = (float)BigToHalf(data.Slice(2));
vec.Z = (float)BigToHalf(data.Slice(4));
vec.X = (float)BinaryPrimitives.ReadHalfBigEndian(data);
vec.Y = (float)BinaryPrimitives.ReadHalfBigEndian(data[2..]);
vec.Z = (float)BinaryPrimitives.ReadHalfBigEndian(data[4..]);
return vec;
}

private static Vector2 ReadVectorHalf2(ReadOnlySpan<byte> data)
{
var vec = new Vector2();
vec.X = (float)BigToHalf(data);
vec.Y = (float)BigToHalf(data.Slice(2));
vec.X = (float)BinaryPrimitives.ReadHalfBigEndian(data);
vec.Y = (float)BinaryPrimitives.ReadHalfBigEndian(data[2..]);
return vec;
}

static Half BigToHalf(ReadOnlySpan<byte> source)
{
return Int16BitsToHalf(BinaryPrimitives.ReadInt16BigEndian(source));
}
static unsafe Half Int16BitsToHalf(short value)

private static Vector3 ReadHend3N(ReadOnlySpan<byte> data)
{
return *(Half*)&value;
// 11 11 10 bit signed values
var i = BinaryPrimitives.ReadUInt32BigEndian(data);
var y = i >> 11;
var z = i >> 22;

// use shift to sign extend
var vec = new Vector3
{
X = (((int)(i & 0x7FF)) << 21 >> 21) / (float)0x3FF,
Y = (((int)(y & 0x7FF)) << 21 >> 21) / (float)0x3FF,
Z = (((int)(z & 0x3FF)) << 22 >> 22) / (float)0x1FF
};
return vec;
}
}
}
35 changes: 23 additions & 12 deletions src/EgoEngineLibrary/Formats/Pssg/RenderDataSourceWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ private void WriteNormal(ShaderVertexInputInfo vi, uint elementIndex, Span<byte>
case "half4":
WriteVectorHalf4(destination, new Vector4(value, 1));
break;
case "hend3n":
WriteHend3N(destination, value);
break;
default:
throw new NotImplementedException($"Support for {vi.Name} data type {vi.DataType} is not implemented.");
}
Expand All @@ -262,6 +265,9 @@ private void WriteTangent(ShaderVertexInputInfo vi, uint elementIndex, Span<byte
case "float3":
WriteVector3(destination, new Vector3(value.X, value.Y, value.Z));
break;
case "hend3n":
WriteHend3N(destination, value.AsVector3());
break;
default:
throw new NotImplementedException($"Support for {vi.Name} data type {vi.DataType} is not implemented.");
}
Expand All @@ -282,6 +288,9 @@ private void WriteBinormal(ShaderVertexInputInfo vi, uint elementIndex, Span<byt
case "float3":
WriteVector3(destination, new Vector3(value.X, value.Y, value.Z));
break;
case "hend3n":
WriteHend3N(destination, value.AsVector3());
break;
default:
throw new NotImplementedException($"Support for {vi.Name} data type {vi.DataType} is not implemented.");
}
Expand Down Expand Up @@ -377,25 +386,27 @@ private static void WriteVector2(Span<byte> destination, Vector2 value)

private static void WriteVectorHalf2(Span<byte> destination, Vector2 value)
{
WriteHalfBigEndian(destination, (Half)value.X);
WriteHalfBigEndian(destination.Slice(2), (Half)value.Y);
BinaryPrimitives.WriteHalfBigEndian(destination, (Half)value.X);
BinaryPrimitives.WriteHalfBigEndian(destination.Slice(2), (Half)value.Y);
}

private static void WriteVectorHalf4(Span<byte> destination, Vector4 value)
{
WriteHalfBigEndian(destination, (Half)value.X);
WriteHalfBigEndian(destination.Slice(2), (Half)value.Y);
WriteHalfBigEndian(destination.Slice(4), (Half)value.Z);
WriteHalfBigEndian(destination.Slice(6), (Half)value.W);
BinaryPrimitives.WriteHalfBigEndian(destination, (Half)value.X);
BinaryPrimitives.WriteHalfBigEndian(destination.Slice(2), (Half)value.Y);
BinaryPrimitives.WriteHalfBigEndian(destination.Slice(4), (Half)value.Z);
BinaryPrimitives.WriteHalfBigEndian(destination.Slice(6), (Half)value.W);
}

private static void WriteHalfBigEndian(Span<byte> destination, Half value)
{
BinaryPrimitives.WriteInt16BigEndian(destination, HalfToInt16Bits(value));
}
private static unsafe short HalfToInt16Bits(Half value)
private static void WriteHend3N(Span<byte> destination, Vector3 value)
{
return *(short*)&value;
// 11 11 10 bit signed values
// Shift up to capture sign bit, then unsigned shift back
var x = ((int)(float.Clamp(value.X, -1, 1) * 0x3FF)) << 21 >>> 21;
var y = ((int)(float.Clamp(value.Y, -1, 1) * 0x3FF)) << 21 >>> 21;
var z = ((int)(float.Clamp(value.Z, -1, 1) * 0x1FF)) << 22 >>> 22;
uint val = (uint)x | ((uint)y << 11) | ((uint)z << 22);
BinaryPrimitives.WriteUInt32BigEndian(destination, val);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PssgShaderProgramCode : PssgElement
new PssgSchemaAttribute("codeType", PssgAttributeType.String),
new PssgSchemaAttribute("profileType", PssgAttributeType.Int),
new PssgSchemaAttribute("profile", PssgAttributeType.Int),
new PssgSchemaAttribute("codeEntry", PssgAttributeType.Int),
new PssgSchemaAttribute("codeEntry", PssgAttributeType.String),
new PssgSchemaAttribute("parameterCount", PssgAttributeType.Int),
new PssgSchemaAttribute("streamCount", PssgAttributeType.Int),
}
Expand Down Expand Up @@ -41,9 +41,9 @@ public uint Profile
set => AddAttribute(Schema.Attributes[3].Name, value);
}

public byte CodeEntry
public string CodeEntry
{
get => GetAttributeValue<byte>(Schema.Attributes[4].Name);
get => GetAttributeValue<string>(Schema.Attributes[4].Name);
set => AddAttribute(Schema.Attributes[4].Name, value);
}

Expand Down
6 changes: 2 additions & 4 deletions src/EgoEngineLibrary/Graphics/Pssg/PssgBinaryReader.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System.Numerics;
using System.Text;
using EgoEngineLibrary.Collections;
using EgoEngineLibrary.Conversion;
using EgoEngineLibrary.IO;

namespace EgoEngineLibrary.Graphics.Pssg
{
public class PssgBinaryReader : EndianBinaryReader
{
public OrderedSet<PssgSchemaElement> ElementTable { get; set; }
public OrderedSet<PssgSchemaAttribute> AttributeTable { get; set; }
public List<PssgSchemaElement> ElementTable { get; set; }
public List<PssgSchemaAttribute> AttributeTable { get; set; }
internal bool UseDataElementCheck { get; set; }

public PssgBinaryReader(EndianBitConverter bitConvertor, Stream stream, bool leaveOpen)
Expand Down
4 changes: 2 additions & 2 deletions src/EgoEngineLibrary/Graphics/Pssg/PssgFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public static PssgFile ReadPssg(Stream fileStream, PssgFileType fileType)
}
}

file._elementTable = reader.ElementTable;
file._attributeTable = reader.AttributeTable;
file._elementTable = new OrderedSet<PssgSchemaElement>(reader.ElementTable);
file._attributeTable = new OrderedSet<PssgSchemaAttribute>(reader.AttributeTable);
}

return file;
Expand Down
7 changes: 7 additions & 0 deletions src/EgoPssgEditor/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
<Application.Styles>
<FluentTheme DensityStyle="Compact" />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
<Style Selector="DataGridCell">
<Setter Property="FontSize" Value="14"></Setter>
<Setter Property="MinHeight" Value="26"></Setter>
</Style>
<Style Selector="TabItem">
<Setter Property="FontSize" Value="20"></Setter>
</Style>
<!-- See https://github.com/AvaloniaUI/Avalonia/issues/20530 -->
<Style Selector="TreeViewItem /template/ StackPanel > Border > Grid">
<Setter Property="HorizontalAlignment" Value="Left"></Setter>
Expand Down
6 changes: 3 additions & 3 deletions src/EgoPssgEditor/EgoPssgEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<AssemblyName>Ego PSSG Editor</AssemblyName>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<PublishTrimmed>true</PublishTrimmed>
<PublishSelfContained>true</PublishSelfContained>
</PropertyGroup>

<PropertyGroup>
<ApplicationIcon>Assets\Ryder25.ico</ApplicationIcon>
<Copyright>Copyright © Petar Tasev 2010 - 2024</Copyright>
<Authors>Petar Tasev</Authors>
<Company>Petar Tasev</Company>
<Description>Opens Ego Engine pssg files</Description>
<Version>12.1.1</Version>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/EgoPssgEditor/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<DataGrid x:Name="attributesDataGrid"
ItemsSource="{Binding ElementName=tvMain, Path=((vm:PssgElementViewModel)SelectedItem).Attributes}"
AutoGenerateColumns="False" CanUserSortColumns="False"
HeadersVisibility="All" RowHeight="20" FontSize="14"
HeadersVisibility="All"
CellPointerPressed="AttributesDataGrid_OnCellPointerPressed">
<DataGrid.Styles>
<Style Selector="DataGridRow" x:DataType="vm:PssgAttributeViewModel">
Expand Down