Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions doc/client.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,41 @@ r_bloomBlurRadius::
defined in pixels at 1080p and scale with the framebuffer size. Default
value is 12.

r_bloomThreshold::
r_bloomBlurScale::
Multiplier applied to the configured blur radius after it is scaled to the
current framebuffer size. Values greater than 1.0 widen the blur while
values below 1.0 tighten it. Default value is 1.0.

r_bloomBlurFalloff::
Controls how quickly the gaussian blur weights fall off from the center of
the kernel. Lower values spread bloom over a larger area; higher values
keep highlights tighter. Default value is 0.75.

r_bloomBrightThreshold::
Minimum luminance for a fragment to contribute to bloom. Fragments below
this threshold are ignored during the bright-pass filter. Default value is
0.8.
0.8. (The legacy ``r_bloomThreshold`` alias is kept for compatibility.)

r_bloomIntensity::
Scales the intensity of the bloom contribution before it is blended back
into the scene. Default value is 1.0.

r_bloomPasses::
Number of blur iterations applied to the bloom buffer. Higher values
produce a softer glow at the cost of performance. Default value is 2.

r_bloomSaturation::
Adjusts saturation of the bloom highlights prior to compositing. Default
value is 1.0.

r_bloomSceneSaturation::
Adjusts saturation of the final scene after bloom and post-processing are
applied. Default value is 1.0.

r_colorCorrection::
Strength of the ACES-inspired color correction applied during the final
post-processing pass. Set to 0 to disable the correction. Default value is
0.

gl_flarespeed::
Specifies flare fading effect speed. Default value is 8. Set this to 0
Expand Down
18 changes: 15 additions & 3 deletions src/refresh/gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ typedef struct {
GLsync sync;
float entity_modulate;
float bloom_sigma;
float bloom_falloff;
uint32_t inverse_intensity_33;
uint32_t inverse_intensity_66;
uint32_t inverse_intensity_100;
Expand Down Expand Up @@ -399,7 +400,14 @@ extern cvar_t *gl_damageblend_frac;
extern cvar_t *r_skipUnderWaterFX;
extern cvar_t *r_bloom;
extern cvar_t *r_bloomBlurRadius;
extern cvar_t *r_bloomThreshold;
extern cvar_t *r_bloomBlurScale;
extern cvar_t *r_bloomBlurFalloff;
extern cvar_t *r_bloomBrightThreshold;
extern cvar_t *r_bloomIntensity;
extern cvar_t *r_bloomPasses;
extern cvar_t *r_bloomSaturation;
extern cvar_t *r_bloomSceneSaturation;
extern cvar_t *r_colorCorrection;
extern cvar_t *gl_dof;

// development variables
Expand Down Expand Up @@ -713,6 +721,7 @@ void GL_LoadWorld(const char *name);
#define GLS_BOKEH_DOWNSAMPLE BIT_ULL(38)
#define GLS_BOKEH_GATHER BIT_ULL(39)
#define GLS_BOKEH_COMBINE BIT_ULL(40)
#define GLS_COLOR_CORRECTION BIT_ULL(41)

#define GLS_BLEND_MASK (GLS_BLEND_BLEND | GLS_BLEND_ADD | GLS_BLEND_MODULATE)
#define GLS_BOKEH_MASK (GLS_BOKEH_COC | GLS_BOKEH_INITIAL | GLS_BOKEH_DOWNSAMPLE | GLS_BOKEH_GATHER | GLS_BOKEH_COMBINE)
Expand All @@ -726,9 +735,10 @@ void GL_LoadWorld(const char *name);
#define GLS_SHADER_MASK (GLS_ALPHATEST_ENABLE | GLS_TEXTURE_REPLACE | GLS_SCROLL_ENABLE | \
GLS_LIGHTMAP_ENABLE | GLS_WARP_ENABLE | GLS_INTENSITY_ENABLE | \
GLS_GLOWMAP_ENABLE | GLS_SKY_MASK | GLS_DEFAULT_FLARE | GLS_MESH_MASK | \
GLS_FOG_MASK | GLS_BLOOM_MASK | GLS_BLUR_MASK | GLS_DYNAMIC_LIGHTS | GLS_BOKEH_MASK)
GLS_FOG_MASK | GLS_BLOOM_MASK | GLS_BLUR_MASK | GLS_DYNAMIC_LIGHTS | GLS_BOKEH_MASK | GLS_COLOR_CORRECTION)
#define GLS_UNIFORM_MASK (GLS_WARP_ENABLE | GLS_LIGHTMAP_ENABLE | GLS_INTENSITY_ENABLE | \
GLS_SKY_MASK | GLS_FOG_MASK | GLS_BLOOM_BRIGHTPASS | GLS_BLUR_MASK | GLS_DYNAMIC_LIGHTS | GLS_BOKEH_MASK)
GLS_SKY_MASK | GLS_FOG_MASK | GLS_BLOOM_BRIGHTPASS | GLS_BLOOM_OUTPUT | \
GLS_BLUR_MASK | GLS_DYNAMIC_LIGHTS | GLS_BOKEH_MASK | GLS_COLOR_CORRECTION)
#define GLS_SCROLL_MASK (GLS_SCROLL_ENABLE | GLS_SCROLL_X | GLS_SCROLL_Y | GLS_SCROLL_FLIP | GLS_SCROLL_SLOW)

