From c8d6aa8edfcafafc93f870ec8e07d61fd004693e Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Thu, 14 Apr 2022 15:04:37 +0200 Subject: [PATCH] materials: Make fallback radiance (used when no BSP radiance given) an explicit attribute --- src/refresh/vkpt/bsp_mesh.c | 13 ++++++------- src/refresh/vkpt/material.c | 13 +++++++++++++ src/refresh/vkpt/material.h | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/refresh/vkpt/bsp_mesh.c b/src/refresh/vkpt/bsp_mesh.c index 4bc54dff8..057402692 100644 --- a/src/refresh/vkpt/bsp_mesh.c +++ b/src/refresh/vkpt/bsp_mesh.c @@ -135,15 +135,9 @@ compute_emissive(mtexinfo_t *texinfo) const float bsp_emissive = (float)texinfo->radiance * cvar_pt_bsp_radiance_scale->value; - const qboolean is_emissive_fake = texinfo->material->image_emissive && ((texinfo->material->image_emissive->flags & IF_FAKE_EMISSIVE) != 0); - - // If emissive is "fake", treat absence of SURF_LIGHT flag as "not emissive" - // If emissive is not "fake" (ie explicit image), treat absence of SURF_LIGHT flag as "fully emissive" - const float fallback_emissive = is_emissive_fake ? 0.f : 1.f; - return ((texinfo->c.flags & SURF_LIGHT) && texinfo->material->bsp_radiance) ? bsp_emissive - : fallback_emissive; + : texinfo->material->default_radiance; } #define DUMP_WORLD_MESH_TO_OBJ 0 @@ -2029,7 +2023,12 @@ bsp_mesh_register_textures(bsp_t *bsp) synth_surface_material &= !is_warp_surface; if (synth_surface_material) + { MAT_SynthesizeEmissive(mat); + /* If emissive is "fake", treat absence of BSP radiance flag as "not emissive": + * The assumption is that this is closer to the author's intention */ + mat->default_radiance = 0.0f; + } } info->material = mat; diff --git a/src/refresh/vkpt/material.c b/src/refresh/vkpt/material.c index eb3b9bb5a..7c08414c5 100644 --- a/src/refresh/vkpt/material.c +++ b/src/refresh/vkpt/material.c @@ -168,6 +168,9 @@ static void MAT_Reset(pbr_material_t * mat) mat->base_factor = 1.f; mat->light_styles = true; mat->bsp_radiance = true; + /* Treat absence of SURF_LIGHT flag as "fully emissive" by default. + * Typically works well with explicit emissive image. */ + mat->default_radiance = 1.f; mat->flags = MATERIAL_KIND_REGULAR; mat->num_frames = 1; mat->emissive_threshold = cvar_pt_surface_lights_threshold->integer; @@ -292,6 +295,7 @@ enum AttributeIndex MAT_TEXTURE_EMISSIVE, MAT_LIGHT_STYLES, MAT_BSP_RADIANCE, + MAT_DEFAULT_RADIANCE, MAT_TEXTURE_MASK, MAT_SYNTH_EMISSIVE, MAT_EMISSIVE_THRESHOLD, @@ -316,6 +320,7 @@ static struct MaterialAttribute { {MAT_TEXTURE_EMISSIVE, "texture_emissive", ATTR_STRING}, {MAT_LIGHT_STYLES, "light_styles", ATTR_BOOL}, {MAT_BSP_RADIANCE, "bsp_radiance", ATTR_BOOL}, + {MAT_DEFAULT_RADIANCE, "default_radiance", ATTR_FLOAT}, {MAT_TEXTURE_MASK, "texture_mask", ATTR_STRING}, {MAT_SYNTH_EMISSIVE, "synth_emissive", ATTR_BOOL}, {MAT_EMISSIVE_THRESHOLD, "emissive_threshold", ATTR_INT}, @@ -449,6 +454,10 @@ static int set_material_attribute(pbr_material_t* mat, const char* attribute, co mat->bsp_radiance = bvalue; if (reload_flags) *reload_flags |= RELOAD_MAP; break; + case MAT_DEFAULT_RADIANCE: + mat->default_radiance = fvalue; + if (reload_flags) *reload_flags |= RELOAD_MAP; + break; case MAT_TEXTURE_MASK: set_material_texture(mat, svalue, mat->filename_mask, &mat->image_mask, IF_NONE, !sourceFile); if (reload_flags) *reload_flags |= RELOAD_MAP; @@ -684,6 +693,9 @@ static void save_materials(const char* file_name, bool save_all, bool force) if (!mat->bsp_radiance) FS_FPrintf(file, "\tbsp_radiance 0\n"); + if (mat->default_radiance != 1.f) + FS_FPrintf(file, "\tdefault_radiance %f\n", mat->default_radiance); + if (mat->synth_emissive) FS_FPrintf(file, "\tsynth_emissive 1\n"); @@ -980,6 +992,7 @@ void MAT_Print(pbr_material_t const * mat) Com_Printf(" is_light %d\n", (mat->flags & MATERIAL_FLAG_LIGHT) != 0); Com_Printf(" light_styles %d\n", mat->light_styles ? 1 : 0); Com_Printf(" bsp_radiance %d\n", mat->bsp_radiance ? 1 : 0); + Com_Printf(" default_radiance %f\n", mat->default_radiance); Com_Printf(" synth_emissive %d\n", mat->synth_emissive ? 1 : 0); Com_Printf(" emissive_threshold %d\n", mat->emissive_threshold); } diff --git a/src/refresh/vkpt/material.h b/src/refresh/vkpt/material.h index 462c529ec..701836f7f 100644 --- a/src/refresh/vkpt/material.h +++ b/src/refresh/vkpt/material.h @@ -57,6 +57,7 @@ typedef struct pbr_material_s { int next_frame; bool light_styles; bool bsp_radiance; + float default_radiance; imageflags_t image_flags; imagetype_t image_type; bool synth_emissive;