Crafter.Graphics/examples/Sponza/closesthit.glsl

26 lines
1 KiB
GLSL

//SPDX-License-Identifier: MIT
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#version 460
#extension GL_EXT_ray_tracing : enable
#extension GL_EXT_shader_image_load_formatted : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable
#extension GL_EXT_descriptor_heap : enable
#extension GL_EXT_nonuniform_qualifier : enable
// Specialization constant: descriptor-heap slot of the albedo texture.
// Set from descriptorHeap.bufferStartElement + the slot allocated for
// the Image2D<RGBA8> on the host side. Sampling uses gl_HitAttributeEXT
// barycentrics as UVs — proof-of-binding rather than UV-correct shading.
// Per-vertex UV interpolation lands when Mesh on Vulkan exposes the
// data-region buffer.
layout(constant_id = 0) const uint16_t albedoSlot = 0us;
layout(descriptor_heap) uniform sampler2D albedo[];
hitAttributeEXT vec2 hitAttrs;
layout(location = 0) rayPayloadInEXT vec3 hitValue;
void main() {
vec2 bary = vec2(hitAttrs.x, hitAttrs.y);
hitValue = texture(albedo[albedoSlot], bary).rgb;
}