Add simple sound occusion based on YQ2 AL EFX code

Can be disabled via s_occlusion 0, strength is modified
via s_occlusion_strength (higher values are actually less occlusion).

Cherrypick of b557494e14
This commit is contained in:
SkacikPL 2022-08-05 23:36:57 +03:00 committed by Denis Pauk
parent 9820aa4cb1
commit 66f1bc9a33
4 changed files with 41 additions and 0 deletions

View file

@ -266,6 +266,10 @@ Set `0` by default.
* **s_underwater**: Dampen sounds if submerged. Enabled by default.
* **s_occlusion**: If set to `1` sound occusion effects are enabled. This is only
supported by the OpenAL sound backend. By default this cvar is disabled (set to 0).
* **s_occlusion_strength**: Occlusion strength, higher values are actually less occlusion.
## Graphics (all renderers)

View file

@ -176,6 +176,8 @@ extern cvar_t *s_ambient;
extern cvar_t* s_underwater;
extern cvar_t* s_underwater_gain_hf;
extern cvar_t* s_doppler;
extern cvar_t* s_occlusion;
extern cvar_t* s_occlusion_strength;
extern cvar_t* s_ps_sorting;
/*

View file

@ -274,6 +274,37 @@ AL_Spatialize(channel_t *ch)
qalSource3f(ch->srcnum, AL_VELOCITY, AL_UnpackVector(velocity));
}
if (s_occlusion->value)
{
trace_t trace;
vec3_t mins = { 0, 0, 0 }, maxs = { 0, 0, 0 };
trace = CM_BoxTrace(origin, listener_origin, mins, maxs, 0, MASK_PLAYERSOLID);
if (trace.fraction < 1.0 &&
!(ch->entnum == -1 || ch->entnum == cl.playernum + 1 || !ch->dist_mult)
)
{
vec3_t distance;
float dist;
float final;
VectorSubtract(origin, listener_origin, distance);
dist = VectorLength(distance);
final = 1.0 - ((dist / 1000) * s_occlusion_strength->value);
qalSourcef(ch->srcnum, AL_GAIN, min(max(final, 0), 1));
if (!snd_is_underwater)
qalSourcei(ch->srcnum, AL_DIRECT_FILTER, underwaterFilter);
}
else
{
if (!snd_is_underwater)
qalSourcei(ch->srcnum, AL_DIRECT_FILTER, 0) ;
}
}
return;
}
}

View file

@ -72,6 +72,8 @@ cvar_t *s_ambient;
cvar_t* s_underwater;
cvar_t* s_underwater_gain_hf;
cvar_t* s_doppler;
cvar_t* s_occlusion;
cvar_t* s_occlusion_strength;
cvar_t* s_ps_sorting;
channel_t channels[MAX_CHANNELS];
@ -1551,6 +1553,8 @@ S_Init(void)
s_underwater = Cvar_Get("s_underwater", "1", CVAR_ARCHIVE);
s_underwater_gain_hf = Cvar_Get("s_underwater_gain_hf", "0.25", CVAR_ARCHIVE);
s_doppler = Cvar_Get("s_doppler", "0", CVAR_ARCHIVE);
s_occlusion = Cvar_Get("s_occlusion", "0", CVAR_ARCHIVE);
s_occlusion_strength = Cvar_Get("s_occlusion_strength", "0", CVAR_ARCHIVE);
s_ps_sorting = Cvar_Get("s_ps_sorting", "1", CVAR_ARCHIVE);
Cmd_AddCommand("play", S_Play);