SimpleBlocksClosestHit.hlsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "Common.hlsl"
  2. StructuredBuffer<int> textureIdBuffer : register(t1, space2);
  3. StructuredBuffer<int> indexBuffer : register(t1, space3);
  4. StructuredBuffer<VertexData> vertexData : register(t1, space4);
  5. StructuredBuffer<int> indexOffsetBuffer : register(t1, space5);
  6. [shader("closesthit")]
  7. void SimpleBlocksClosestHit(inout RayHits currentPayload, SimpleBlocksAttributes attrib)
  8. {
  9. if (currentPayload.hitCount == 0)
  10. {
  11. return; // already inside of shadow ray
  12. }
  13. RayHits tmpPayload;
  14. // shadow rays
  15. for (int i = 0; i < currentPayload.hitCount; i++)
  16. {
  17. tmpPayload.hitCount = -1; // shadow ray
  18. RayDesc ray;
  19. ray.Origin = WorldRayOrigin() + (currentPayload.hits[i].distance - 0.001) * WorldRayDirection();
  20. ray.Direction = dayLightDirection;
  21. ray.TMin = 0.00001;
  22. ray.TMax = 1000;
  23. TraceRay(TLAS,
  24. 0, 0xFF, 0,
  25. 0, 0, ray, tmpPayload);
  26. float normalFactor = saturate(dot(normalize(currentPayload.hits[i].normal), normalize(dayLightDirection)));
  27. float3 color = unpackLight(currentPayload.hits[i].dayLight) * dayLightFactor;
  28. if (tmpPayload.hitCount == 0)
  29. {
  30. color = color / 2;
  31. }
  32. else
  33. {
  34. color = dayLightFactor * (0.5 + normalFactor / 2);
  35. }
  36. currentPayload.hits[i].dayLight = packLight(color);
  37. }
  38. // TODO: reflection rays
  39. }