From d8d5019971ed48540b0e0bc022dd3aa7275abef8 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Tue, 5 Sep 2023 12:06:59 -0400 Subject: [PATCH] vk: filter smoothing normals by texture thanks to G.I.F --- ref/vk/vk_brush.c | 20 +++++++++++++++++--- ref/vk/vk_mapents.c | 4 ++-- ref/vk/vk_mapents.h | 4 +++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index dcf2f4f6..eaba8753 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -799,18 +799,32 @@ static void getSurfaceNormal( const msurface_t *surf, vec3_t out_normal) { //VectorScale(normal, surf->plane. } +static int getSurfaceTexture(const msurface_t *surf, int surface_index) { + const xvk_patch_surface_t *const psurf = R_VkPatchGetSurface(surface_index); + if (psurf && psurf->tex_id >= 0) + return psurf->tex_id; + return surf->texinfo->texture->gl_texturenum; +} + static qboolean shouldSmoothLinkSurfaces(const model_t* mod, int surf1, int surf2) { //return Q_min(surf1, surf2) == 741 && Q_max(surf1, surf2) == 743; + // TODO patch filtering + + // Do not join surfaces with different textures. Assume they belong to different objects. + const int t1 = getSurfaceTexture(mod->surfaces + surf1, surf1); + const int t2 = getSurfaceTexture(mod->surfaces + surf2, surf2); + if (t1 != t2) + return false; + vec3_t n1, n2; getSurfaceNormal(mod->surfaces + surf1, n1); getSurfaceNormal(mod->surfaces + surf2, n2); - // TODO patch filtering const float dot = DotProduct(n1, n2); - DEBUG("Smoothing: dot(%d, %d) = %f (t=%f)", surf1, surf2, dot, g_map_entities.smoothing_threshold); + DEBUG("Smoothing: dot(%d, %d) = %f (t=%f)", surf1, surf2, dot, g_map_entities.smoothing.threshold); - return dot >= g_map_entities.smoothing_threshold; + return dot >= g_map_entities.smoothing.threshold; } static int lvFindValue(const linked_value_t *li, int count, int needle) { diff --git a/ref/vk/vk_mapents.c b/ref/vk/vk_mapents.c index 4833603f..a884431e 100644 --- a/ref/vk/vk_mapents.c +++ b/ref/vk/vk_mapents.c @@ -571,7 +571,7 @@ static void parseEntities( char *string, qboolean is_patch ) { } else if (have_fields & Field__xvk_ent_id) { patchEntity( &values, have_fields ); } else if (have_fields & Field__xvk_smoothing_threshold) { - g_map_entities.smoothing_threshold = cosf(DEG2RAD(values._xvk_smoothing_threshold)); + g_map_entities.smoothing.threshold = cosf(DEG2RAD(values._xvk_smoothing_threshold)); } } break; @@ -678,7 +678,7 @@ void XVK_ParseMapEntities( void ) { g_map_entities.single_environment_index = NoEnvironmentLights; g_map_entities.entity_count = 0; g_map_entities.func_walls_count = 0; - g_map_entities.smoothing_threshold = cosf(DEG2RAD(45.f)); + g_map_entities.smoothing.threshold = cosf(DEG2RAD(45.f)); parseEntities( map->entities, false ); orientSpotlights(); diff --git a/ref/vk/vk_mapents.h b/ref/vk/vk_mapents.h index e3e07ab0..68278174 100644 --- a/ref/vk/vk_mapents.h +++ b/ref/vk/vk_mapents.h @@ -130,7 +130,9 @@ typedef struct { //#define MAX_MAP_ENTITIES 2048 xvk_mapent_ref_t refs[MAX_MAP_ENTITIES]; - float smoothing_threshold; + struct { + float threshold; + } smoothing; } xvk_map_entities_t; extern xvk_map_entities_t g_map_entities;