Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive storage and static model improvements #171

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d28f882
Replaced the SoA storage of world and instanced primitives with unifi…
apanteleev Nov 25, 2021
0d6d22b
Fixed the tangents upload code.
apanteleev Nov 25, 2021
2b19383
Switched to writing the primitive data in bsp_mesh directly. Massive …
apanteleev Nov 25, 2021
9d1e47c
Switched the data formats for frame-based and IQM models to the same …
apanteleev Dec 9, 2021
318e641
Removed the sky and dynamic flags from ray payload, added buffer index.
apanteleev Dec 10, 2021
02e2a56
Replaced the single instanceCustomIndex field storing a dynamic flag …
apanteleev Dec 11, 2021
9b652f9
Break up long line (no functional changes).
apanteleev Dec 11, 2021
6b358e6
Build static BLAS for models without animations.
apanteleev Dec 11, 2021
d6bf89a
Replaced the macro-driven declaration of instance buffer structure co…
apanteleev Dec 13, 2021
0eaa588
Fixed the flickering lights on bsp models.
apanteleev Dec 13, 2021
87fc76f
Use static BLAS of eligible models instead of passing them through in…
apanteleev Dec 13, 2021
cc60f1d
Unified the BSP models and regular models into the same representatio…
apanteleev Dec 14, 2021
38ec7ed
Added support for multiple meshes/geometries in static models.
apanteleev Dec 15, 2021
d2b944c
Switched from a statically sized world primitive buffer to a dynamic …
apanteleev Dec 15, 2021
73bf198
Place the world BLAS into the same vertex buffer, create BLAS for BSP…
apanteleev Dec 16, 2021
82d9ac2
Removed the MAX_MODEL_MESHES limit.
apanteleev Dec 16, 2021
b814ed6
Added calculation of model tangents on load.
apanteleev Dec 16, 2021
a41502f
Removed a stale comment.
apanteleev Dec 16, 2021
bba1bb5
Implemented shadow map rendering for instanced static meshes - both b…
apanteleev Dec 16, 2021
1ded7f7
Refactoring the fill_model_instance function.
apanteleev Dec 16, 2021
c2ada48
That was unnecessary.
apanteleev Dec 16, 2021
66e75a1
Disabled culling on transparent materials.
apanteleev Dec 16, 2021
a5e136c
Removed the unnecessary use_prim_offset parameter.
apanteleev Dec 16, 2021
5f0cab4
Increased the max instance count.
apanteleev Dec 16, 2021
29b16eb
Track primitives, not vertices.
apanteleev Dec 17, 2021
4b25324
Replaced MAX_PRIM_INSTANCED with a dynamically sized buffer.
apanteleev Dec 17, 2021
01b314d
Added the missing VERTEX_BUFFER bit to the model VBOs.
apanteleev Dec 17, 2021
58bad6d
Clang compat and cleanup.
apanteleev Dec 18, 2021
e3bcb45
Fixed the masked materials on static models.
apanteleev Dec 18, 2021
25b232d
Re-create the static model VBOs when their materials change.
apanteleev Dec 18, 2021
6404801
Renamed the motion fields in VboPrimitive for clarity.
apanteleev Dec 18, 2021
835de32
Expanded the V-buffer to have enough bits for many instances with mil…
apanteleev Dec 18, 2021
4746ce7
Merge branch 'master' into vbo
apanteleev Dec 18, 2021
21c7277
Addressing PR feedback.
apanteleev Dec 18, 2021
74c3c60
Replaced the uses of mat3 for positions of a triangle with prim_posit…
apanteleev Dec 18, 2021
762d608
Rollback the TRIANGLE_FACING_CULL_DISABLE_BIT change on transparent g…
apanteleev Dec 18, 2021
5944201
Merge branch 'master' into vbo
apanteleev Dec 18, 2021
a34e8c9
Merge branch 'master' into vbo
apanteleev Dec 20, 2021
03972d6
Fixed the model resource leaks on map change.
apanteleev Dec 20, 2021
0ae6d78
Fixed the BSP resource leak on map change.
apanteleev Dec 20, 2021
57e2a49
Added debug names to model and world objects.
apanteleev Dec 20, 2021
ed2ad93
Fixed the excessive destruction of model VBOs on map or material chan…
apanteleev Dec 20, 2021
cb04989
Fixed the memory leak in the static environment maps on map changes.
apanteleev Dec 20, 2021
a161674
Fixed the primitive indexing for explosions.
apanteleev Dec 20, 2021
e1b2a22
Added support for generic translucent geometry specified using the SU…
apanteleev Dec 20, 2021
53a5af3
Fixed the player setup screen rendering.
apanteleev Dec 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/refresh/vkpt/bsp_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ collect_surfaces(int *idx_ctr, bsp_mesh_t *wm, bsp_t *bsp, int model_idx, int (*
material_id = (material_id & ~MATERIAL_LIGHT_STYLE_MASK) | ((camera_id << MATERIAL_LIGHT_STYLE_SHIFT) & MATERIAL_LIGHT_STYLE_MASK);
}

if (*idx_ctr + create_poly(bsp, surf, material_id, NULL, NULL, NULL, NULL, NULL, NULL) >= MAX_VERT_BSP) {
if (*idx_ctr + create_poly(bsp, surf, material_id, NULL, NULL, NULL, NULL, NULL, NULL) >= MAX_PRIM_BSP * 3) {
Com_Error(ERR_FATAL, "error: exceeding max vertex limit\n");
}

Expand Down Expand Up @@ -1354,7 +1354,7 @@ compute_world_tangents(bsp_t* bsp, bsp_mesh_t* wm)
// compute tangent space
uint32_t ntriangles = wm->num_indices / 3;

wm->texel_density = Z_Malloc(MAX_VERT_BSP * sizeof(float) / 3);
wm->texel_density = Z_Malloc(MAX_PRIM_BSP * sizeof(float));

for (int idx_tri = 0; idx_tri < ntriangles; ++idx_tri)
{
Expand Down Expand Up @@ -1876,13 +1876,13 @@ bsp_mesh_create_from_bsp(bsp_mesh_t *wm, bsp_t *bsp, const char* map_name)

wm->num_vertices = 0;
wm->num_indices = 0;
wm->positions = Z_Malloc(MAX_VERT_BSP * 3 * sizeof(*wm->positions));
wm->tex_coords = Z_Malloc(MAX_VERT_BSP * 2 * sizeof(*wm->tex_coords));
wm->normals = Z_Malloc(MAX_VERT_BSP * sizeof(uint32_t));
wm->tangents = Z_Malloc(MAX_VERT_BSP * sizeof(uint32_t));
wm->materials = Z_Malloc(MAX_VERT_BSP / 3 * sizeof(*wm->materials));
wm->clusters = Z_Malloc(MAX_VERT_BSP / 3 * sizeof(*wm->clusters));
wm->emissive_factors = Z_Malloc(MAX_VERT_BSP / 3 * sizeof(*wm->emissive_factors));
wm->positions = Z_Malloc(MAX_PRIM_BSP * 9 * sizeof(*wm->positions));
wm->tex_coords = Z_Malloc(MAX_PRIM_BSP * 6 * sizeof(*wm->tex_coords));
wm->normals = Z_Malloc(MAX_PRIM_BSP * 3 * sizeof(uint32_t));
wm->tangents = Z_Malloc(MAX_PRIM_BSP * 3 * sizeof(uint32_t));
wm->materials = Z_Malloc(MAX_PRIM_BSP * sizeof(*wm->materials));
wm->clusters = Z_Malloc(MAX_PRIM_BSP * sizeof(*wm->clusters));
wm->emissive_factors = Z_Malloc(MAX_PRIM_BSP * sizeof(*wm->emissive_factors));

// clear these here because `bsp_mesh_load_custom_sky` creates lights before `collect_light_polys`
wm->num_light_polys = 0;
Expand Down Expand Up @@ -1952,7 +1952,7 @@ bsp_mesh_create_from_bsp(bsp_mesh_t *wm, bsp_t *bsp, const char* map_name)

compute_world_tangents(bsp, wm);

if (wm->num_vertices >= MAX_VERT_BSP) {
if (wm->num_vertices >= MAX_PRIM_BSP * 3) {
Com_Error(ERR_FATAL, "The BSP model has too many vertices (%d)", wm->num_vertices);
}

Expand Down
2 changes: 1 addition & 1 deletion src/refresh/vkpt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4017,7 +4017,7 @@ R_BeginRegistration_RTX(const char *name)
bsp_mesh_create_from_bsp(&vkpt_refdef.bsp_mesh_world, bsp, name);
vkpt_light_stats_create(&vkpt_refdef.bsp_mesh_world);
_VK(vkpt_vertex_buffer_upload_bsp_mesh_to_staging(&vkpt_refdef.bsp_mesh_world));
_VK(vkpt_vertex_buffer_bsp_upload_staging());
_VK(vkpt_vertex_buffer_bsp_upload_staging(vkpt_refdef.bsp_mesh_world.num_vertices / 3));
vkpt_refdef.bsp_mesh_world_loaded = 1;
bsp = NULL;
world_anim_frame = 0;
Expand Down
26 changes: 13 additions & 13 deletions src/refresh/vkpt/path_tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,35 +687,35 @@ vkpt_pt_create_static(
int num_vertices_custom_sky)
{
VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
VkDeviceAddress address_vertex = offsetof(BspVertexBuffer, positions_bsp);
VkDeviceAddress address_vertex = 0;

scratch_buf_ptr = 0;

VkResult ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_bsp, address_vertex, NULL, 0, num_vertices, 0, &blas_static, qfalse, qfalse);
VkResult ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_world, address_vertex, NULL, 0, num_vertices, 0, &blas_static, qfalse, qfalse);

MEM_BARRIER_BUILD_ACCEL(cmd_buf);
address_vertex += num_vertices * sizeof(float) * 3;
scratch_buf_ptr = 0;

ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_bsp, address_vertex, NULL, 0, num_vertices_transparent, 0, &blas_transparent, qfalse, qfalse);
ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_world, address_vertex, NULL, 0, num_vertices_transparent, 0, &blas_transparent, qfalse, qfalse);

MEM_BARRIER_BUILD_ACCEL(cmd_buf);
address_vertex += num_vertices_transparent * sizeof(float) * 3;
scratch_buf_ptr = 0;

ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_bsp, address_vertex, NULL, 0, num_vertices_masked, 0, &blas_masked, qfalse, qfalse);
ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_world, address_vertex, NULL, 0, num_vertices_masked, 0, &blas_masked, qfalse, qfalse);

