Skip to content

Commit

Permalink
materials: Make fallback radiance (used when no BSP radiance given) a…
Browse files Browse the repository at this point in the history
…n explicit attribute
  • Loading branch information
res2k committed Apr 18, 2022
1 parent 1883f51 commit c8d6aa8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/refresh/vkpt/bsp_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/refresh/vkpt/material.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/refresh/vkpt/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c8d6aa8

Please sign in to comment.