Blender V5.3
gpu_shader_math_safe.bsl.hh File Reference

Go to the source code of this file.

Functions

Safe Math Functions
float safe_mod (float a, float b)
float safe_divide (float a, float b)
float safe_rcp (float a)
float safe_sqrt (float a)
float safe_acos (float a)
float fallback_pow (float x, float y, float fallback)
float compatible_pow (float x, float y)
float compatible_mod (float a, float b)
float wrap (float a, float b, float c)

Function Documentation

◆ compatible_mod()

float compatible_mod ( float a,
float b )

A version of mod that behaves similar to C++ std::modf, and is safe such that it returns 0 when b is also 0.

Definition at line 109 of file gpu_shader_math_safe.bsl.hh.

References b, compatible_mod(), and N.

Referenced by compatible_mod(), compatible_mod(), compatible_mod(), compatible_mod(), compatible_mod(), compatible_mod(), compatible_mod(), math_modulo(), snoise(), snoise(), snoise(), snoise(), and vector_math_modulo().

◆ compatible_pow()

float compatible_pow ( float x,
float y )

A version of pow that behaves similar to C++ std::pow.

Definition at line 83 of file gpu_shader_math_safe.bsl.hh.

References compatible_pow(), mod, pow, x, and y.

Referenced by compatible_pow(), compatible_pow(), compatible_pow(), compatible_pow(), math_power(), node_gamma(), and vector_math_power().

◆ fallback_pow()

float fallback_pow ( float x,
float y,
float fallback )

A version of pow that returns a fallback value if the computation is undefined. From the spec: The result is undefined if x < 0 or if x = 0 and y is less than or equal 0.

Definition at line 71 of file gpu_shader_math_safe.bsl.hh.

References fallback_pow(), pow, x, and y.

Referenced by fallback_pow(), fallback_pow(), fallback_pow(), and fallback_pow().

◆ safe_acos()

◆ safe_divide()

float safe_divide ( float a,
float b )

Safe divide a by b. If b equal 0 the result will be 0.

Definition at line 28 of file gpu_shader_math_safe.bsl.hh.

References b, and safe_divide().

Referenced by area_light_rect_sample(), atan2(), bsdf_eval_pass_diffuse_weight(), bsdf_eval_pass_glossy_weight(), bsdf_hair_huang_albedo(), bsdf_microfacet_eval(), bsdf_microfacet_sample(), bsdf_thin_glass_fresnel(), BVHObjectBinning::BVHObjectBinning(), BVHSpatialSplit::BVHSpatialSplit(), d_gamma_d_h(), fisheye_to_direction(), eevee::ltc::detail::form_factor_attenuation(), fractal_voronoi_x_fx(), fractal_voronoi_x_fx(), fractal_voronoi_x_fx(), fractal_voronoi_x_fx(), fractal_voronoi_x_fx(), fresnel_conductor_polarized(), guiding_record_direct_light(), hair_attenuation(), inversesqrt(), light_tree_emitter_importance(), light_tree_node_importance(), mapping_normal(), mapping_texture(), math_divide(), math_snap(), pdf_exponential_distribution(), principled_eval_translucent(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide(), safe_divide< float2 >(), safe_divide< float3 >(), safe_divide< float4 >(), safe_logf(), smootherstep(), smootherstep(), smootherstep(), snap(), svm_mapping(), svm_math(), svm_node_closure_bsdf(), svm_node_vector_map_range(), svm_vector_math(), sync_volume_object(), tan(), transform_decompose(), trimmed_logistic(), vector_map_range_linear(), vector_map_range_smootherstep(), vector_map_range_smoothstep(), vector_map_range_stepped(), vector_math_divide(), and vector_math_snap().

◆ safe_mod()

float safe_mod ( float a,
float b )

Safe a modulo b. If b equal 0 the result will be 0.

Definition at line 19 of file gpu_shader_math_safe.bsl.hh.

References b, mod, and safe_mod().

Referenced by safe_mod(), safe_mod(), safe_mod(), safe_mod(), safe_mod(), safe_mod< float2 >(), safe_mod< float3 >(), and safe_mod< float4 >().

◆ safe_rcp()

float safe_rcp ( float a)

Safe reciprocal function. Returns 1/a. If a equal 0 the result will be 0.

Definition at line 37 of file gpu_shader_math_safe.bsl.hh.

References safe_rcp().

Referenced by attr_load_color_post(), eevee::raytracing::denoise::bilateral_main(), bxdf_ggx_eval_refraction(), spherical_harmonics::clamp_energy(), eevee::dof::bokeh_lut::comp_main(), eevee::dof::resolve::comp_main(), eevee::dof::setup::downsample::comp_main(), eevee::dof::setup::reduce::comp_main(), eevee::dof::setup::setup::comp_main(), spherical_harmonics::compress(), blender::xpbd::ConstraintSetParams::ConstraintSetParams(), eevee::subsurface::convolve_main(), eevee::fast_gi::denoise(), eevee::dof::Accumulator::dof_gather_accumulate_resolve(), eevee::fast_gi::eval(), curves::nurbs::evaluate_curve(), eevee::camera::fisheye_equisolid_to_direction(), eevee::camera::fisheye_lens_polynomial_to_direction(), eevee::camera::fisheye_to_direction(), eevee::dof::scatter::frag_main(), ScreenSpaceRay::from_start_end(), eevee::geom_volume(), overlay::armature::shape::outline::Resources::geometry_main(), blender::bke::greasepencil::get_stroke_to_texture_matrix(), eevee::lightprobe::volume::grid_bias_sample_coord(), eevee::dof::setup::stabilize::Resources::history_blend_factor(), eevee::film::Film::history_blend_factor(), eevee::init_globals_mesh(), eevee::volume::integration_main(), intersect(), eevee::deferred::light_eval_frag(), workbench::volume::line_unit_box_intersect_dist(), eevee::lightprobe::volume::load_grid(), eevee::raytracing::denoise::DenoiseTemporal::local_statistics_get(), eevee::lightprobe::sphere::mip_convolve(), eevee::camera::mirror_ball_from_direction(), eevee::fast_gi::resolve(), draw::resource_finalize_main(), eevee::film::safe_divide_even_color(), safe_rcp(), safe_rcp(), safe_rcp< float2 >(), safe_rcp< float3 >(), safe_rcp< float4 >(), eevee::shadow_pcf_offset(), eevee::raytracing::denoise::spatial_main(), workbench::dof::sum_weighted(), eevee::surf_deferred(), eevee::surf_hybrid(), eevee::raytracing::denoise::temporal_main(), blender::tests::TEST(), and eevee::dof::setup::weighted_sum_array().

◆ safe_sqrt()

◆ wrap()

float wrap ( float a,
float b,
float c )

Wrap the given value a to fall within the range [b, c].

Definition at line 121 of file gpu_shader_math_safe.bsl.hh.

References b, floor, and wrap().

Referenced by workbench::get_world_lighting(), math_wrap(), svm_vector_math(), vector_math_wrap(), wrap(), wrap(), wrap(), wrap(), wrap(), wrap(), wrap(), and wrap().