I wanna learn about DDGI implementation in URP
After placing probes, i trace some rays from each probe, when ray intersect with any geometry, i need to trace ray again from intersection point to the directional light (so i can know this point is in shadow or not)
// When this shader is called, that means ray from probe has hit geometry
[shader("closesthit")]
void ClosestHit(inout DDGIPayload payload : SV_RayPayload)
{
// I need to trace shadow ray from hit point
// In order to know if the hit point is in shadow.
bool visibility = TraceDirectionalShadowRay(mainLight, hitPosWS);
if(!visibility) return;
// If hit point is not in shadow, we can compute its radiance use Lambert Diffuse Law
// If hit point is in shadow, radiance will keep to zero.
float3 radiance = ComputeRadiance(...);
payload.radiance = radiance;
}
bool TraceShadowRay(RayDesc rayDesc)
{
RayQuery<RAY_FLAG_CULL_NON_OPAQUE | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH> q;
q.TraceRayInline(_AccelerationStructure, RAY_FLAG_NONE, 0xFF, rayDesc);
while (q.Proceed())
{
switch (q.CandidateType())
{
case CANDIDATE_NON_OPAQUE_TRIANGLE:
{
q.CommitNonOpaqueTriangleHit();
break;
}
}
}
return q.CommittedStatus() != COMMITTED_TRIANGLE_HIT;
}
bool TraceDirectionalShadowRay(Light light, float3 worldPos)
{
RayDesc rayDesc;
rayDesc.Origin = worldPos;
rayDesc.Direction = light.direction;
rayDesc.TMin = 1e-1f;
rayDesc.TMax = FLT_MAX;
return TraceShadowRay(rayDesc);
}
I found some implementations use TraceRayInline to trace shadow ray from intersection point, i tried to use the same way in Unity, but in URP (with Unity 2022.3.17f1), i got some errors:
[ Opcode AllocateRayQuery not valid in shader model lib_6_3(closesthit) ]
[ Opcode RayQuery_TraceRayInline not valid in shader model lib_6_3(closesthit) ]