.
DXR1.1: Getting started with RayQuery
Reference code :
https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl
Couldn't spot any minimal DXR 1.1 RayQuery sample code that compiled, so here's one.
// File: query.hlsl : minimal DXR1.1 ray query sample code.
// To compile : dxc query.hlsl -T ps_6_5 -E Composite_Pixel
// Initialized from bottom & top level acceleration structures in parent dx12 app.
RaytracingAccelerationStructure __scene : register(t0, space0);
float4 Composite_Pixel() : SV_Target
{
// a. Configure
RayQuery<RAY_FLAG_CULL_NON_OPAQUE|RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES|RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH> query;
uint ray_flags = 0; // Any this ray requires in addition those above.
uint ray_instance_mask = 0xffffffff;
// b. Initialize - hardwired here to deliver minimal sample code.
RayDesc ray;
ray.TMin = 1e-5f;
ray.TMax = 1e10f;
ray.Origin = float3(0,0,0);
ray.Direction = float3(0,0,1);
query.TraceRayInline( __scene, ray_flags, ray_instance_mask, ray);
// c. Cast
// Proceed() is where behind-the-scenes traversal happens, including the heaviest of any driver inlined code.
// In this simplest of scenarios, Proceed() only needs to be called once rather than a loop.
// Based on the template specialization above, traversal completion is guaranteed.
query.Proceed();
// d. Examine and act on the result of the traversal.
if (query.CommittedStatus() == COMMITTED_TRIANGLE_HIT)
{
// TODO: Grab ray parameters & sample accordingly.
/* ShadeMyTriangleHit(
query.CommittedInstanceIndex(),
query.CommittedPrimitiveIndex(),
query.CommittedGeometryIndex(),
query.CommittedRayT(),
query.CommittedTriangleBarycentrics(),
query.CommittedTriangleFrontFace() );*/
return float4(0,1,0,1);
}
else
{
// COMMITTED_NOTHING. From template specialization above, COMMITTED_PROCEDURAL_PRIMITIVE can't happen so no need to check for that.
// Miss shading - sample the environment.
// Environment_Sample(query.WorldRayOrigin(), query.WorldRayDirection());
return float4(0,0,1,1);
}
return float4(1,0,0,1);
}
query.Proceed() is interesting syntax - its effectively C++.
Can we do that now in hlsl or is its use limited to hardwired built ins ?
Link to docs regarding enhanced hlsl language syntax welcome & appreciated.
that syntax has been around for sometimes now, remember this?:
Texture2D your_texture;
SamplerState your_texture_sampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
float4 main_ps(...)..
{
Output.RGBColor = your_texture.Sample(your_texture_sampler, In.TextureUV) * In.Diffuse;
...
if u type “hlsl development cookbook” on Amazon, u'll reach ?
Have fun ?
Yes, you can write you own methods for structs in HLSL if you prefer to do things that way.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement