ChunkClosestHit.hlsl 937 B

12345678910111213141516171819202122232425262728293031
  1. #include "Common.hlsl"
  2. [shader("closesthit")]
  3. void ChunkClosestHit(inout HitInfo currentPayload, ChunkHitAttributes attrib)
  4. {
  5. if (currentPayload.hitCount == 0)
  6. {
  7. return; // already inside of shadow ray
  8. }
  9. HitInfo tmpPayload;
  10. // shadow rays
  11. for (int i = 0; i < currentPayload.hitCount; i++)
  12. {
  13. tmpPayload.hitCount = -1; // shadow ray
  14. RayDesc ray;
  15. ray.Origin = WorldRayOrigin() + (currentPayload.distance[i] - 0.001) * WorldRayDirection();
  16. ray.Direction = dayLightDirection;
  17. ray.TMin = 0.00001;
  18. ray.TMax = 1000;
  19. TraceRay(TLAS,
  20. 0, 0xFF, 0,
  21. 0, 0, ray, tmpPayload);
  22. float3 color = unpackLight(currentPayload.dayLight[i]) * dayLightFactor;
  23. if (tmpPayload.hitCount == 0)
  24. {
  25. color = color / 2;
  26. }
  27. currentPayload.dayLight[i] = packLight(color);
  28. }
  29. // TODO: reflection rays
  30. }