ChunkClosestHit.hlsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "Common.hlsl"
  2. [shader("closesthit")]
  3. void ChunkClosestHit(inout RayHits currentPayload, ChunkHitAttributes attrib)
  4. {
  5. if (currentPayload.hitCount == 0)
  6. {
  7. return; // already inside of shadow ray
  8. }
  9. RayHits 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.hits[i].distance - 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. float normalFactor = saturate(dot(normalize(currentPayload.hits[i].normal), normalize(dayLightDirection)));
  23. float3 color = unpackLight(currentPayload.hits[i].dayLight) * dayLightFactor;
  24. if (tmpPayload.hitCount == 0)
  25. {
  26. color = color / 2;
  27. }
  28. else
  29. {
  30. color = color * (0.5 + normalFactor / 2);
  31. }
  32. currentPayload.hits[i].dayLight = packLight(color);
  33. }
  34. // TODO: reflection rays
  35. }