From e384f2e1f7a8a0d03af86de4d530dc4741af7752 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Sat, 22 Jan 2022 19:13:08 -0800 Subject: [PATCH] rt: move shader binding defs to interop --- ref_vk/shaders/ray_interop.h | 13 ++++ ref_vk/shaders/ray_light_direct.comp | 73 ----------------------- ref_vk/shaders/ray_light_direct_iface.h | 8 --- ref_vk/shaders/ray_light_poly_direct.rgen | 2 - ref_vk/shaders/ray_primary.rgen | 1 - ref_vk/shaders/ray_primary_iface.h | 5 -- ref_vk/vk_ray_resources.h | 5 +- 7 files changed, 15 insertions(+), 92 deletions(-) delete mode 100644 ref_vk/shaders/ray_light_direct.comp delete mode 100644 ref_vk/shaders/ray_light_direct_iface.h delete mode 100644 ref_vk/shaders/ray_primary_iface.h diff --git a/ref_vk/shaders/ray_interop.h b/ref_vk/shaders/ray_interop.h index 368c2b55..9f6a1833 100644 --- a/ref_vk/shaders/ray_interop.h +++ b/ref_vk/shaders/ray_interop.h @@ -2,6 +2,19 @@ #ifndef RAY_INTEROP_H_INCLUDED #define RAY_INTEROP_H_INCLUDED +#define RAY_LIGHT_DIRECT_INPUTS(X) \ + X(10, position_t, rgba32f) \ + X(11, normals_gs, rgba16f) \ + +#define RAY_LIGHT_DIRECT_OUTPUTS(X) \ + X(13, light_poly_diffuse, rgba16f) \ + X(14, light_poly_specular, rgba16f) \ + +#define RAY_PRIMARY_OUTPUTS(X) \ + X(10, base_color_a, rgba8) \ + X(11, position_t, rgba32f) \ + X(12, normals_gs, rgba16f) \ + #define LIST_SPECIALIZATION_CONSTANTS(X) \ X(0, uint, MAX_POINT_LIGHTS, 256) \ X(1, uint, MAX_EMISSIVE_KUSOCHKI, 256) \ diff --git a/ref_vk/shaders/ray_light_direct.comp b/ref_vk/shaders/ray_light_direct.comp deleted file mode 100644 index 571ab7de..00000000 --- a/ref_vk/shaders/ray_light_direct.comp +++ /dev/null @@ -1,73 +0,0 @@ -#version 460 core -#extension GL_GOOGLE_include_directive : require -#extension GL_EXT_control_flow_attributes : require -#extension GL_EXT_ray_query: require - -#include "utils.glsl" - -layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; - -#include "ray_light_direct_iface.h" - -#define GLSL -#include "ray_interop.h" -#undef GLSL - -#define X(index, name, format) layout(set=0,binding=index,format) uniform readonly image2D name; -RAY_LIGHT_DIRECT_INPUTS(X) -#undef X -#define X(index, name, format) layout(set=0,binding=index,format) uniform writeonly image2D out_image_##name; -RAY_LIGHT_DIRECT_OUTPUTS(X) -#undef X - -layout(set = 0, binding = 1) uniform accelerationStructureEXT tlas; -layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; }; - -#include "ray_kusochki.glsl" - -#define RAY_QUERY - -#define BINDING_LIGHTS 7 -#define BINDING_LIGHT_CLUSTERS 8 -#include "light.glsl" - -void readNormals(ivec2 uv, out vec3 geometry_normal, out vec3 shading_normal) { - const vec4 n = imageLoad(normals_gs, uv); - geometry_normal = normalDecode(n.xy); - shading_normal = normalDecode(n.zw); -} - -void main() { - //vec2 uv = (gl_LaunchIDEXT.xy + .5) / gl_LaunchSizeEXT.xy * 2. - 1.; - const ivec2 res = ivec2(imageSize(position_t)); - const ivec2 pix = ivec2(gl_GlobalInvocationID); - const vec2 uv = (pix + .5) / res * 2. - 1.; - - rand01_state = ubo.random_seed + gl_GlobalInvocationID.x * 1833 + gl_GlobalInvocationID.y * 31337; - - // FIXME incorrect for reflection/refraction - vec4 target = ubo.inv_proj * vec4(uv.x, uv.y, 1, 1); - vec3 direction = normalize((ubo.inv_view * vec4(target.xyz, 0)).xyz); - - MaterialProperties material; - material.baseColor = vec3(1.); - material.emissive = vec3(0.f); - material.metalness = 0.f; // TODO - material.roughness = 1.f; // TODO - - const vec3 pos = imageLoad(position_t, pix).xyz; - - vec3 geometry_normal, shading_normal; - readNormals(pix, geometry_normal, shading_normal); - - const vec3 throughput = vec3(1.); - vec3 diffuse = vec3(0.), specular = vec3(0.); - computeLighting(pos + geometry_normal * .001, shading_normal, throughput, -direction, material, diffuse, specular); - - //specular = shading_normal; - //diffuse = geometry_normal; - //diffuse = shading_normal; - imageStore(out_image_light_poly_diffuse, pix, vec4(diffuse, 0.f)); - //imageStore(out_image_light_diffuse, pix, vec4(1.,0.,0.f, 0.f)); - imageStore(out_image_light_poly_specular, pix, vec4(specular, 0.f)); -} diff --git a/ref_vk/shaders/ray_light_direct_iface.h b/ref_vk/shaders/ray_light_direct_iface.h deleted file mode 100644 index bbab5183..00000000 --- a/ref_vk/shaders/ray_light_direct_iface.h +++ /dev/null @@ -1,8 +0,0 @@ -#define RAY_LIGHT_DIRECT_INPUTS(X) \ - X(10, position_t, rgba32f) \ - X(11, normals_gs, rgba16f) \ - -#define RAY_LIGHT_DIRECT_OUTPUTS(X) \ - X(13, light_poly_diffuse, rgba16f) \ - X(14, light_poly_specular, rgba16f) \ - diff --git a/ref_vk/shaders/ray_light_poly_direct.rgen b/ref_vk/shaders/ray_light_poly_direct.rgen index e2921f6d..306b356c 100644 --- a/ref_vk/shaders/ray_light_poly_direct.rgen +++ b/ref_vk/shaders/ray_light_poly_direct.rgen @@ -5,8 +5,6 @@ #include "utils.glsl" -#include "ray_light_direct_iface.h" - #define GLSL #include "ray_interop.h" #undef GLSL diff --git a/ref_vk/shaders/ray_primary.rgen b/ref_vk/shaders/ray_primary.rgen index 958bdabc..816ff964 100644 --- a/ref_vk/shaders/ray_primary.rgen +++ b/ref_vk/shaders/ray_primary.rgen @@ -2,7 +2,6 @@ #extension GL_GOOGLE_include_directive : require #include "ray_primary_common.glsl" -#include "ray_primary_iface.h" #define X(index, name, format) layout(set=0,binding=index,format) uniform image2D out_image_##name; RAY_PRIMARY_OUTPUTS(X) diff --git a/ref_vk/shaders/ray_primary_iface.h b/ref_vk/shaders/ray_primary_iface.h deleted file mode 100644 index eebdc4d2..00000000 --- a/ref_vk/shaders/ray_primary_iface.h +++ /dev/null @@ -1,5 +0,0 @@ -#define RAY_PRIMARY_OUTPUTS(X) \ - X(10, base_color_a, rgba8) \ - X(11, position_t, rgba32f) \ - X(12, normals_gs, rgba16f) \ - diff --git a/ref_vk/vk_ray_resources.h b/ref_vk/vk_ray_resources.h index 86c3149a..e45c44f5 100644 --- a/ref_vk/vk_ray_resources.h +++ b/ref_vk/vk_ray_resources.h @@ -1,9 +1,8 @@ #pragma once #include "vk_rtx.h" - -#include "shaders/ray_primary_iface.h" -#include "shaders/ray_light_direct_iface.h" +#include "vk_const.h" +#include "shaders/ray_interop.h" typedef struct { uint32_t width, height;