Home Game Development directx – How should I bind various types of material data to the ray tracing rendering pipeline in DirectX12?

directx – How should I bind various types of material data to the ray tracing rendering pipeline in DirectX12?

0
directx – How should I bind various types of material data to the ray tracing rendering pipeline in DirectX12?

[ad_1]

My problem is a bit complicated. When doing ray tracing rendering, all data in the scene needs to be prepared. In addition to texture resources, each object to be rendered will also have its own material data. Because the shader codes are different, the data structures of these material data are also different. For example:

sturct S1 { float3 p1, uint p2, float p3 };
struct S2 { float2 p1, float2 p2, uint2 p3};

Assuming that all objects in the scene use the same material, then their material data structure are the same. So I can create an SRV for each material data (one material data corresponds to an ID3D12Resource), and then bind it through the Descriptor Table to the pipeline and write a declaration in HLSL:

StructuredBuffer<S1> _MaterialDatasBuffer : register(t0);

Then use the ID obtained through InstanceID() to index this S1 array buffer. It’s very simple.

But the problem is that it’s impossible for all objects in the scene to use the same material, and the data structures corresponding to different materials are different. So it seems that I can’t use a single StructuredBuffer to bind all data. But I don’t want to write a StructuredBuffer for every type of material, because I want my solution to handle arbitrary scenarios. Suppose there are 1,000 objects in the scene and 100 type of materials are used, I don’t want to create 100 descriptor table in C++ and I also don’t want to write 100 StructuredBuffers of different types in HLSL. So how should I do?

Actually I have solved this problem in Vulkan. In Vulkan, each of my material data corresponds to a VkBuffer. Then I stored the VkBuffer addresses of all the material data in the scene into an array, and bound this address array to the pipeline. Then index the address array according to the current object ID in GLSL, and after obtaining the address, use buffer_reference to obtain the data at the address. In this way, no matter how many material data types there are, you only need to declare the material data type corresponding to the current shader in glsl:

layout(buffer_reference, scalar) buffer MaterialBuffer { S1 material; };

But it seems that in D3D12 it is not possible to obtain a buffer on the GPU memory through the GPU address like Vulkan. So how can I bind a variable amount of material data which have different data structure to the pipeline?

[ad_2]