MEM_BARRIER_BUILD_ACCEL(cmd_buf);
address_vertex += num_vertices_masked * sizeof(float) * 3;
scratch_buf_ptr = 0;

ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_bsp, address_vertex, NULL, 0, num_vertices_sky, 0, &blas_sky, qfalse, qfalse);
ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_world, address_vertex, NULL, 0, num_vertices_sky, 0, &blas_sky, qfalse, qfalse);

MEM_BARRIER_BUILD_ACCEL(cmd_buf);
address_vertex += num_vertices_sky * sizeof(float) * 3;
scratch_buf_ptr = 0;

ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_bsp, address_vertex, NULL, 0, num_vertices_custom_sky, 0, &blas_custom_sky, qfalse, qfalse);
ret = vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_world, address_vertex, NULL, 0, num_vertices_custom_sky, 0, &blas_custom_sky, qfalse, qfalse);

MEM_BARRIER_BUILD_ACCEL(cmd_buf);
address_vertex += num_vertices_custom_sky * sizeof(float) * 3;
Expand All @@ -740,30 +740,30 @@ vkpt_pt_create_all_dynamic(
{
scratch_buf_ptr = 0;

uint64_t offset_vertex_base = offsetof(ModelDynamicVertexBuffer, positions_instanced);
uint64_t offset_vertex_base = 0;
uint64_t offset_vertex = offset_vertex_base;
uint64_t offset_index = 0;
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_model_dynamic, offset_vertex, NULL, offset_index, upload_info->dynamic_vertex_num, 0, blas_dynamic + idx, qtrue, qtrue);
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_instanced, offset_vertex, NULL, offset_index, upload_info->dynamic_vertex_num, 0, blas_dynamic + idx, qtrue, qtrue);

