Common.hlsl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Hit information, aka ray payload
  2. // This sample only carries a shading color and hit distance.
  3. // Note that the payload should be kept as small as possible,
  4. // and that its size must be declared in the corresponding
  5. // D3D12_RAYTRACING_SHADER_CONFIG pipeline subobjet.
  6. #pragma pack_matrix(row_major)
  7. #define MAX_TRANSPACENT_HITS 5
  8. struct [raypayload] HitInfo
  9. {
  10. float4 color[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit, miss) : read(caller, anyhit, closesthit, miss);
  11. float distance[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit) : read(caller, anyhit, closesthit);
  12. int dayLight[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit) : read(caller, anyhit, closesthit);
  13. int dynamicLight[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit) : read(caller, anyhit, closesthit);
  14. uint hitCount : write(caller, anyhit, closesthit, miss) : read(caller, anyhit, closesthit, miss);
  15. };
  16. // Attributes output by the raytracing when hitting a surface,
  17. // here the barycentric coordinates
  18. struct Attributes
  19. {
  20. float2 texCoord;
  21. int textureId;
  22. int dayLight;
  23. int dynamicLight;
  24. };
  25. struct SimpleBlocksAttributes
  26. {
  27. float2 bary;
  28. };
  29. uint packLight(float3 light)
  30. {
  31. uint r = (uint) (light.r * 255.0) & 0xFF;
  32. uint g = (uint) (light.g * 255.0) & 0xFF;
  33. uint b = (uint) (light.b * 255.0) & 0xFF;
  34. return (r << 16) | (g << 8) | b;
  35. }
  36. float3 unpackLight(int light)
  37. {
  38. float r = ((light >> 16) & 0xFF) / 255.0f;
  39. float g = ((light >> 8) & 0xFF) / 255.0f;
  40. float b = (light & 0xFF) / 255.0f;
  41. return float3(r, g, b);
  42. }