rtx: move Lights buffer definition to common header
This commit is contained in:
parent
119c73abfa
commit
208d7528ad
|
@ -14,8 +14,6 @@ const float point_light_attenuation_const = 10000.;
|
|||
const float shadow_offset_fudge = .1;
|
||||
const float meters_per_unit = 1.;// / 39.37;
|
||||
|
||||
layout (constant_id = 0) const uint MAX_POINT_LIGHTS = 32;
|
||||
layout (constant_id = 1) const uint MAX_EMISSIVE_KUSOCHKI = 256;
|
||||
layout (constant_id = 2) const uint MAX_VISIBLE_POINT_LIGHTS = 31;
|
||||
layout (constant_id = 3) const uint MAX_VISIBLE_SURFACE_LIGHTS = 255;
|
||||
layout (constant_id = 4) const float LIGHT_GRID_CELL_SIZE = 256.;
|
||||
|
@ -33,19 +31,7 @@ layout(set = 0, binding = 2) uniform UBO {
|
|||
mat4 inv_proj, inv_view;
|
||||
} ubo;
|
||||
|
||||
// TODO #include, use from here and regular shader
|
||||
struct EmissiveKusok {
|
||||
uint kusok_index;
|
||||
vec4 tx_row_x, tx_row_y, tx_row_z;
|
||||
};
|
||||
|
||||
layout (set = 0, binding = 7/*, align=4*/) uniform Lights {
|
||||
uint num_kusochki;
|
||||
uint num_point_lights;
|
||||
vec3 sun_dir, sun_color;
|
||||
EmissiveKusok kusochki[MAX_EMISSIVE_KUSOCHKI];
|
||||
PointLight point_lights[MAX_POINT_LIGHTS];
|
||||
} lights;
|
||||
layout (set = 0, binding = 7/*, align=4*/) uniform UBOLights { Lights lights; };
|
||||
|
||||
struct LightCluster {
|
||||
uint8_t num_dlights;
|
||||
|
@ -200,7 +186,7 @@ vec3 computeLighting(vec3 throughput, vec3 view_dir, MaterialProperties material
|
|||
}
|
||||
for (uint i = begin_i; i < end_i; ++i) {
|
||||
#else
|
||||
|
||||
|
||||
for (uint i = 0; i < num_emissive_kusochki; ++i) {
|
||||
#endif
|
||||
const uint index_into_emissive_kusochki = uint(light_grid.clusters[cluster_index].emissive_surfaces[i]);
|
||||
|
|
|
@ -1,24 +1,10 @@
|
|||
#version 460 core
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#include "ray_common.glsl"
|
||||
#include "ray_kusochki.glsl"
|
||||
|
||||
layout (constant_id = 0) const uint MAX_POINT_LIGHTS = 32;
|
||||
layout (constant_id = 1) const uint MAX_EMISSIVE_KUSOCHKI = 256;
|
||||
|
||||
// TODO #include, use from here and regular shader
|
||||
struct EmissiveKusok {
|
||||
uint kusok_index;
|
||||
vec4 tx_row_x, tx_row_y, tx_row_z;
|
||||
};
|
||||
|
||||
layout (set = 0, binding = 7/*, align=4*/) uniform Lights {
|
||||
uint num_kusochki;
|
||||
uint num_point_lights;
|
||||
vec3 sun_dir, sun_color;
|
||||
EmissiveKusok kusochki[MAX_EMISSIVE_KUSOCHKI];
|
||||
PointLight point_lights[MAX_POINT_LIGHTS];
|
||||
} lights;
|
||||
layout (set = 0, binding = 7/*, align=4*/) uniform UBOLights { Lights lights; };
|
||||
|
||||
layout(location = 0) rayPayloadInEXT RayPayload payload;
|
||||
|
||||
|
|
|
@ -7,8 +7,13 @@
|
|||
#define TOKENPASTE(x, y) x ## y
|
||||
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
||||
#define PAD(x) float TOKENPASTE2(pad_, __LINE__)[x];
|
||||
#define STRUCT struct
|
||||
#else
|
||||
#define PAD(x)
|
||||
#define STRUCT
|
||||
|
||||
layout (constant_id = 0) const uint MAX_POINT_LIGHTS = 32;
|
||||
layout (constant_id = 1) const uint MAX_EMISSIVE_KUSOCHKI = 256;
|
||||
#endif
|
||||
|
||||
#define GEOMETRY_BIT_ANY 0x01
|
||||
|
@ -35,6 +40,24 @@ struct PointLight {
|
|||
vec4 color;
|
||||
};
|
||||
|
||||
struct EmissiveKusok {
|
||||
uint kusok_index;
|
||||
PAD(3)
|
||||
vec4 tx_row_x, tx_row_y, tx_row_z;
|
||||
};
|
||||
|
||||
struct Lights {
|
||||
uint num_kusochki;
|
||||
uint num_point_lights;
|
||||
PAD(2)
|
||||
vec3 sun_dir;
|
||||
PAD(1)
|
||||
vec3 sun_color;
|
||||
PAD(1)
|
||||
STRUCT EmissiveKusok kusochki[MAX_EMISSIVE_KUSOCHKI];
|
||||
STRUCT PointLight point_lights[MAX_POINT_LIGHTS];
|
||||
};
|
||||
|
||||
struct PushConstants {
|
||||
uint random_seed;
|
||||
int bounces;
|
||||
|
@ -43,11 +66,13 @@ struct PushConstants {
|
|||
uint debug_light_index_begin, debug_light_index_end;
|
||||
};
|
||||
|
||||
#undef PAD
|
||||
#undef STRUCT
|
||||
|
||||
#ifndef GLSL
|
||||
#undef uint
|
||||
#undef vec3
|
||||
#undef vec4
|
||||
#undef TOKENPASTE
|
||||
#undef TOKENPASTE2
|
||||
#undef PAD
|
||||
#endif
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
#include "vk_buffer.h"
|
||||
#include "vk_const.h"
|
||||
|
||||
#include "shaders/ray_interop.h"
|
||||
|
||||
#define MAX_ACCELS 1024
|
||||
#define MAX_KUSOCHKI 8192
|
||||
#define MAX_EMISSIVE_KUSOCHKI 256
|
||||
#define MODEL_CACHE_SIZE 1024
|
||||
|
||||
#include "shaders/ray_interop.h"
|
||||
|
||||
typedef struct vk_ray_model_s {
|
||||
VkAccelerationStructureKHR as;
|
||||
VkAccelerationStructureGeometryKHR *geoms;
|
||||
|
@ -28,22 +28,6 @@ typedef struct vk_ray_model_s {
|
|||
|
||||
typedef struct Kusok vk_kusok_data_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t num_kusochki;
|
||||
uint32_t num_point_lights;
|
||||
uint32_t padding__1[2];
|
||||
vec3_t sun_dir;
|
||||
uint32_t padding__2[1];
|
||||
vec3_t sun_color;
|
||||
uint32_t padding__3[1];
|
||||
struct {
|
||||
uint32_t kusok_index;
|
||||
uint32_t padding__[3];
|
||||
matrix3x4 transform;
|
||||
} kusochki[MAX_EMISSIVE_KUSOCHKI];
|
||||
struct PointLight point_lights[MAX_POINT_LIGHTS];
|
||||
} vk_lights_buffer_t;
|
||||
|
||||
typedef struct {
|
||||
matrix3x4 transform_row;
|
||||
vk_ray_model_t *model;
|
||||
|
|
|
@ -656,23 +656,23 @@ static void updateLights( void )
|
|||
|
||||
// Upload dynamic emissive kusochki
|
||||
{
|
||||
vk_lights_buffer_t *ek = g_ray_model_state.lights_buffer.mapped;
|
||||
struct Lights *lights = g_ray_model_state.lights_buffer.mapped;
|
||||
ASSERT(g_lights.num_emissive_surfaces <= MAX_EMISSIVE_KUSOCHKI);
|
||||
ek->num_kusochki = g_lights.num_emissive_surfaces;
|
||||
lights->num_kusochki = g_lights.num_emissive_surfaces;
|
||||
for (int i = 0; i < g_lights.num_emissive_surfaces; ++i) {
|
||||
ek->kusochki[i].kusok_index = g_lights.emissive_surfaces[i].kusok_index;
|
||||
Matrix3x4_Copy(ek->kusochki[i].transform, g_lights.emissive_surfaces[i].transform);
|
||||
lights->kusochki[i].kusok_index = g_lights.emissive_surfaces[i].kusok_index;
|
||||
Matrix3x4_Copy(lights->kusochki[i].tx_row_x, g_lights.emissive_surfaces[i].transform);
|
||||
}
|
||||
|
||||
ek->num_point_lights = g_lights.num_point_lights;
|
||||
lights->num_point_lights = g_lights.num_point_lights;
|
||||
for (int i = 0; i < g_lights.num_point_lights; ++i) {
|
||||
Vector4Copy(g_lights.point_lights[i].origin, ek->point_lights[i].position);
|
||||
Vector4Copy(g_lights.point_lights[i].color, ek->point_lights[i].color);
|
||||
Vector4Copy(g_lights.point_lights[i].origin, lights->point_lights[i].position);
|
||||
Vector4Copy(g_lights.point_lights[i].color, lights->point_lights[i].color);
|
||||
}
|
||||
|
||||
//VectorCopy(g_lights.map.sun_color, ek->sun_color);
|
||||
VectorScale(g_lights.map.sun_color, 50, ek->sun_color);
|
||||
VectorCopy(g_lights.map.sun_dir, ek->sun_dir);
|
||||
//VectorCopy(g_lights.map.sun_color, lights->sun_color);
|
||||
VectorScale(g_lights.map.sun_color, 50, lights->sun_color);
|
||||
VectorCopy(g_lights.map.sun_dir, lights->sun_dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1002,7 +1002,7 @@ qboolean VK_RayInit( void )
|
|||
}
|
||||
g_ray_model_state.kusochki_alloc.size = MAX_KUSOCHKI;
|
||||
|
||||
if (!createBuffer("ray lights_buffer", &g_ray_model_state.lights_buffer, sizeof(vk_lights_buffer_t),
|
||||
if (!createBuffer("ray lights_buffer", &g_ray_model_state.lights_buffer, sizeof(struct Lights),
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT /* | VK_BUFFER_USAGE_TRANSFER_DST_BIT */,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
|
||||
// FIXME complain, handle
|
||||
|
|
Loading…
Reference in New Issue