transparent_model_primitive_offset = upload_info->transparent_model_vertex_offset / 3;
offset_vertex = offset_vertex_base + upload_info->transparent_model_vertex_offset * sizeof(float) * 3;
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_model_dynamic, offset_vertex, NULL, offset_index, upload_info->transparent_model_vertex_num, 0, blas_transparent_models + idx, qtrue, qtrue);
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_instanced, offset_vertex, NULL, offset_index, upload_info->transparent_model_vertex_num, 0, blas_transparent_models + idx, qtrue, qtrue);

masked_model_primitive_offset = upload_info->masked_model_vertex_offset / 3;
offset_vertex = offset_vertex_base + upload_info->masked_model_vertex_offset * sizeof(float) * 3;
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_model_dynamic, offset_vertex, NULL, offset_index, upload_info->masked_model_vertex_num, 0, blas_masked_models + idx, qtrue, qtrue);
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_instanced, offset_vertex, NULL, offset_index, upload_info->masked_model_vertex_num, 0, blas_masked_models + idx, qtrue, qtrue);

viewer_model_primitive_offset = upload_info->viewer_model_vertex_offset / 3;
offset_vertex = offset_vertex_base + upload_info->viewer_model_vertex_offset * sizeof(float) * 3;
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_model_dynamic, offset_vertex, NULL, offset_index, upload_info->viewer_model_vertex_num, 0, blas_viewer_models + idx, qtrue, qtrue);
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_instanced, offset_vertex, NULL, offset_index, upload_info->viewer_model_vertex_num, 0, blas_viewer_models + idx, qtrue, qtrue);