typedef enum {
Expand Down Expand Up @@ -829,6 +839,8 @@ typedef struct {
vec4_t dof_params;
vec4_t dof_screen;
vec4_t dof_depth;
vec4_t bloom_params;
vec4_t bloom_color;
vec4_t vieworg;
} glUniformBlock_t;

Expand Down
70 changes: 65 additions & 5 deletions src/refresh/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,41 @@ cvar_t *r_skipUnderWaterFX;
cvar_t *r_enablefog;
cvar_t *r_bloom;
cvar_t *r_bloomBlurRadius;
cvar_t *r_bloomThreshold;
cvar_t *r_bloomBlurScale;
cvar_t *r_bloomBlurFalloff;
cvar_t *r_bloomBrightThreshold;
cvar_t *r_bloomIntensity;
cvar_t *r_bloomPasses;
cvar_t *r_bloomSaturation;
cvar_t *r_bloomSceneSaturation;
cvar_t *r_colorCorrection;

static cvar_t *r_bloomThresholdLegacy;
static bool bloom_threshold_sync = false;

static void r_bloom_threshold_primary_changed(cvar_t *self)
{
(void)self;

if (!r_bloomBrightThreshold || bloom_threshold_sync)
return;

if (r_bloomThresholdLegacy) {
bloom_threshold_sync = true;
Cvar_SetValue(r_bloomThresholdLegacy, r_bloomBrightThreshold->value, FROM_CODE);
bloom_threshold_sync = false;
}
}

static void r_bloom_threshold_alias_changed(cvar_t *self)
{
if (!self || !r_bloomBrightThreshold || bloom_threshold_sync)
return;

bloom_threshold_sync = true;
Cvar_SetValue(r_bloomBrightThreshold, self->value, FROM_CODE);
bloom_threshold_sync = false;
}
cvar_t *gl_dof;
cvar_t *gl_swapinterval;

Expand Down Expand Up @@ -868,6 +902,10 @@ static void GL_DrawDepthOfField(pp_flags_t flags)
glStateBits_t bits = GLS_DEFAULT;
if (waterwarp)
bits |= GLS_WARP_ENABLE;
if (R_ColorCorrectionActive()) {
bits |= GLS_COLOR_CORRECTION;
R_SetPostProcessUniforms(0.0f, 0.0f);
}

GL_ForceTexture(TMU_TEXTURE, TEXNUM_PP_DOF_RESULT);

Expand All @@ -878,20 +916,22 @@ static void GL_DrawDepthOfField(pp_flags_t flags)
static int32_t r_skipUnderWaterFX_modified = 0;
static int32_t r_bloom_modified = 0;
static int32_t gl_dof_modified = 0;
static int32_t r_colorCorrection_modified = 0;

static pp_flags_t GL_BindFramebuffer(void)
{
pp_flags_t flags = PP_NONE;
bool resized = false;
const bool dof_active = gl_dof->integer && glr.fd.depth_of_field;
const bool colorCorrection = R_ColorCorrectionActive();

if (!gl_static.use_shaders)
return PP_NONE;

if ((glr.fd.rdflags & RDF_UNDERWATER) && !r_skipUnderWaterFX->integer)
flags |= PP_WATERWARP;

if (!(glr.fd.rdflags & RDF_NOWORLDMODEL) && r_bloom->integer)
if (!(glr.fd.rdflags & RDF_NOWORLDMODEL) && (r_bloom->integer || colorCorrection))
flags |= PP_BLOOM;

if (dof_active)
Expand All @@ -902,13 +942,16 @@ static pp_flags_t GL_BindFramebuffer(void)

if (resized || r_skipUnderWaterFX->modified_count != r_skipUnderWaterFX_modified ||
r_bloom->modified_count != r_bloom_modified ||
gl_dof->modified_count != gl_dof_modified) {
gl_dof->modified_count != gl_dof_modified ||
(r_colorCorrection && r_colorCorrection->modified_count != r_colorCorrection_modified)) {
glr.framebuffer_ok = GL_InitFramebuffers();
glr.framebuffer_width = glr.fd.width;
glr.framebuffer_height = glr.fd.height;
r_skipUnderWaterFX_modified = r_skipUnderWaterFX->modified_count;
r_bloom_modified = r_bloom->modified_count;
gl_dof_modified = gl_dof->modified_count;
if (r_colorCorrection)
r_colorCorrection_modified = r_colorCorrection->modified_count;
if (flags & PP_BLOOM)
gl_backend->update_blur();
}
Expand Down Expand Up @@ -1269,8 +1312,25 @@ static void GL_Register(void)
r_skipUnderWaterFX = Cvar_Get("r_skipUnderWaterFX", "0", 0);
r_enablefog = Cvar_Get("r_enablefog", "1", 0);
r_bloom = Cvar_Get("r_bloom", "1", 0);
r_bloomBlurRadius = Cvar_Get("r_bloomBlurRadius", "2.0", 0);
r_bloomThreshold = Cvar_Get("r_bloomThreshold", "0.1", 0);
r_bloomBlurRadius = Cvar_Get("r_bloomBlurRadius", "12", 0);
r_bloomBlurScale = Cvar_Get("r_bloomBlurScale", "1.0", 0);
r_bloomBlurFalloff = Cvar_Get("r_bloomBlurFalloff", "0.75", 0);
r_bloomBrightThreshold = Cvar_Get("r_bloomBrightThreshold", "0.8", 0);
r_bloomIntensity = Cvar_Get("r_bloomIntensity", "1.0", 0);
r_bloomPasses = Cvar_Get("r_bloomPasses", "2", 0);
r_bloomSaturation = Cvar_Get("r_bloomSaturation", "1.0", 0);
r_bloomSceneSaturation = Cvar_Get("r_bloomSceneSaturation", "1.0", 0);
r_colorCorrection = Cvar_Get("r_colorCorrection", "0", 0);
r_bloomThresholdLegacy = Cvar_Get("r_bloomThreshold", "0.8", 0);

if (r_bloomBrightThreshold)
r_bloomBrightThreshold->changed = r_bloom_threshold_primary_changed;
if (r_bloomThresholdLegacy)
r_bloomThresholdLegacy->changed = r_bloom_threshold_alias_changed;
r_bloom_threshold_primary_changed(r_bloomBrightThreshold);

if (r_colorCorrection)
r_colorCorrection_modified = r_colorCorrection->modified_count;
gl_dof = Cvar_Get("gl_dof", "1", 0);
gl_swapinterval = Cvar_Get("gl_swapinterval", "1", CVAR_ARCHIVE);
gl_swapinterval->changed = gl_swapinterval_changed;
Expand Down
Loading