Common.hlsl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Hit information, aka ray payload
  2. // This sample only carries a shading color and hit distance.
  3. // Note that the rayPayload 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(closesthit, anyhit, miss) : read(caller, anyhit, closesthit, miss);
  11. float distance[MAX_TRANSPACENT_HITS] : write(anyhit) : read(anyhit, closesthit);
  12. int dayLight[MAX_TRANSPACENT_HITS] : write(closesthit, anyhit, miss) : read(caller, anyhit, closesthit, miss);
  13. int dynamicLight[MAX_TRANSPACENT_HITS] : write(closesthit, anyhit, miss) : read(caller, anyhit, closesthit, miss);
  14. int 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 ChunkHitAttributes
  19. {
  20. float2 texCoord;
  21. int textureId;
  22. int dayLight;
  23. int dynamicLight;
  24. };
  25. struct SimpleBlocksAttributes
  26. {
  27. float2 bary;
  28. };
  29. struct VertexData
  30. {
  31. float2 texcoord;
  32. float3 normal;
  33. };
  34. int packLight(float3 light)
  35. {
  36. uint r = (uint) (light.r * 255.0) & 0xFF;
  37. uint g = (uint) (light.g * 255.0) & 0xFF;
  38. uint b = (uint) (light.b * 255.0) & 0xFF;
  39. return (int) ((r << 16) | (g << 8) | b);
  40. }
  41. float3 unpackLight(int light)
  42. {
  43. float r = ((light >> 16) & 0xFF) / 255.0f;
  44. float g = ((light >> 8) & 0xFF) / 255.0f;
  45. float b = (light & 0xFF) / 255.0f;
  46. return float3(r, g, b);
  47. }
  48. // Global resources
  49. Texture2D<float4> textures[] : register(t0, space1);
  50. SamplerState gSampler : register(s0, space0);
  51. cbuffer DX12ShaderLightInfo : register(b0, space1)
  52. {
  53. float3 dayLightFactor;
  54. uint padding;
  55. float3 dayLightDirection;
  56. };
  57. // Raytracing acceleration structure, accessed as a SRV
  58. RaytracingAccelerationStructure TLAS : register(t0, space0);
  59. RWTexture2D<float4> gOutput : register(u0);
  60. RWTexture2D<float4> guiTexture : register(u1);
  61. cbuffer RayGenerationSettings : register(b0, space0)
  62. {
  63. int renderGui;
  64. int useRays;
  65. float minDistance;
  66. float maxDistance;
  67. float4x4 inverseView;
  68. float4x4 inverseProjection;
  69. };