rt: add skybox support

This commit is contained in:
Ivan Avdeev 2022-02-02 21:47:40 -08:00
parent 3a6bed136a
commit 4bb44c1569
4 changed files with 14 additions and 2 deletions

View File

@ -16,6 +16,7 @@
X(Buffer, lights) \
X(Buffer, light_clusters) \
X(Texture, all_textures) \
X(Texture, skybox) \
enum {
#define X(type, name, ...) RayResource_##name,

View File

@ -10,6 +10,7 @@
layout(set = 0, binding = 6) uniform sampler2D textures[MAX_TEXTURES];
layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; };
layout(set = 0, binding = 7) uniform samplerCube skybox;
layout(location = PAYLOAD_LOCATION_PRIMARY) rayPayloadInEXT RayPayloadPrimary payload;
hitAttributeEXT vec2 bary;
@ -29,8 +30,8 @@ void main() {
const uint tex_base_color = kusok.tex_base_color;
if ((tex_base_color & KUSOK_MATERIAL_FLAG_SKYBOX) != 0) {
// FIXME read skybox
payload.base_color_a = vec4(1.,0.,1.,1.);
payload.emissive.rgb = pow(texture(skybox, gl_WorldRayDirectionEXT).rgb, vec3(2.2));
return;
} else {
payload.base_color_a = sampleTexture(tex_base_color, geom.uv, geom.uv_lods) * kusok.color;
payload.material_rmxx.r = (kusok.tex_roughness > 0) ? sampleTexture(kusok.tex_roughness, geom.uv, geom.uv_lods).r : kusok.roughness;

View File

@ -10,6 +10,7 @@
X(4, indices, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR) \
X(5, vertices, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR) \
X(6, all_textures, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MAX_TEXTURES, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR) \
X(7, skybox, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR) \
static const VkDescriptorSetLayoutBinding bindings[] = {
#define INIT_BINDING(index, name, type, count, stages) \

View File

@ -1019,6 +1019,15 @@ static void performTracing( VkCommandBuffer cmdbuf, const vk_ray_frame_render_ar
.value.image_array = tglob.dii_all_textures,
},
[RayResource_skybox] = {
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.value.image = {
.sampler = vk_core.default_sampler,
.imageView = tglob.skybox_cube.vk.image.view ? tglob.skybox_cube.vk.image.view : tglob.cubemap_placeholder.vk.image.view,
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
},
},
#define RES_SET_IMAGE(index, name, ...) \
[RayResource_##name] = { \
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, \