Merge pull request #105249 from Repiteo/core/math-defs-namespace

Core: Use `Math` namespace for constants
This commit is contained in:
Thaddeus Crews
2025-04-11 09:51:04 -05:00
181 changed files with 812 additions and 818 deletions

View File

@ -60,7 +60,7 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
final_cutoff = 1; //don't allow less than this
}
double omega = Math_TAU * final_cutoff / sampling_rate;
double omega = Math::TAU * final_cutoff / sampling_rate;
double sin_v = Math::sin(omega);
double cos_v = Math::cos(omega);
@ -134,7 +134,7 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
double hicutoff = resonance;
double centercutoff = (cutoff + resonance) / 2.0;
double bandwidth = (Math::log(centercutoff) - Math::log(hicutoff)) / Math::log((double)2);
omega = Math_TAU * centercutoff / sampling_rate;
omega = Math::TAU * centercutoff / sampling_rate;
alpha = Math::sin(omega) * Math::sinh(Math::log((double)2) / 2 * bandwidth * omega / Math::sin(omega));
a0 = 1 + alpha;
@ -191,7 +191,7 @@ void AudioFilterSW::set_stages(int p_stages) {
/* Fourier transform kernel to obtain response */
float AudioFilterSW::get_response(float p_freq, Coeffs *p_coeffs) {
float freq = p_freq / sampling_rate * Math_TAU;
float freq = p_freq / sampling_rate * Math::TAU;
float cx = p_coeffs->b0, cy = 0.0;

View File

@ -84,7 +84,7 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A
if (v.cutoff == 0) {
continue;
}
float auxlp = expf(-Math_TAU * v.cutoff / mix_rate);
float auxlp = expf(-Math::TAU * v.cutoff / mix_rate);
float c1 = 1.0 - auxlp;
float c2 = auxlp;
AudioFrame h = filter_h[vc];
@ -104,7 +104,7 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A
float phase = (float)(local_cycles & AudioEffectChorus::CYCLES_MASK) / (float)(1 << AudioEffectChorus::CYCLES_FRAC);
float wave_delay = sinf(phase * Math_TAU) * max_depth_frames;
float wave_delay = sinf(phase * Math::TAU) * max_depth_frames;
int wave_delay_frames = lrint(floor(wave_delay));
float wave_delay_frac = wave_delay - (float)wave_delay_frames;

View File

@ -73,7 +73,7 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au
tap2_vol.right *= CLAMP(1.0 + base->tap_2_pan, 0, 1);
// feedback lowpass here
float lpf_c = expf(-Math_TAU * base->feedback_lowpass / mix_rate); // 0 .. 10khz
float lpf_c = expf(-Math::TAU * base->feedback_lowpass / mix_rate); // 0 .. 10khz
float lpf_ic = 1.0 - lpf_c;
const AudioFrame *src = p_src_frames;

View File

@ -36,8 +36,8 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi
const float *src = (const float *)p_src_frames;
float *dst = (float *)p_dst_frames;
//float lpf_c=expf(-Math_TAU*keep_hf_hz.get()/(mix_rate*(float)OVERSAMPLE));
float lpf_c = expf(-Math_TAU * base->keep_hf_hz / (AudioServer::get_singleton()->get_mix_rate()));
//float lpf_c=expf(-Math::TAU*keep_hf_hz.get()/(mix_rate*(float)OVERSAMPLE));
float lpf_c = expf(-Math::TAU * base->keep_hf_hz / (AudioServer::get_singleton()->get_mix_rate()));
float lpf_ic = 1.0 - lpf_c;
float drive_f = base->drive;

View File

@ -37,13 +37,13 @@ void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames, AudioFra
float dmin = base->range_min / (sampling_rate / 2.0);
float dmax = base->range_max / (sampling_rate / 2.0);
float increment = Math_TAU * (base->rate / sampling_rate);
float increment = Math::TAU * (base->rate / sampling_rate);
for (int i = 0; i < p_frame_count; i++) {
phase += increment;
while (phase >= Math_TAU) {
phase -= Math_TAU;
while (phase >= Math::TAU) {
phase -= Math::TAU;
}
float d = dmin + (dmax - dmin) * ((sin(phase) + 1.f) / 2.f);

View File

@ -92,7 +92,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
fftFrameSize2 = fftFrameSize/2;
stepSize = fftFrameSize/osamp;
freqPerBin = sampleRate/(double)fftFrameSize;
expct = 2.*Math_PI*(double)stepSize/(double)fftFrameSize;
expct = 2.*Math::PI*(double)stepSize/(double)fftFrameSize;
inFifoLatency = fftFrameSize-stepSize;
if (gRover == 0) { gRover = inFifoLatency;
}
@ -112,7 +112,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
/* do windowing and re,im interleave */
for (k = 0; k < fftFrameSize;k++) {
window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5;
window = -.5*cos(2.*Math::PI*(double)k/(double)fftFrameSize)+.5;
gFFTworksp[2*k] = gInFIFO[k] * window;
gFFTworksp[2*k+1] = 0.;
}
@ -140,14 +140,14 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
tmp -= (double)k*expct;
/* map delta phase into +/- Pi interval */
qpd = tmp/Math_PI;
qpd = tmp/Math::PI;
if (qpd >= 0) { qpd += qpd&1;
} else { qpd -= qpd&1;
}
tmp -= Math_PI*(double)qpd;
tmp -= Math::PI*(double)qpd;
/* get deviation from bin frequency from the +/- Pi interval */
tmp = osamp*tmp/(2.*Math_PI);
tmp = osamp*tmp/(2.*Math::PI);
/* compute the k-th partials' true frequency */
tmp = (double)k*freqPerBin + tmp*freqPerBin;
@ -184,7 +184,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
tmp /= freqPerBin;
/* take osamp into account */
tmp = 2.*Math_PI*tmp/osamp;
tmp = 2.*Math::PI*tmp/osamp;
/* add the overlap phase advance back in */
tmp += (double)k*expct;
@ -207,7 +207,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
/* do windowing and add to output accumulator */
for(k=0; k < fftFrameSize; k++) {
window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5;
window = -.5*cos(2.*Math::PI*(double)k/(double)fftFrameSize)+.5;
gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp);
}
for (k = 0; k < stepSize; k++) { gOutFIFO[k] = gOutputAccum[k];
@ -260,7 +260,7 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign)
le2 = le>>1;
ur = 1.0;
ui = 0.0;
arg = Math_PI / (le2>>1);
arg = Math::PI / (le2>>1);
wr = cos(arg);
wi = sign*sin(arg);
for (j = 0; j < le2; j += 2) {

View File

@ -71,7 +71,7 @@ static void smbFft(float *fftBuffer, long fftFrameSize, long sign)
le2 = le >> 1;
ur = 1.0;
ui = 0.0;
arg = Math_PI / (le2 >> 1);
arg = Math::PI / (le2 >> 1);
wr = cos(arg);
wi = sign * sin(arg);
for (j = 0; j < le2; j += 2) {
@ -110,7 +110,7 @@ void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames
while (p_frame_count) {
int to_fill = fft_size * 2 - temporal_fft_pos;
to_fill = MIN(to_fill, p_frame_count);
const double to_fill_step = Math_TAU / (double)fft_size;
const double to_fill_step = Math::TAU / (double)fft_size;
float *fftw = temporal_fft.ptrw();
for (int i = 0; i < to_fill; i++) { //left and right buffers

View File

@ -88,9 +88,9 @@ void EQ::recalculate_band_coefficients() {
double frq_l = round(frq / pow(2.0, octave_size / 2.0));
double side_gain2 = POW2(Math_SQRT12);
double th = Math_TAU * frq / mix_rate;
double th_l = Math_TAU * frq_l / mix_rate;
double side_gain2 = POW2(Math::SQRT12);
double th = Math::TAU * frq / mix_rate;
double th_l = Math::TAU * frq_l / mix_rate;
double c2a = side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) + side_gain2 - POW2(sin(th_l));

View File

@ -90,7 +90,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) {
}
if (params.hpf > 0) {
float hpaux = expf(-Math_TAU * params.hpf * 6000 / params.mix_rate);
float hpaux = expf(-Math::TAU * params.hpf * 6000 / params.mix_rate);
float hp_a1 = (1.0 + hpaux) / 2.0;
float hp_a2 = -(1.0 + hpaux) / 2.0;
float hp_b1 = hpaux;
@ -292,7 +292,7 @@ void Reverb::update_parameters() {
float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough)
auxdmp *= auxdmp;
c.damp = expf(-Math_TAU * auxdmp * 10000 / params.mix_rate); // 0 .. 10khz
c.damp = expf(-Math::TAU * auxdmp * 10000 / params.mix_rate); // 0 .. 10khz
}
}

View File

@ -1440,7 +1440,7 @@ void RendererCanvasCull::canvas_item_add_circle(RID p_item, const Point2 &p_pos,
// Store circle center in the last point.
points_ptr[circle_segments + 1] = p_pos;
const real_t circle_point_step = Math_TAU / circle_segments;
const real_t circle_point_step = Math::TAU / circle_segments;
for (int i = 0; i < circle_segments + 1; i++) {
float angle = i * circle_point_step;
@ -1484,7 +1484,7 @@ void RendererCanvasCull::canvas_item_add_circle(RID p_item, const Point2 &p_pos,
points.resize(2 * circle_segments + 2);
colors.resize(2 * circle_segments + 2);
const real_t circle_point_step = Math_TAU / circle_segments;
const real_t circle_point_step = Math::TAU / circle_segments;
Vector2 *points_ptr = points.ptrw();
Color *colors_ptr = colors.ptrw();

View File

@ -81,7 +81,7 @@ SSEffects::SSEffects() {
int b = spmap[subPass];
float ca, sa;
float angle0 = (float(a) + float(b) / float(sub_pass_count)) * Math_PI * 0.5f;
float angle0 = (float(a) + float(b) / float(sub_pass_count)) * Math::PI * 0.5f;
ca = Math::cos(angle0);
sa = Math::sin(angle0);
@ -706,7 +706,7 @@ void SSEffects::screen_space_indirect_lighting(Ref<RenderSceneBuffersRD> p_rende
}
}
radius_near_limit /= tan_half_fov_y;
ssil.gather_push_constant.intensity = p_settings.intensity * Math_PI;
ssil.gather_push_constant.intensity = p_settings.intensity * Math::PI;
ssil.gather_push_constant.fade_out_mul = -1.0 / (ssil_fadeout_to - ssil_fadeout_from);
ssil.gather_push_constant.fade_out_add = ssil_fadeout_from / (ssil_fadeout_to - ssil_fadeout_from) + 1.0;
ssil.gather_push_constant.inv_radius_near_limit = 1.0f / radius_near_limit;
@ -788,7 +788,7 @@ void SSEffects::screen_space_indirect_lighting(Ref<RenderSceneBuffersRD> p_rende
RD::get_singleton()->draw_command_begin_label("Generate Importance Map");
ssil.importance_map_push_constant.half_screen_pixel_size[0] = 1.0 / p_ssil_buffers.buffer_width;
ssil.importance_map_push_constant.half_screen_pixel_size[1] = 1.0 / p_ssil_buffers.buffer_height;
ssil.importance_map_push_constant.intensity = p_settings.intensity * Math_PI;
ssil.importance_map_push_constant.intensity = p_settings.intensity * Math::PI;
//base pass
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssil.pipelines[SSIL_GATHER_BASE]);

View File

@ -205,9 +205,9 @@ void Fog::init_fog_shader(uint32_t p_max_directional_lights, int p_roughness_lay
ShaderCompiler::DefaultIdentifierActions actions;
actions.renames["TIME"] = "scene_params.time";
actions.renames["PI"] = _MKSTR(Math_PI);
actions.renames["TAU"] = _MKSTR(Math_TAU);
actions.renames["E"] = _MKSTR(Math_E);
actions.renames["PI"] = _MKSTR(Math::PI);
actions.renames["TAU"] = _MKSTR(Math::TAU);
actions.renames["E"] = _MKSTR(Math::E);
actions.renames["WORLD_POSITION"] = "world.xyz";
actions.renames["OBJECT_POSITION"] = "params.position";
actions.renames["UVW"] = "uvw";

View File

@ -1674,7 +1674,7 @@ void GI::SDFGI::debug_probes(RID p_framebuffer, const uint32_t p_view_count, con
push_constant.band_power = 4;
push_constant.sections_in_band = ((band_points / 2) - 1);
push_constant.band_mask = band_points - 2;
push_constant.section_arc = Math_TAU / float(push_constant.sections_in_band);
push_constant.section_arc = Math::TAU / float(push_constant.sections_in_band);
push_constant.y_mult = y_mult;
uint32_t total_points = push_constant.sections_in_band * band_points;
@ -1977,11 +1977,11 @@ void GI::SDFGI::pre_process_gi(const Transform3D &p_transform, RenderDataRD *p_r
// Convert from Luminous Power to Luminous Intensity
if (lights[idx].type == RS::LIGHT_OMNI) {
lights[idx].energy *= 1.0 / (Math_PI * 4.0);
lights[idx].energy *= 1.0 / (Math::PI * 4.0);
} else if (lights[idx].type == RS::LIGHT_SPOT) {
// Spot Lights are not physically accurate, Luminous Intensity should change in relation to the cone angle.
// We make this assumption to keep them easy to control.
lights[idx].energy *= 1.0 / Math_PI;
lights[idx].energy *= 1.0 / Math::PI;
}
}
@ -2440,11 +2440,11 @@ void GI::SDFGI::render_static_lights(RenderDataRD *p_render_data, Ref<RenderScen
// Convert from Luminous Power to Luminous Intensity
if (lights[idx].type == RS::LIGHT_OMNI) {
lights[idx].energy *= 1.0 / (Math_PI * 4.0);
lights[idx].energy *= 1.0 / (Math::PI * 4.0);
} else if (lights[idx].type == RS::LIGHT_SPOT) {
// Spot Lights are not physically accurate, Luminous Intensity should change in relation to the cone angle.
// We make this assumption to keep them easy to control.
lights[idx].energy *= 1.0 / Math_PI;
lights[idx].energy *= 1.0 / Math::PI;
}
}
@ -2906,11 +2906,11 @@ void GI::VoxelGIInstance::update(bool p_update_light_instances, const Vector<RID
// Convert from Luminous Power to Luminous Intensity
if (l.type == RS::LIGHT_OMNI) {
l.energy *= 1.0 / (Math_PI * 4.0);
l.energy *= 1.0 / (Math::PI * 4.0);
} else if (l.type == RS::LIGHT_SPOT) {
// Spot Lights are not physically accurate, Luminous Intensity should change in relation to the cone angle.
// We make this assumption to keep them easy to control.
l.energy *= 1.0 / Math_PI;
l.energy *= 1.0 / Math::PI;
}
}

View File

@ -783,9 +783,9 @@ void SkyRD::init() {
actions.renames["SCREEN_UV"] = "uv";
actions.renames["FRAGCOORD"] = "gl_FragCoord";
actions.renames["TIME"] = "params.time";
actions.renames["PI"] = _MKSTR(Math_PI);
actions.renames["TAU"] = _MKSTR(Math_TAU);
actions.renames["E"] = _MKSTR(Math_E);
actions.renames["PI"] = _MKSTR(Math::PI);
actions.renames["TAU"] = _MKSTR(Math::TAU);
actions.renames["E"] = _MKSTR(Math::E);
actions.renames["HALF_RES_COLOR"] = "half_res_color";
actions.renames["QUARTER_RES_COLOR"] = "quarter_res_color";
actions.renames["RADIANCE"] = "radiance";

View File

@ -618,9 +618,9 @@ void SceneShaderForwardClustered::init(const String p_defines) {
actions.renames["TIME"] = "global_time";
actions.renames["EXPOSURE"] = "(1.0 / scene_data_block.data.emissive_exposure_normalization)";
actions.renames["PI"] = _MKSTR(Math_PI);
actions.renames["TAU"] = _MKSTR(Math_TAU);
actions.renames["E"] = _MKSTR(Math_E);
actions.renames["PI"] = _MKSTR(Math::PI);
actions.renames["TAU"] = _MKSTR(Math::TAU);
actions.renames["E"] = _MKSTR(Math::E);
actions.renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
actions.renames["CLIP_SPACE_FAR"] = "SHADER_SPACE_FAR";
actions.renames["VIEWPORT_SIZE"] = "read_viewport_size";

View File

@ -552,9 +552,9 @@ void SceneShaderForwardMobile::init(const String p_defines) {
actions.renames["TIME"] = "scene_data_block.data.time";
actions.renames["EXPOSURE"] = "(1.0 / scene_data_block.data.emissive_exposure_normalization)";
actions.renames["PI"] = _MKSTR(Math_PI);
actions.renames["TAU"] = _MKSTR(Math_TAU);
actions.renames["E"] = _MKSTR(Math_E);
actions.renames["PI"] = _MKSTR(Math::PI);
actions.renames["TAU"] = _MKSTR(Math::TAU);
actions.renames["E"] = _MKSTR(Math::E);
actions.renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
actions.renames["CLIP_SPACE_FAR"] = "SHADER_SPACE_FAR";
actions.renames["VIEWPORT_SIZE"] = "read_viewport_size";

View File

@ -1773,9 +1773,9 @@ RendererCanvasRenderRD::RendererCanvasRenderRD() {
actions.renames["CANVAS_MATRIX"] = "canvas_data.canvas_transform";
actions.renames["SCREEN_MATRIX"] = "canvas_data.screen_transform";
actions.renames["TIME"] = "canvas_data.time";
actions.renames["PI"] = _MKSTR(Math_PI);
actions.renames["TAU"] = _MKSTR(Math_TAU);
actions.renames["E"] = _MKSTR(Math_E);
actions.renames["PI"] = _MKSTR(Math::PI);
actions.renames["TAU"] = _MKSTR(Math::TAU);
actions.renames["E"] = _MKSTR(Math::E);
actions.renames["AT_LIGHT_PASS"] = "false";
actions.renames["INSTANCE_CUSTOM"] = "instance_custom";

View File

@ -643,7 +643,7 @@ void LightStorage::update_light_buffers(RenderDataRD *p_render_data, const Paged
if (RendererSceneRenderRD::get_singleton()->is_using_physical_light_units()) {
light_data.energy *= light->param[RS::LIGHT_PARAM_INTENSITY];
} else {
light_data.energy *= Math_PI;
light_data.energy *= Math::PI;
}
if (p_render_data->camera_attributes.is_valid()) {
@ -866,14 +866,14 @@ void LightStorage::update_light_buffers(RenderDataRD *p_render_data, const Paged
// Convert from Luminous Power to Luminous Intensity
if (type == RS::LIGHT_OMNI) {
energy *= 1.0 / (Math_PI * 4.0);
energy *= 1.0 / (Math::PI * 4.0);
} else {
// Spot Lights are not physically accurate, Luminous Intensity should change in relation to the cone angle.
// We make this assumption to keep them easy to control.
energy *= 1.0 / Math_PI;
energy *= 1.0 / Math::PI;
}
} else {
energy *= Math_PI;
energy *= Math::PI;
}
if (p_render_data->camera_attributes.is_valid()) {

View File

@ -80,9 +80,9 @@ ParticlesStorage::ParticlesStorage() {
}
actions.renames["TRANSFORM"] = "PARTICLE.xform";
actions.renames["TIME"] = "frame_history.data[0].time";
actions.renames["PI"] = _MKSTR(Math_PI);
actions.renames["TAU"] = _MKSTR(Math_TAU);
actions.renames["E"] = _MKSTR(Math_E);
actions.renames["PI"] = _MKSTR(Math::PI);
actions.renames["TAU"] = _MKSTR(Math::TAU);
actions.renames["E"] = _MKSTR(Math::E);
actions.renames["LIFETIME"] = "params.lifetime";
actions.renames["DELTA"] = "local_delta";
actions.renames["NUMBER"] = "particle_number";

View File

@ -240,15 +240,15 @@ RID RenderingServer::_make_test_cube() {
RID RenderingServer::make_sphere_mesh(int p_lats, int p_lons, real_t p_radius) {
Vector<Vector3> vertices;
Vector<Vector3> normals;
const double lat_step = Math_TAU / p_lats;
const double lon_step = Math_TAU / p_lons;
const double lat_step = Math::TAU / p_lats;
const double lon_step = Math::TAU / p_lons;
for (int i = 1; i <= p_lats; i++) {
double lat0 = lat_step * (i - 1) - Math_TAU / 4;
double lat0 = lat_step * (i - 1) - Math::TAU / 4;
double z0 = Math::sin(lat0);
double zr0 = Math::cos(lat0);
double lat1 = lat_step * i - Math_TAU / 4;
double lat1 = lat_step * i - Math::TAU / 4;
double z1 = Math::sin(lat1);
double zr1 = Math::cos(lat1);
@ -327,9 +327,9 @@ void _get_axis_angle(const Vector3 &p_normal, const Vector4 &p_tangent, float &r
r_angle = float(angle);
if (d < 0.0) {
r_angle = CLAMP((1.0 - r_angle / Math_PI) * 0.5, 0.0, 0.49999);
r_angle = CLAMP((1.0 - r_angle / Math::PI) * 0.5, 0.0, 0.49999);
} else {
r_angle = CLAMP((r_angle / Math_PI) * 0.5 + 0.5, 0.500008, 1.0);
r_angle = CLAMP((r_angle / Math::PI) * 0.5 + 0.5, 0.500008, 1.0);
}
}
@ -337,7 +337,7 @@ void _get_axis_angle(const Vector3 &p_normal, const Vector4 &p_tangent, float &r
// and p_angle includes the binormal direction.
void _get_tbn_from_axis_angle(const Vector3 &p_axis, float p_angle, Vector3 &r_normal, Vector4 &r_tangent) {
float binormal_sign = p_angle > 0.5 ? 1.0 : -1.0;
float angle = Math::abs(p_angle * 2.0 - 1.0) * Math_PI;
float angle = Math::abs(p_angle * 2.0 - 1.0) * Math::PI;
Basis tbn = Basis(p_axis, angle);
Vector3 tan = tbn.rows[0];