35 lines
1.7 KiB
Text
35 lines
1.7 KiB
Text
|
|
//SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
#version 460
|
||
|
|
#extension GL_EXT_ray_tracing : enable
|
||
|
|
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable
|
||
|
|
#extension GL_EXT_descriptor_heap : enable
|
||
|
|
#extension GL_EXT_nonuniform_qualifier : enable
|
||
|
|
|
||
|
|
// Picks a storage buffer and a sampled image out of the descriptor heap by a
|
||
|
|
// runtime index. Instance 0 uses descriptor set 0 everywhere, so the index is
|
||
|
|
// the same across each wave. Instance 1 alternates between sets 1 and 0 from
|
||
|
|
// one pixel column to the next, so neighbouring lanes of every wave over it
|
||
|
|
// pick different descriptors. On NVIDIA 610.43.02 a runtime index here lost the
|
||
|
|
// device, for both descriptor kinds, which is why the engine's examples select
|
||
|
|
// hit-shader descriptors through spec constants.
|
||
|
|
layout(constant_id = 0) const uint16_t bufferStart = 0us;
|
||
|
|
layout(constant_id = 1) const uint textureBase = 0u;
|
||
|
|
layout(constant_id = 2) const uint colourBase = 0u;
|
||
|
|
|
||
|
|
layout(descriptor_heap, std430) readonly buffer Colour { vec4 value; } colours[];
|
||
|
|
layout(descriptor_heap) uniform texture2D textures[];
|
||
|
|
layout(descriptor_heap) uniform sampler samplers[];
|
||
|
|
|
||
|
|
layout(location = 0) rayPayloadInEXT vec3 hitValue;
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
uint set = gl_InstanceCustomIndexEXT == 0u ? 0u : 1u - (gl_LaunchIDEXT.x & 1u);
|
||
|
|
vec4 colour = colours[nonuniformEXT(uint(bufferStart) + colourBase + set)].value;
|
||
|
|
vec4 texel = textureLod(sampler2D(textures[nonuniformEXT(textureBase + set)], samplers[0]),
|
||
|
|
vec2(0.5), 0.0);
|
||
|
|
// Red from the buffer, green from the texture, so each descriptor kind
|
||
|
|
// is checked separately.
|
||
|
|
hitValue = vec3(colour.r, texel.g, 0.0);
|
||
|
|
}
|