Refactor: variant-aware shader/material pipeline overhaul

Major architectural update to graphics/material/shader system:
- Introduced strongly-typed key structs (Key64/Key128) for passes, variants, and pipelines; removed legacy key types.
- Implemented robust hashing and key generation utilities for efficient variant and pipeline lookup/caching.
- Shader compiler now compiles/caches all keyword variants using new key system; includes handled as lists.
- Switched to push constant root signature for per-draw data; updated HLSL and C# codegen accordingly.
- Refactored Material, Shader, and Pass data structures for cache efficiency and variant support.
- Pipeline library and PSO management now use 128-bit keys and variant-specific caching.
- Replaced WorldNode with SceneNode in editor/scene graph; introduced ComponentManager for archetype/query management.
- Migrated math utilities to Misaki.HighPerformance.Mathematics; updated editor controls.
- Updated all HLSL and codegen for new buffer/push constant layouts and macros.
- Misc: project reference cleanup, D3D12 Work Graph support, doc updates, and code modernization.
This commit is contained in:
2026-01-09 22:25:37 +09:00
parent c9be05fc60
commit 6a041f75ba
93 changed files with 1926 additions and 1390 deletions

View File

@@ -1,31 +1,54 @@
using Misaki.HighPerformance.Mathematics;
using System.Runtime.CompilerServices;
namespace Ghost.Engine.Utilities;
public static class MathUtility
{
public const float RAD_TO_DEG = 180f / MathF.PI;
public const float DEG_TO_RAD = MathF.PI / 180f;
/// <summary>
/// Converts radians to degrees.
/// </summary>
/// <param name="radians">The angle in radians to convert.</param>
/// <returns>The angle in degrees.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float RadToDeg(float radians)
extension(float4x4 matrix)
{
return radians * RAD_TO_DEG;
}
/// <summary>
/// Creates a transformation matrix from position, rotation, and scale vectors.
/// </summary>
/// <param name="position">Defines the translation component of the transformation matrix.</param>
/// <param name="rotation">Specifies the orientation of the object in 3D space.</param>
/// <param name="scale">Determines the size of the object along each axis.</param>
/// <returns>Returns a transformation matrix that combines the specified position, rotation, and scale.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float4x4 TRS(float3 position, quaternion rotation, float3 scale)
{
var R = new float3x3(rotation);
return new float4x4(
R[0][0] * scale.x, R[0][1] * scale.y, R[0][2] * scale.z, position.x,
R[1][0] * scale.x, R[1][1] * scale.y, R[1][2] * scale.z, position.y,
R[2][0] * scale.x, R[2][1] * scale.y, R[2][2] * scale.z, position.z,
0f, 0f, 0f, 1f
);
}
/// <summary>
/// Converts degrees to radians.
/// </summary>
/// <param name="degrees">The angle in degrees to convert.</param>
/// <returns>The angle in radians.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float DegToRad(float degrees)
{
return degrees * DEG_TO_RAD;
/// <summary>
/// Gets the translation, rotation, and scale components from a transformation matrix.
/// </summary>
/// <param name="position">The position component extracted from the matrix.</param>
/// <param name="rotation">The rotation component extracted from the matrix as a quaternion.</param>
/// <param name="scale">The scale component extracted from the matrix.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void GetTRS(out float3 position, out quaternion rotation, out float3 scale)
{
position = matrix.c3.xyz;
var scaleX = math.length(matrix.c0.xyz);
var scaleY = math.length(matrix.c1.xyz);
var scaleZ = math.length(matrix.c2.xyz);
scale = new float3(scaleX, scaleY, scaleZ);
var rotationMatrix = new float3x3(
matrix.c0.x / scale.x, matrix.c0.y / scale.x, matrix.c0.z / scale.x,
matrix.c1.x / scale.y, matrix.c1.y / scale.y, matrix.c1.z / scale.y,
matrix.c2.x / scale.z, matrix.c2.y / scale.z, matrix.c2.z / scale.z
);
rotation = new quaternion(rotationMatrix);
}
}
}
}

View File

