yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
9ec6b9168
master
1//DISABLE_TEST:SIMPLE(filecheck=HLSL): -target hlsl -stage compute -entry computeMain -zero-initialize 2//DISABLE_TEST:SIMPLE(filecheck=GLSL): -target glsl -stage compute -entry computeMain -zero-initialize 3 4// HLSL-NOT: RayQuery{{.*}} {{.*}} = 5// GLSL-NOT: rayQueryEXT {{.*}} = 6 7uniform RaytracingAccelerationStructure scene; 8RWStructuredBuffer<float> outputBuffer; 9 10bool traceRayClosestHit( 11 float3 rayOrigin, 12 float3 rayDir, 13 out float t) 14{ 15 RayDesc ray; 16 ray.Origin = rayOrigin; 17 ray.TMin = 0.01f; 18 ray.Direction = rayDir; 19 ray.TMax = 1e4f; 20 RayQuery<RAY_FLAG_NONE> q; 21 let rayFlags = RAY_FLAG_NONE; 22 23 q.TraceRayInline( 24 scene, 25 rayFlags, 26 0xff, 27 ray); 28 29 q.Proceed(); 30 if(q.CommittedStatus() == COMMITTED_TRIANGLE_HIT) 31 { 32 t = q.CommittedRayT(); 33 return true; 34 } 35 unused(t); 36 return false; 37} 38 39[shader("compute")] 40[numthreads(1,1,1)] 41void computeMain( 42 uint3 threadIdx : SV_DispatchThreadID) 43{ 44 float t = 0.0; 45 traceRayClosestHit(float3(0.1, 0.1, 0.0), float3(0,0,1), t); 46 outputBuffer[threadIdx.x] = t; 47}