viewer_weapon_primitive_offset = upload_info->viewer_weapon_vertex_offset / 3;
offset_vertex = offset_vertex_base + upload_info->viewer_weapon_vertex_offset * sizeof(float) * 3;
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_model_dynamic, offset_vertex, NULL, offset_index, upload_info->viewer_weapon_vertex_num, 0, blas_viewer_weapon + idx, qtrue, qtrue);
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_instanced, offset_vertex, NULL, offset_index, upload_info->viewer_weapon_vertex_num, 0, blas_viewer_weapon + idx, qtrue, qtrue);

explosions_primitive_offset = upload_info->explosions_vertex_offset / 3;
offset_vertex = offset_vertex_base + upload_info->explosions_vertex_offset * sizeof(float) * 3;
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_vertex_model_dynamic, offset_vertex, NULL, offset_index, upload_info->explosions_vertex_num, 0, blas_explosions + idx, qtrue, qtrue);
vkpt_pt_create_accel_bottom(cmd_buf, &qvk.buf_positions_instanced, offset_vertex, NULL, offset_index, upload_info->explosions_vertex_num, 0, blas_explosions + idx, qtrue, qtrue);

BufferResource_t* buffer_vertex = NULL;
BufferResource_t* buffer_index = NULL;
Expand Down
5 changes: 3 additions & 2 deletions src/refresh/vkpt/shader/animate_materials.comp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_nonuniform_qualifier : enable

#include "utils.glsl"

Expand All @@ -41,7 +42,7 @@ main()
if(prim >= global_ubo.num_static_primitives)
return;

uint material = get_materials_bsp(prim);
uint material = primitive_buffers[VERTEX_BUFFER_WORLD].primitives[prim].material_id;
uint new_material = material;
MaterialInfo minfo = get_material_info(material);

Expand All @@ -59,7 +60,7 @@ main()

if(new_material != material)
{
set_materials_bsp(prim, new_material);
primitive_buffers[VERTEX_BUFFER_WORLD].primitives[prim].material_id = new_material;
}
}

12 changes: 7 additions & 5 deletions src/refresh/vkpt/shader/asvgf_gradient_reproject.comp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ void patch_position(ivec2 ipos, ivec2 found_pos_prev)
// Read the visibility buffer
uvec2 vis_buf = texelFetch(TEX_PT_VISBUF_B, found_pos_prev, 0).xy;

Triangle triangle;
uint buffer_idx;
uint primitive_id;

if (visbuf_is_static_prim(vis_buf.x))
{
uint primitive_id = visbuf_get_static_prim(vis_buf.x);
triangle = get_bsp_triangle(primitive_id);
primitive_id = visbuf_get_static_prim(vis_buf.x);
buffer_idx = VERTEX_BUFFER_WORLD;
}
else
{
uint instance_id_prev = visbuf_get_instance_id(vis_buf.x);
uint triangle_idx = visbuf_get_instance_prim(vis_buf.x);
uint primitive_id;

// Map the dynamic objects geometry data from the previous frame into the current frame
if (visbuf_is_world_instance(vis_buf.x))
Expand All @@ -100,9 +100,11 @@ void patch_position(ivec2 ipos, ivec2 found_pos_prev)
primitive_id = buf_offset + triangle_idx;
}

triangle = get_instanced_triangle(primitive_id);
buffer_idx = VERTEX_BUFFER_INSTANCED;
}

Triangle triangle = load_triangle(buffer_idx, primitive_id);

vec3 bary = visbuf_unpack_barycentrics(vis_buf.y);

