| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- // Hit information, aka ray payload
- // This sample only carries a shading color and hit distance.
- // Note that the payload should be kept as small as possible,
- // and that its size must be declared in the corresponding
- // D3D12_RAYTRACING_SHADER_CONFIG pipeline subobjet.
- #pragma pack_matrix(row_major)
- #define MAX_TRANSPACENT_HITS 5
- struct [raypayload] HitInfo
- {
- float4 color[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit, miss) : read(caller, anyhit, closesthit, miss);
- float distance[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit) : read(caller, anyhit, closesthit);
- int dayLight[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit, miss) : read(caller, anyhit, closesthit);
- int dynamicLight[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit, miss) : read(caller, anyhit, closesthit);
- uint hitCount : write(caller, anyhit, closesthit, miss) : read(caller, anyhit, closesthit, miss);
- };
- // Attributes output by the raytracing when hitting a surface,
- // here the barycentric coordinates
- struct ChunkHitAttributes
- {
- float2 texCoord;
- int textureId;
- int dayLight;
- int dynamicLight;
- };
- struct SimpleBlocksAttributes
- {
- float2 bary;
- };
- uint packLight(float3 light)
- {
- uint r = (uint) (light.r * 255.0) & 0xFF;
- uint g = (uint) (light.g * 255.0) & 0xFF;
- uint b = (uint) (light.b * 255.0) & 0xFF;
- return (r << 16) | (g << 8) | b;
- }
- float3 unpackLight(int light)
- {
- float r = ((light >> 16) & 0xFF) / 255.0f;
- float g = ((light >> 8) & 0xFF) / 255.0f;
- float b = (light & 0xFF) / 255.0f;
- return float3(r, g, b);
- }
- // Global resources
- Texture2D<float4> textures[] : register(t0, space1);
- SamplerState gSampler : register(s0, space0);
|