I have a Custom Raytracing Shader and inside im attempting to initialize a Struct, But not matter what i try, D3D Keeps Crashing. I dont know how to Read Shader Debug Logs, so I sent the log into ChatGPT where i got a response saying that there is a problem with Improper memory layout or alignment during Initialization
Here is the Struct inside my shader:
FMaterialClosestHitPayload Payload = {
0.0, // HitT (from FMinimalPayload)
{ 0.1, 0.05 }, // RayCone (Width, SpreadAngle)
float3(0.0, 0.0, 0.0), // Radiance
float3(0.0, 0.0, 1.0), // WorldNormal
float3(1.0, 1.0, 1.0), // BaseColor
float3(0.0, 0.0, 0.0), // DiffuseColor
float3(0.0, 0.0, 0.0), // SpecularColor
1.0, // Opacity
0.5, // Metallic
0.5, // Specular
0.5, // Roughness
1.5, // Ior
0, // ShadingModelID
0, // BlendingMode
0, // PrimitiveLightingChannelMask
float4(0.0, 0.0, 0.0, 0.0), // CustomData
0.0, // GBufferAO
float3(0.0, 0.0, 0.0), // IndirectIrradiance
float3(0.0, 0.0, 0.0), // TranslatedWorldPos
0u, // Flags
float3(1.0, 0.0, 0.0), // WorldTangent
0.0 // Anisotropy
};
And here is the Struct in the Source Code (RayTracingCommon.ush Ln.675)
struct FMaterialClosestHitPayload : FMinimalPayload
{
// Unpacked Packed
// offset bytes
// float FMinimalPayload::HitT // 0 4 32bits
FRayCone RayCone; // 4 8 64bits
float3 Radiance; // 8 6 48bits
float3 WorldNormal; // 24 6 48bits
float3 BaseColor; // 36 6 48bits
float3 DiffuseColor; // 48 0 (derived)
float3 SpecularColor; // 60 0 (derived)
float Opacity; // 72 2 16bits
float Metallic; // 76 1 8bits
float Specular; // 80 1 8bits
float Roughness; // 84 2 16bits
float Ior; // 88 2 16bits
uint ShadingModelID; // 92 1 4bits
uint BlendingMode; // 96 0 3bits (packed with ShadingModelID)
uint PrimitiveLightingChannelMask; // 100 0 3bits (packed with ShadingModelID)
float4 CustomData; // 104 4 32bits
float GBufferAO; // 120 0 (removed)
float3 IndirectIrradiance; // 124 0 48bits – gbuffer only has float payload and there are truncation HLSL warnings// Quite some code assume FRayHitInfo has a WorldPos
// So keep it here and force to re-construct it in Unpack call using ray information.
// It is not packed in FRayHitInfoPacked
float3 TranslatedWorldPos; // 136 0 (derived)
uint Flags; // 148 0 6bits (packed with ShadingModelID)
float3 WorldTangent; // 152 6 48bits
float Anisotropy; // 164 2 16bits (packed with WorldTangent)
// 166 totalvoid SetFrontFace() { Flags |= RAY_TRACING_PAYLOAD_OUTPUT_FLAG_FRONT_FACE; }
bool IsFrontFace() { return (Flags & RAY_TRACING_PAYLOAD_OUTPUT_FLAG_FRONT_FACE) != 0; }void SetTwoSided() { Flags |= RAY_TRACING_PAYLOAD_OUTPUT_FLAG_TWO_SIDED; }
bool IsTwoSided() { return (Flags & RAY_TRACING_PAYLOAD_OUTPUT_FLAG_TWO_SIDED) != 0; }FRayCone GetRayCone() { return RayCone; }
void SetRayCone(FRayCone NewRayCone) { RayCone = NewRayCone; }bool HasAnisotropy() { return abs(Anisotropy) >= 0.001f; }
float3 GetRayDirection() { return IndirectIrradiance; /* Alias IndirectIrradiance/RayDirection */ }
};
I am doing it Correctly?
How i can fix it?