Community Tutorial: How to Create a Custom Ray Tracing Shader as a Plugin

Thank you for your reply!
I noticed that there are some ClosestHit shaders in RayTracingMaterialDefaultHitShaders.usf, but none of them seem to read material information.

After exploring the UE source code, I believe the key to enabling a custom ClosestHit shader to read material data might lie in RayTracingMaterialHitShaders.usf and RayTracingMaterialHitShaders.cpp, particularly in the MaterialCHS function:

RAY_TRACING_ENTRY_CLOSEST_HIT(MaterialCHS,
    FPackedMaterialClosestHitPayload, PackedPayload,
    FRayTracingIntersectionAttributes, Attributes)
{
    PackedPayload.HitT = RayTCurrent();
    ......
    // Fill payload with material data
    GetMaterialPayload(PixelMaterialInputs, MaterialParameters, Interpolants, PackedPayload.IsEnableSkyLightContribution(), Payload); 
    ......
}

However, I’m not quite sure how to proceed from here. I appreciate the link you shared—it seems like it involves modifications and customization of this part as well. I’ll take a closer look and study the code carefully.

1 Like