// Reconstruct the position based on the barycentrics
Expand Down
23 changes: 13 additions & 10 deletions src/refresh/vkpt/shader/instance_geometry.comp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ get_model_triangle(uint model_id, uint prim_id, uint idx_offset, uint vert_offse
t.tangents[2] = vec3(0);

t.material_id = 0; // needs to come from uniform buffer

t.alpha = 1.0;
t.cluster = ~0u;
t.instance = 0;
t.emissive_factor = 1;
t.texel_density = 0;

return t;
Expand Down Expand Up @@ -209,8 +210,9 @@ get_iqm_triangle(uint model_id, uint prim_id, uint idx_offset, uint vert_offset,
}

t.material_id = 0; // needs to come from uniform buffer

t.alpha = 1.0;
t.cluster = ~0u;
t.instance = 0;
t.emissive_factor = 1;
t.texel_density = 0;

return t;
Expand Down Expand Up @@ -251,7 +253,7 @@ main()

if(is_world) {
uint id = instance_id;
Triangle t = get_bsp_triangle(idx + instance_buffer.bsp_prim_offset[id]);
Triangle t = load_triangle(VERTEX_BUFFER_WORLD, idx + instance_buffer.bsp_prim_offset[id]);
M_curr = instance_buffer.bsp_mesh_instances[id].M;
uint id_prev = instance_buffer.world_current_to_prev[id];
M_prev = instance_buffer.bsp_mesh_instances_prev[id_prev].M;
Expand Down Expand Up @@ -311,7 +313,7 @@ main()
M_prev = M_curr;
}

t_i.alpha = mi_curr.alpha.x;
t_i.emissive_factor = mi_curr.alpha.x;
t_i.material_id = mi_curr.material;
// t_i.material_id |= MATERIAL_FLAG_HANDEDNESS; // not sure
t_i.cluster = instance_buffer.model_cluster_id[instance_id];
Expand Down Expand Up @@ -340,8 +342,8 @@ main()
t_i.tangents[1].xyz = t_i.tangents[0].xyz;
t_i.tangents[2].xyz = t_i.tangents[0].xyz;

t_i.alpha = mi_curr.alpha.x;
t_i.texel_density = t.texel_density;
t_i.emissive_factor = mi_curr.alpha.x;
t_i.texel_density = t.texel_density;

t_i.material_id = mi_curr.material;
t_i.material_id |= handedness ? MATERIAL_FLAG_HANDEDNESS : 0;
Expand Down Expand Up @@ -388,7 +390,8 @@ main()
t_i.tangents[1] = vec3(M_curr * vec4(t_i.tangents[1], 0.0));
t_i.tangents[2] = vec3(M_curr * vec4(t_i.tangents[2], 0.0));

uint instance_triangle_id = visbuf_pack_instance(instance_id, idx, is_world);
store_instanced_triangle(t_i, instance_triangle_id, idx + buf_offset);
t_i.instance = visbuf_pack_instance(instance_id, idx, is_world);

store_triangle(t_i, VERTEX_BUFFER_INSTANCED, idx + buf_offset);
}
}
13 changes: 5 additions & 8 deletions src/refresh/vkpt/shader/path_tracer_hit_shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ void pt_logic_rchit(inout RayPayloadGeometry ray_payload, int primitiveID, uint

bool pt_logic_masked(int primitiveID, uint instanceCustomIndex, vec2 bary)
{
Triangle triangle;
uint prim = primitiveID + instanceCustomIndex & AS_INSTANCE_MASK_OFFSET;
if ((instanceCustomIndex & AS_INSTANCE_FLAG_DYNAMIC) != 0)
triangle = get_instanced_triangle(prim);
else
triangle = get_bsp_triangle(prim);
uint buffer_idx = (instanceCustomIndex & AS_INSTANCE_FLAG_DYNAMIC) != 0 ? VERTEX_BUFFER_INSTANCED : VERTEX_BUFFER_WORLD;
Triangle triangle = load_triangle(buffer_idx, prim);

MaterialInfo minfo = get_material_info(triangle.material_id);

Expand Down Expand Up @@ -156,7 +153,7 @@ vec4 pt_logic_sprite(int primitiveID, vec2 bary)
vec4 pt_logic_explosion(int primitiveID, uint instanceCustomIndex, vec3 worldRayDirection, vec2 bary)
{
const uint primitive_id = primitiveID + instanceCustomIndex & AS_INSTANCE_MASK_OFFSET;
const Triangle triangle = get_instanced_triangle(primitive_id);
const Triangle triangle = load_triangle(VERTEX_BUFFER_INSTANCED, primitive_id);

const vec3 barycentric = vec3(1.0 - bary.x - bary.y, bary.x, bary.y);
const vec2 tex_coord = triangle.tex_coords * barycentric;
Expand All @@ -167,11 +164,11 @@ vec4 pt_logic_explosion(int primitiveID, uint instanceCustomIndex, vec3 worldRay
if((triangle.material_id & MATERIAL_KIND_MASK) == MATERIAL_KIND_EXPLOSION)
{
const vec3 normal = triangle.normals * barycentric;
emission.rgb = mix(emission.rgb, get_explosion_color(normal, worldRayDirection.xyz), triangle.alpha);
emission.rgb = mix(emission.rgb, get_explosion_color(normal, worldRayDirection.xyz), triangle.emissive_factor);
emission.rgb *= global_ubo.pt_explosion_brightness;
}

emission.a *= triangle.alpha;
emission.a *= triangle.emissive_factor;
emission.rgb *= emission.a;

emission.rgb *= global_ubo.prev_adapted_luminance * 500;
Expand Down
5 changes: 2 additions & 3 deletions src/refresh/vkpt/shader/path_tracer_rgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ Triangle
get_hit_triangle(RayPayloadGeometry rp)
{
uint prim = get_primitive(rp);
uint buffer_idx = is_dynamic_instance(rp) ? VERTEX_BUFFER_INSTANCED : VERTEX_BUFFER_WORLD;

return is_dynamic_instance(rp)
? get_instanced_triangle(prim)
: get_bsp_triangle(prim);
return load_triangle(buffer_idx, prim);
}

vec3
Expand Down
17 changes: 3 additions & 14 deletions src/refresh/vkpt/shader/primary_rays.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,15 @@ main()
return;
}

Triangle triangle;
vec3 bary;
Triangle triangle = get_hit_triangle(ray_payload_geometry);
vec3 bary = get_hit_barycentric(ray_payload_geometry);

{
bool is_dynamic_primitive = is_dynamic_instance(ray_payload_geometry);
uint primitive_id = get_primitive(ray_payload_geometry);
bary = get_hit_barycentric(ray_payload_geometry);

uvec2 vis_buf;
vis_buf.x = is_dynamic_primitive
? get_instance_id_instanced(primitive_id)
: visbuf_pack_static_prim(primitive_id);
vis_buf.x = triangle.instance;
vis_buf.y = visbuf_pack_barycentrics(bary);

imageStore(IMG_PT_VISBUF_A, ipos, uvec4(vis_buf, 0, 0));

if(is_dynamic_primitive)
triangle = get_instanced_triangle(primitive_id);
else
triangle = get_bsp_triangle(primitive_id);
}

if(is_readback_pixel)
Expand Down
7 changes: 0 additions & 7 deletions src/refresh/vkpt/shader/read_visbuf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#define VISBUF_INSTANCE_ID_MASK 0x000003FF
#define VISBUF_INSTANCE_PRIM_MASK 0x3FFFFC00
#define VISBUF_INSTANCE_PRIM_SHIFT 10
#define VISBUF_STATIC_PRIM_MASK 0x3FFFFFFF
#define VISBUF_WORLD_INSTANCE_FLAG 0x40000000
#define VISBUF_STATIC_PRIM_FLAG 0x80000000

uint visbuf_pack_instance(uint instance_id, uint primitive_id, bool is_world_instance)
{
return (instance_id & VISBUF_INSTANCE_ID_MASK)
Expand Down
7 changes: 1 addition & 6 deletions src/refresh/vkpt/shader/reflect_refract.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,8 @@ main()
transparent = alpha_blend_premultiplied(transparent, vec4(primary_emissive * throughput, 0));
}

bool is_dynamic_primitive = is_dynamic_instance(ray_payload_geometry);
uint primitive_id = get_primitive(ray_payload_geometry);

uvec2 vis_buf;
vis_buf.x = is_dynamic_primitive
? get_instance_id_instanced(primitive_id)
: visbuf_pack_static_prim(primitive_id);
vis_buf.x = triangle.instance;
vis_buf.y = visbuf_pack_barycentrics(bary);

imageStore(IMG_PT_VISBUF_A, ipos, uvec4(vis_buf, 0, 0));
Expand Down
Loading