2021-08-26 19:41:35 +02:00
|
|
|
// Common definitions for both shaders and native code
|
2022-01-08 07:14:50 +01:00
|
|
|
#ifndef RAY_INTEROP_H_INCLUDED
|
|
|
|
#define RAY_INTEROP_H_INCLUDED
|
2021-08-26 19:41:35 +02:00
|
|
|
|
2022-01-21 05:04:43 +01:00
|
|
|
#define LIST_SPECIALIZATION_CONSTANTS(X) \
|
|
|
|
X(0, uint, MAX_POINT_LIGHTS, 256) \
|
|
|
|
X(1, uint, MAX_EMISSIVE_KUSOCHKI, 256) \
|
|
|
|
X(2, uint, MAX_VISIBLE_POINT_LIGHTS, 63) \
|
|
|
|
X(3, uint, MAX_VISIBLE_SURFACE_LIGHTS, 255) \
|
|
|
|
X(4, float, LIGHT_GRID_CELL_SIZE, 128.) \
|
|
|
|
X(5, uint, MAX_LIGHT_CLUSTERS, 262144) \
|
|
|
|
X(6, uint, MAX_TEXTURES, 4096) \
|
|
|
|
X(7, uint, SBT_RECORD_SIZE, 32) \
|
|
|
|
|
2021-09-04 21:36:30 +02:00
|
|
|
#ifndef GLSL
|
2021-12-22 06:38:04 +01:00
|
|
|
#include "xash3d_types.h"
|
2023-01-18 20:06:35 +01:00
|
|
|
#include "vk_const.h"
|
2021-12-22 06:38:04 +01:00
|
|
|
#define MAX_EMISSIVE_KUSOCHKI 256
|
2021-09-04 21:36:30 +02:00
|
|
|
#define uint uint32_t
|
2021-10-27 19:21:06 +02:00
|
|
|
#define vec2 vec2_t
|
2021-09-04 21:36:30 +02:00
|
|
|
#define vec3 vec3_t
|
|
|
|
#define vec4 vec4_t
|
2022-01-08 22:44:02 +01:00
|
|
|
#define mat4 matrix4x4
|
2023-02-06 08:35:08 +01:00
|
|
|
typedef int ivec3[3];
|
2023-11-30 19:01:40 +01:00
|
|
|
typedef int ivec2[2];
|
2021-09-04 21:36:30 +02:00
|
|
|
#define TOKENPASTE(x, y) x ## y
|
|
|
|
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
|
|
|
#define PAD(x) float TOKENPASTE2(pad_, __LINE__)[x];
|
2021-10-14 19:56:19 +02:00
|
|
|
#define STRUCT struct
|
2022-01-21 05:04:43 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
#define DECLARE_SPECIALIZATION_CONSTANT(index, type, name, default_value) \
|
|
|
|
SPEC_##name##_INDEX = index,
|
|
|
|
LIST_SPECIALIZATION_CONSTANTS(DECLARE_SPECIALIZATION_CONSTANT)
|
|
|
|
#undef DECLARE_SPECIALIZATION_CONSTANT
|
|
|
|
};
|
|
|
|
|
|
|
|
#else // if GLSL else
|
2021-10-20 20:29:48 +02:00
|
|
|
#extension GL_EXT_shader_8bit_storage : require
|
|
|
|
|
2021-09-04 21:36:30 +02:00
|
|
|
#define PAD(x)
|
2021-10-14 19:56:19 +02:00
|
|
|
#define STRUCT
|
|
|
|
|
2022-01-21 05:04:43 +01:00
|
|
|
#define DECLARE_SPECIALIZATION_CONSTANT(index, type, name, default_value) \
|
|
|
|
layout (constant_id = index) const type name = default_value;
|
|
|
|
LIST_SPECIALIZATION_CONSTANTS(DECLARE_SPECIALIZATION_CONSTANT)
|
|
|
|
#undef DECLARE_SPECIALIZATION_CONSTANT
|
|
|
|
|
|
|
|
#endif // not GLSL
|
2021-09-04 21:36:30 +02:00
|
|
|
|
2023-11-23 18:25:24 +01:00
|
|
|
struct Vertex {
|
|
|
|
vec3 pos;
|
|
|
|
vec3 prev_pos;
|
|
|
|
vec3 normal;
|
|
|
|
vec3 tangent;
|
|
|
|
vec2 gl_tc;
|
|
|
|
vec2 _unused_lm_tc;
|
|
|
|
uint color;
|
|
|
|
};
|
|
|
|
|
2021-10-29 20:05:07 +02:00
|
|
|
#define GEOMETRY_BIT_OPAQUE 0x01
|
2023-02-03 20:00:34 +01:00
|
|
|
#define GEOMETRY_BIT_ALPHA_TEST 0x02
|
2023-04-24 20:38:12 +02:00
|
|
|
#define GEOMETRY_BIT_BLEND 0x04
|
2023-02-03 20:00:34 +01:00
|
|
|
#define GEOMETRY_BIT_REFRACTIVE 0x08
|
2021-10-29 20:21:47 +02:00
|
|
|
|
|
|
|
#define SHADER_OFFSET_MISS_REGULAR 0
|
|
|
|
#define SHADER_OFFSET_MISS_SHADOW 1
|
2021-10-29 21:04:45 +02:00
|
|
|
#define SHADER_OFFSET_MISS_EMPTY 2
|
2021-10-29 20:21:47 +02:00
|
|
|
|
|
|
|
#define SHADER_OFFSET_HIT_REGULAR 0
|
|
|
|
#define SHADER_OFFSET_HIT_ALPHA_TEST 1
|
2021-10-29 21:04:45 +02:00
|
|
|
#define SHADER_OFFSET_HIT_ADDITIVE 2
|
2021-12-08 21:08:26 +01:00
|
|
|
|
|
|
|
#define SHADER_OFFSET_HIT_REGULAR_BASE 0
|
|
|
|
#define SHADER_OFFSET_HIT_SHADOW_BASE 3
|
2021-11-25 20:53:44 +01:00
|
|
|
|
2023-04-24 20:38:12 +02:00
|
|
|
#define MATERIAL_MODE_OPAQUE 0
|
|
|
|
#define MATERIAL_MODE_OPAQUE_ALPHA_TEST 1
|
|
|
|
#define MATERIAL_MODE_TRANSLUCENT 2
|
|
|
|
#define MATERIAL_MODE_BLEND_ADD 3
|
|
|
|
#define MATERIAL_MODE_BLEND_MIX 4
|
|
|
|
#define MATERIAL_MODE_BLEND_GLOW 5
|
2023-06-07 19:24:29 +02:00
|
|
|
#define MATERIAL_MODE_COUNT 6
|
2021-09-06 20:57:23 +02:00
|
|
|
|
2023-11-07 19:30:46 +01:00
|
|
|
#define TEX_BASE_SKYBOX 0x0f000000u
|
2021-09-04 21:36:30 +02:00
|
|
|
|
2023-05-02 00:34:13 +02:00
|
|
|
struct Material {
|
2021-11-14 22:53:50 +01:00
|
|
|
uint tex_base_color;
|
2021-09-04 21:36:30 +02:00
|
|
|
|
2023-04-24 19:44:01 +02:00
|
|
|
// TODO can be combined into a single texture
|
2021-11-14 22:53:50 +01:00
|
|
|
uint tex_roughness;
|
|
|
|
uint tex_metalness;
|
|
|
|
uint tex_normalmap;
|
2021-12-01 19:32:32 +01:00
|
|
|
|
2023-04-24 19:44:01 +02:00
|
|
|
// TODO:
|
|
|
|
// uint tex_emissive;
|
|
|
|
// uint tex_detail;
|
|
|
|
|
2021-12-01 19:32:32 +01:00
|
|
|
float roughness;
|
|
|
|
float metalness;
|
2023-04-12 19:26:37 +02:00
|
|
|
float normal_scale;
|
2023-05-02 00:34:13 +02:00
|
|
|
PAD(1)
|
|
|
|
|
|
|
|
vec4 base_color;
|
2023-04-24 19:44:01 +02:00
|
|
|
};
|
2023-03-01 02:50:50 +01:00
|
|
|
|
2023-05-02 00:34:13 +02:00
|
|
|
struct ModelHeader {
|
2023-01-22 00:45:29 +01:00
|
|
|
mat4 prev_transform;
|
2023-05-02 00:34:13 +02:00
|
|
|
vec4 color;
|
|
|
|
uint mode;
|
|
|
|
PAD(3)
|
2021-09-04 21:36:30 +02:00
|
|
|
};
|
|
|
|
|
2023-04-24 19:44:01 +02:00
|
|
|
struct Kusok {
|
2023-05-25 21:12:18 +02:00
|
|
|
// Geometry data, static
|
2023-04-24 19:44:01 +02:00
|
|
|
uint index_offset;
|
|
|
|
uint vertex_offset;
|
|
|
|
|
|
|
|
// material below consists of scalar fields only, so it's not aligned to vec4.
|
|
|
|
// Alignt it here to vec4 explicitly, so that later vector fields are properly aligned (for simplicity).
|
2023-06-01 19:15:30 +02:00
|
|
|
uint _padding0[2];
|
2023-04-24 19:44:01 +02:00
|
|
|
|
|
|
|
// Per-kusok because individual surfaces can be patched
|
2023-05-25 21:12:18 +02:00
|
|
|
// TODO? still move to material, or its own table? As this can be dynamic
|
2023-04-24 19:44:01 +02:00
|
|
|
vec3 emissive;
|
|
|
|
PAD(1)
|
|
|
|
|
2023-05-02 00:34:13 +02:00
|
|
|
// TODO reference into material table
|
|
|
|
STRUCT Material material;
|
2023-04-24 19:44:01 +02:00
|
|
|
};
|
|
|
|
|
2021-09-19 23:43:22 +02:00
|
|
|
struct PointLight {
|
2024-01-15 17:40:17 +01:00
|
|
|
vec4 origin_r2; // vec4(center.xyz, radius²)
|
2021-10-16 23:33:02 +02:00
|
|
|
vec4 color_stopdot;
|
|
|
|
vec4 dir_stopdot2;
|
2024-01-15 17:40:17 +01:00
|
|
|
|
|
|
|
// TODO move to either dedicated array, or section of array (by-index type delimiter)
|
2021-10-20 20:29:48 +02:00
|
|
|
uint environment; // Is directional-only environment light
|
|
|
|
PAD(3)
|
2021-09-19 23:43:22 +02:00
|
|
|
};
|
|
|
|
|
2022-01-15 08:48:57 +01:00
|
|
|
struct PolygonLight {
|
2022-01-16 06:34:43 +01:00
|
|
|
vec4 plane;
|
2022-01-15 08:48:57 +01:00
|
|
|
|
|
|
|
vec3 center;
|
2022-01-16 06:34:43 +01:00
|
|
|
float area;
|
2022-01-15 08:48:57 +01:00
|
|
|
|
|
|
|
vec3 emissive;
|
2022-01-16 06:34:43 +01:00
|
|
|
uint vertices_count_offset;
|
2022-01-15 08:48:57 +01:00
|
|
|
};
|
|
|
|
|
2022-07-30 23:16:24 +02:00
|
|
|
struct LightsMetadata {
|
2022-01-15 08:48:57 +01:00
|
|
|
uint num_polygons;
|
2021-10-14 19:56:19 +02:00
|
|
|
uint num_point_lights;
|
2021-11-21 23:53:51 +01:00
|
|
|
PAD(2)
|
2023-02-06 08:35:08 +01:00
|
|
|
ivec3 grid_min_cell;
|
|
|
|
PAD(1)
|
|
|
|
ivec3 grid_size;
|
|
|
|
PAD(1)
|
2021-10-14 19:56:19 +02:00
|
|
|
STRUCT PointLight point_lights[MAX_POINT_LIGHTS];
|
2022-01-15 08:48:57 +01:00
|
|
|
STRUCT PolygonLight polygons[MAX_EMISSIVE_KUSOCHKI];
|
2022-01-16 02:16:45 +01:00
|
|
|
vec4 polygon_vertices[MAX_EMISSIVE_KUSOCHKI * 7]; // vec3 but aligned
|
2021-10-14 19:56:19 +02:00
|
|
|
};
|
|
|
|
|
2021-10-20 20:29:48 +02:00
|
|
|
struct LightCluster {
|
|
|
|
uint8_t num_point_lights;
|
2022-01-16 08:12:12 +01:00
|
|
|
uint8_t num_polygons;
|
2021-10-20 20:29:48 +02:00
|
|
|
uint8_t point_lights[MAX_VISIBLE_POINT_LIGHTS];
|
2022-01-16 08:12:12 +01:00
|
|
|
uint8_t polygons[MAX_VISIBLE_SURFACE_LIGHTS];
|
2021-10-20 20:29:48 +02:00
|
|
|
};
|
|
|
|
|
2021-11-19 20:31:45 +01:00
|
|
|
#define PUSH_FLAG_LIGHTMAP_ONLY 0x01
|
2021-11-02 18:14:28 +01:00
|
|
|
|
2023-11-03 15:58:13 +01:00
|
|
|
#define DEBUG_DISPLAY_DISABLED 0
|
|
|
|
#define DEBUG_DISPLAY_BASECOLOR 1
|
|
|
|
#define DEBUG_DISPLAY_BASEALPHA 2
|
|
|
|
#define DEBUG_DISPLAY_EMISSIVE 3
|
|
|
|
#define DEBUG_DISPLAY_NSHADE 4
|
|
|
|
#define DEBUG_DISPLAY_NGEOM 5
|
2023-11-03 16:26:57 +01:00
|
|
|
#define DEBUG_DISPLAY_LIGHTING 6
|
2023-11-03 17:05:36 +01:00
|
|
|
#define DEBUG_DISPLAY_SURFHASH 7
|
2023-11-06 18:47:21 +01:00
|
|
|
#define DEBUG_DISPLAY_DIRECT 8
|
2024-01-02 19:32:49 +01:00
|
|
|
#define DEBUG_DISPLAY_DIRECT_DIFF 9
|
|
|
|
#define DEBUG_DISPLAY_DIRECT_SPEC 10
|
|
|
|
#define DEBUG_DISPLAY_INDIRECT 11
|
|
|
|
#define DEBUG_DISPLAY_INDIRECT_DIFF 12
|
|
|
|
#define DEBUG_DISPLAY_INDIRECT_SPEC 13
|
|
|
|
#define DEBUG_DISPLAY_TRIHASH 14
|
2024-01-11 17:56:23 +01:00
|
|
|
#define DEBUG_DISPLAY_MATERIAL 15
|
2024-01-26 20:02:19 +01:00
|
|
|
#define DEBUG_DISPLAY_DIFFUSE 16
|
|
|
|
#define DEBUG_DISPLAY_SPECULAR 17
|
2023-11-03 15:58:13 +01:00
|
|
|
// add more when needed
|
|
|
|
|
2024-01-26 16:52:17 +01:00
|
|
|
#define DEBUG_FLAG_WHITE_FURNACE (1<<0)
|
|
|
|
|
2022-01-08 22:44:02 +01:00
|
|
|
struct UniformBuffer {
|
|
|
|
mat4 inv_proj, inv_view;
|
2023-01-22 00:45:29 +01:00
|
|
|
mat4 prev_inv_proj, prev_inv_view;
|
2023-11-30 19:01:40 +01:00
|
|
|
ivec2 res;
|
2022-01-08 22:44:02 +01:00
|
|
|
float ray_cone_width;
|
2022-01-16 08:15:29 +01:00
|
|
|
uint random_seed;
|
2023-09-11 18:31:03 +02:00
|
|
|
uint frame_counter;
|
2023-12-18 18:26:01 +01:00
|
|
|
float skybox_exposure;
|
2023-11-03 15:58:13 +01:00
|
|
|
|
|
|
|
uint debug_display_only;
|
2024-01-26 16:52:17 +01:00
|
|
|
uint debug_flags;
|
2022-01-08 22:44:02 +01:00
|
|
|
};
|
|
|
|
|
2021-10-14 19:56:19 +02:00
|
|
|
#undef PAD
|
|
|
|
#undef STRUCT
|
|
|
|
|
2021-09-04 21:36:30 +02:00
|
|
|
#ifndef GLSL
|
|
|
|
#undef uint
|
|
|
|
#undef vec3
|
|
|
|
#undef vec4
|
|
|
|
#undef TOKENPASTE
|
|
|
|
#undef TOKENPASTE2
|
|
|
|
#endif
|
2022-01-08 07:14:50 +01:00
|
|
|
|
|
|
|
#endif // RAY_INTEROP_H_INCLUDED
|