@@ -1,49 +0,0 @@
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Ghost.Engine.Utilities;
public static class MatrixUtility
{
/// <summary>
/// Generates a transformation matrix from position, rotation, and scale vectors.
/// </summary>
/// <param name="position">Defines the translation component of the transformation matrix.</param>
/// <param name="rotation">Specifies the orientation of the object in 3D space.</param>
/// <param name="scale">Determines the size of the object along each axis.</param>
/// <returns>Returns a transformation matrix that combines the specified position, rotation, and scale.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x4 CreateTRS(Vector3 position, Quaternion rotation, Vector3 scale)
{
return Matrix4x4.CreateScale(scale) * Matrix4x4.CreateFromQuaternion(rotation) * Matrix4x4.CreateTranslation(position);
}
/// <summary>
/// Decomposes a transformation matrix into its position, rotation, and scale components.
/// </summary>
/// <remarks>This method assumes the input matrix represents a valid affine transformation, including
/// translation, rotation, and scaling. If the matrix contains skew or other non-standard transformations, the
/// results may be undefined.</remarks>
/// <param name="matrix">The <see cref="Matrix4x4"/> to decompose. Must represent a valid transformation matrix.</param>
/// <param name="position">When the method returns, contains the position component extracted from the matrix.</param>
/// <param name="rotation">When the method returns, contains the rotation component extracted from the matrix as a <see
/// cref="Quaternion"/>.</param>
/// <param name="scale">When the method returns, contains the scale component extracted from the matrix.</param>
public static void GetTRS(Matrix4x4 matrix, out Vector3 position, out Quaternion rotation, out Vector3 scale)
{
position = new(matrix.M41, matrix.M42, matrix.M43);
var scaleX = new Vector3(matrix.M11, matrix.M12, matrix.M13).Length();
var scaleY = new Vector3(matrix.M21, matrix.M22, matrix.M23).Length();
var scaleZ = new Vector3(matrix.M31, matrix.M32, matrix.M33).Length();
scale = new(scaleX, scaleY, scaleZ);
Matrix4x4 rotationMatrix = new(
matrix.M11 / scale.X, matrix.M12 / scale.X, matrix.M13 / scale.X, 0,
matrix.M21 / scale.Y, matrix.M22 / scale.Y, matrix.M23 / scale.Y, 0,
matrix.M31 / scale.Z, matrix.M32 / scale.Z, matrix.M33 / scale.Z, 0,
0, 0, 0, 1);
rotation = Quaternion.CreateFromRotationMatrix(rotationMatrix);
}
}

View File

@@ -1,45 +0,0 @@
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Ghost.Engine.Utilities;
public static class VectorUtility
{
/// <summary>
/// Converts a Vector3 representing Euler angles (in degrees) to a Quaternion.
/// </summary>
/// <param name="v">The Vector3 containing Euler angles (X: Pitch, Y: Yaw, Z: Roll) in degrees.</param>
/// <returns>A Quaternion representing the rotation defined by the Euler angles.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion ToQuaternion(this Vector3 v)
{
return Quaternion.CreateFromYawPitchRoll(MathUtility.DegToRad(v.Y), MathUtility.DegToRad(v.X), MathUtility.DegToRad(v.Z));
}
public static Vector3 CreateFromQuaternion(Quaternion quaternion)
{
// Convert quaternion to Euler angles (Yaw, Pitch, Roll)
quaternion = Quaternion.Normalize(quaternion);
// Extract pitch (X), yaw (Y), roll (Z)
var ysqr = quaternion.Y * quaternion.Y;
// Pitch (X-axis rotation)
var t0 = +2.0 * (quaternion.W * quaternion.X + quaternion.Y * quaternion.Z);
var t1 = +1.0 - 2.0 * (quaternion.X * quaternion.X + ysqr);
var pitch = Math.Atan2(t0, t1);
// Yaw (Y-axis rotation)
var t2 = +2.0 * (quaternion.W * quaternion.Y - quaternion.Z * quaternion.X);
t2 = Math.Clamp(t2, -1.0, 1.0);
var yaw = Math.Asin(t2);
// Roll (Z-axis rotation)
var t3 = +2.0 * (quaternion.W * quaternion.Z + quaternion.X * quaternion.Y);
var t4 = +1.0 - 2.0 * (ysqr + quaternion.Z * quaternion.Z);
var roll = Math.Atan2(t3, t4);
const float radToDeg = 180f / MathF.PI;
return new Vector3((float)pitch, (float)yaw, (float)roll) * radToDeg;
}
}