Skip to content

Commit

Permalink
rt: only overshoot additive for glow mode
Browse files Browse the repository at this point in the history
Add another flag to kusochki for glow geometry.
Move flags to a new kusok.flags field.

Fixes #231 (or at least makes it not stand out too much)
  • Loading branch information
w23 committed Mar 1, 2023
1 parent 149dc7c commit 59e8a8c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ref/vk/shaders/light_common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ bool shadowed(vec3 pos, vec3 dir, float dist, bool check_sky) {

const int instance_kusochki_offset = rayQueryGetIntersectionInstanceCustomIndexEXT(rq, true);
const int kusok_index = instance_kusochki_offset + rayQueryGetIntersectionGeometryIndexEXT(rq, true);
const uint tex_base_color = getKusok(kusok_index).tex_base_color;
if ((tex_base_color & KUSOK_MATERIAL_FLAG_SKYBOX) == 0)
const uint flags = getKusok(kusok_index).flags;
if ((flags & KUSOK_MATERIAL_FLAG_SKYBOX) == 0)
return true;
}
}
Expand Down
7 changes: 5 additions & 2 deletions ref/vk/shaders/ray_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ LIST_SPECIALIZATION_CONSTANTS(DECLARE_SPECIALIZATION_CONSTANT)
#define SHADER_OFFSET_HIT_REGULAR_BASE 0
#define SHADER_OFFSET_HIT_SHADOW_BASE 3

#define KUSOK_MATERIAL_FLAG_SKYBOX 0x80000000
#define KUSOK_MATERIAL_FLAG_SKYBOX (1<<0)
#define KUSOK_MATERIAL_FLAG_FIXME_GLOW (1<<1)

struct Kusok {
uint index_offset;
Expand All @@ -85,7 +86,9 @@ struct Kusok {

float roughness;
float metalness;
PAD(2)
uint flags;

PAD(1)

mat4 prev_transform;
};
Expand Down
5 changes: 2 additions & 3 deletions ref/vk/shaders/ray_primary_hit.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {
payload.prev_pos_t = vec4(geom.prev_pos, 0.);

const Kusok kusok = getKusok(geom.kusok_index);
const uint tex_base_color = kusok.tex_base_color;

if ((tex_base_color & KUSOK_MATERIAL_FLAG_SKYBOX) != 0) {
if ((kusok.flags & KUSOK_MATERIAL_FLAG_SKYBOX) != 0) {
payload.emissive.rgb = SRGBtoLINEAR(texture(skybox, rayDirection).rgb);
return;
} else {
payload.base_color_a = sampleTexture(tex_base_color, geom.uv, geom.uv_lods);
payload.base_color_a = sampleTexture(kusok.tex_base_color, geom.uv, geom.uv_lods);
payload.material_rmxx.r = (kusok.tex_roughness > 0) ? sampleTexture(kusok.tex_roughness, geom.uv, geom.uv_lods).r : kusok.roughness;
payload.material_rmxx.g = (kusok.tex_metalness > 0) ? sampleTexture(kusok.tex_metalness, geom.uv, geom.uv_lods).r : kusok.metalness;

Expand Down
6 changes: 5 additions & 1 deletion ref/vk/shaders/trace_additive.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ vec3 traceAdditive(vec3 pos, vec3 dir, float L) {

const float hit_t = rayQueryGetIntersectionTEXT(rq, false);
const float overshoot = hit_t - L;
ret += color * smoothstep(additive_soft_overshoot, 0., overshoot);

if (overshoot < 0.)
ret += color;
else if ((kusok.flags & KUSOK_MATERIAL_FLAG_FIXME_GLOW) != 0)
ret += color * smoothstep(additive_soft_overshoot, 0., overshoot);
}
return ret;
}
Expand Down
18 changes: 9 additions & 9 deletions ref/vk/vk_ray_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr
kusok->roughness = mat->roughness;
kusok->metalness = mat->metalness;

kusok->flags = 0;

// HACK until there is a proper mechanism for patching materials, see https://github.com/w23/xash3d-fwgs/issues/213
// FIXME also this erases previous roughness unconditionally
if (HACK_reflective) {
Expand All @@ -184,7 +186,10 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr
}

if (geom->material == kXVkMaterialSky)
kusok->tex_base_color |= KUSOK_MATERIAL_FLAG_SKYBOX;
kusok->flags |= KUSOK_MATERIAL_FLAG_SKYBOX;

if (geom->material == kXVkMaterialEmissiveGlow)
kusok->flags |= KUSOK_MATERIAL_FLAG_FIXME_GLOW;

{
vec4_t gcolor;
Expand All @@ -195,7 +200,7 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr
Vector4Copy(gcolor, kusok->color);
}

if (geom->material == kXVkMaterialEmissive) {
if (geom->material == kXVkMaterialEmissive || geom->material == kXVkMaterialEmissiveGlow) {
VectorCopy(geom->emissive, kusok->emissive);
} else {
RT_GetEmissiveForTexture( kusok->emissive, geom->texture );
Expand Down Expand Up @@ -308,13 +313,8 @@ vk_ray_model_t* VK_RayModelCreate( vk_ray_model_init_t args ) {
/* ); */
/* } */

if (mg->material == kXVkMaterialSky) {
kusochki[i].tex_base_color |= KUSOK_MATERIAL_FLAG_SKYBOX;
} else {
kusochki[i].tex_base_color &= (~KUSOK_MATERIAL_FLAG_SKYBOX);
}

if (HACK_additive_emissive && mg->material != kXVkMaterialEmissive) {
if (HACK_additive_emissive && mg->material != kXVkMaterialEmissive && mg->material != kXVkMaterialEmissiveGlow) {
mg->material = kXVkMaterialEmissive;
VectorCopy(args.model->color, mg->emissive);
}
Expand Down Expand Up @@ -517,7 +517,7 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render
vk_render_geometry_t *geom = render_model->geometries + i;

// FIXME an impedance mismatch: render_type is per-model, while materials and emissive color are per-geom
if (HACK_additive_emissive && geom->material != kXVkMaterialEmissive) {
if (HACK_additive_emissive && geom->material != kXVkMaterialEmissive && geom->material != kXVkMaterialEmissiveGlow) {
geom->material = kXVkMaterialEmissive;
VectorCopy(render_model->color, geom->emissive);
}
Expand Down
1 change: 1 addition & 0 deletions ref/vk/vk_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef enum {
kXVkMaterialWater,
kXVkMaterialSky,
kXVkMaterialEmissive,
kXVkMaterialEmissiveGlow,
kXVkMaterialConveyor,
kXVkMaterialChrome,
} XVkMaterialType;
Expand Down
2 changes: 1 addition & 1 deletion ref/vk/vk_sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec
{
const vk_render_geometry_t geometry = {
.texture = texture,
.material = kXVkMaterialEmissive,
.material = render_mode == kRenderGlow ? kXVkMaterialEmissiveGlow : kXVkMaterialEmissive,

.max_vertex = 4,
.vertex_offset = buffer.vertices.unit_offset,
Expand Down

0 comments on commit 59e8a8c

Please sign in to comment.