Skip to content

Commit

Permalink
Fixed the lighting on the first person weapon when it's left-handed.
Browse files Browse the repository at this point in the history
It was broken since fb8f14a.
  • Loading branch information
apanteleev committed Dec 21, 2021
1 parent aaee286 commit a0298a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/refresh/vkpt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,8 @@ R_RenderFrame_RTX(refdef_t *fd)
else
Vector4Set(ubo->fs_blend_color, 0.f, 0.f, 0.f, 0.f);

ubo->weapon_left_handed = upload_info.weapon_left_handed;

vkpt_physical_sky_update_ubo(ubo, &sun_light, render_world);
vkpt_bloom_update(ubo, frame_time, ubo->medium != MEDIUM_NONE, qvk.frame_menu_mode);

Expand Down
2 changes: 2 additions & 0 deletions src/refresh/vkpt/shader/global_ubo.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
GLOBAL_UBO_VAR_LIST_DO(mat4, security_camera_data[MAX_CAMERAS]) \
GLOBAL_UBO_VAR_LIST_DO(ShaderFogVolume, fog_volumes[MAX_FOG_VOLUMES]) \
\
GLOBAL_UBO_VAR_LIST_DO(int, weapon_left_handed) \
\
UBO_CVAR_LIST // WARNING: Do not put any other members into global_ubo after this: the CVAR list is not vec4-aligned


Expand Down
4 changes: 3 additions & 1 deletion src/refresh/vkpt/shader/primary_rays.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ main()
vec3 flat_normal = normalize(cross(
triangle.positions[1] - triangle.positions[0],
triangle.positions[2] - triangle.positions[1]));

float flat_normal_sign = (global_ubo.weapon_left_handed != 0 && (triangle.material_id & MATERIAL_FLAG_WEAPON) != 0) ? -1.0 : 1.0;

if (dot(flat_normal, direction) > 0)
if (dot(flat_normal, direction) * flat_normal_sign > 0)
geo_normal = -geo_normal;

/* compute view-space derivatives of depth and motion vectors */
Expand Down
4 changes: 3 additions & 1 deletion src/refresh/vkpt/shader/reflect_refract.rgen
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ main()
triangle.positions[1] - triangle.positions[0],
triangle.positions[2] - triangle.positions[1]));

if (dot(new_flat_normal, direction) > 0)
float flat_normal_sign = (global_ubo.weapon_left_handed != 0 && (triangle.material_id & MATERIAL_FLAG_WEAPON) != 0) ? -1.0 : 1.0;

if (dot(new_flat_normal, direction) * flat_normal_sign > 0)
new_geo_normal = -new_geo_normal;

// Compute the LOD for the texture on the reflected/refracted surface.
Expand Down

0 comments on commit a0298a8

Please sign in to comment.