From 47d2dffe8cc5ef3fba6268325f50c50ff0dfe08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 15 Apr 2025 11:36:53 +0200 Subject: [PATCH] GPU: Shader CodeBase use constexpr instead of const Do this only when applicable. This allow better compile time checking in Shader C++ compilation. Moreover, this allows to have `constexpr` in shared code between C++ and GLSL. After investigation the `const` keyword in GLSL has the same semantic than C/C++. Rel #137333 and #137446 Pull Request: https://projects.blender.org/blender/blender/pulls/137497 --- .../compositor_kuwahara_anisotropic.glsl | 2 +- ..._anisotropic_compute_structure_tensor.glsl | 4 +- ...pu_shader_compositor_color_correction.glsl | 4 +- ..._shader_compositor_color_to_luminance.glsl | 2 +- .../gpu_shader_compositor_hue_correct.glsl | 2 +- .../shaders/eevee_ambient_occlusion_lib.glsl | 6 +- .../shaders/eevee_bxdf_microfacet_lib.glsl | 4 +- .../shaders/eevee_bxdf_oren_nayar_lib.glsl | 2 +- .../eevee/shaders/eevee_camera_lib.glsl | 2 +- .../shaders/eevee_deferred_light_frag.glsl | 2 +- .../eevee_deferred_thickness_amend_frag.glsl | 2 +- .../eevee_depth_of_field_accumulator_lib.glsl | 14 +-- .../shaders/eevee_depth_of_field_lib.glsl | 8 +- .../eevee_depth_of_field_reduce_comp.glsl | 8 +- .../eevee_depth_of_field_resolve_comp.glsl | 12 +-- .../eevee_depth_of_field_scatter_frag.glsl | 2 +- .../eevee_depth_of_field_stabilize_comp.glsl | 10 +- .../eevee_display_lightprobe_planar_vert.glsl | 12 +-- .../eevee_display_lightprobe_sphere_vert.glsl | 12 +-- .../eevee_display_lightprobe_volume_vert.glsl | 12 +-- .../engines/eevee/shaders/eevee_film_lib.glsl | 16 +-- .../eevee/shaders/eevee_filter_lib.glsl | 2 +- .../eevee/shaders/eevee_gbuffer_lib.glsl | 14 +-- .../shaders/eevee_horizon_denoise_comp.glsl | 2 +- .../shaders/eevee_horizon_resolve_comp.glsl | 2 +- .../shaders/eevee_horizon_scan_comp.glsl | 2 +- .../shaders/eevee_horizon_scan_eval_lib.glsl | 2 +- .../eevee/shaders/eevee_horizon_scan_lib.glsl | 10 +- .../shaders/eevee_horizon_scan_test.glsl | 4 +- .../eevee_light_culling_tile_comp.glsl | 2 +- .../eevee_light_culling_zbin_comp.glsl | 2 +- ...eevee_lightprobe_sphere_convolve_comp.glsl | 2 +- ...vee_lightprobe_sphere_irradiance_comp.glsl | 4 +- .../eevee_lightprobe_sphere_mapping_lib.glsl | 9 +- .../eevee_lightprobe_sphere_remap_comp.glsl | 2 +- ...eevee_lightprobe_sphere_sunlight_comp.glsl | 4 +- .../engines/eevee/shaders/eevee_ltc_lib.glsl | 4 +- .../engines/eevee/shaders/eevee_lut_comp.glsl | 6 +- .../eevee/shaders/eevee_nodetree_lib.glsl | 8 +- .../eevee_ray_denoise_bilateral_comp.glsl | 2 +- .../eevee_ray_denoise_spatial_comp.glsl | 2 +- .../eevee_ray_denoise_temporal_comp.glsl | 2 +- .../shaders/eevee_ray_generate_comp.glsl | 2 +- .../eevee/shaders/eevee_ray_generate_lib.glsl | 2 +- .../eevee_ray_trace_fallback_comp.glsl | 2 +- .../shaders/eevee_ray_trace_planar_comp.glsl | 2 +- .../shaders/eevee_ray_trace_screen_comp.glsl | 2 +- .../shaders/eevee_ray_trace_screen_lib.glsl | 4 +- .../eevee/shaders/eevee_ray_types_lib.glsl | 2 +- .../shaders/eevee_shadow_debug_frag.glsl | 2 +- .../eevee/shaders/eevee_shadow_lib.glsl | 4 +- .../shaders/eevee_shadow_page_mask_comp.glsl | 2 +- .../shaders/eevee_shadow_tag_update_comp.glsl | 2 +- .../eevee_shadow_tilemap_amend_comp.glsl | 2 +- .../shaders/eevee_shadow_tilemap_lib.glsl | 30 +++--- .../shaders/eevee_shadow_tracing_lib.glsl | 2 +- .../eevee_spherical_harmonics_lib.glsl | 2 +- .../eevee_subsurface_convolve_comp.glsl | 2 +- .../shaders/eevee_surf_deferred_frag.glsl | 6 +- .../eevee/shaders/eevee_surf_hybrid_frag.glsl | 6 +- .../eevee/shaders/eevee_surf_shadow_frag.glsl | 4 +- .../eevee/shaders/eevee_surfel_ray_comp.glsl | 2 +- ...verlay_armature_envelope_outline_vert.glsl | 2 +- .../overlay_armature_envelope_solid_frag.glsl | 2 +- .../overlay_armature_envelope_solid_vert.glsl | 2 +- .../overlay_armature_shape_outline_vert.glsl | 16 +-- .../overlay_armature_shape_solid_vert.glsl | 4 +- .../overlay_armature_shape_wire_frag.glsl | 3 +- .../overlay_armature_shape_wire_vert.glsl | 18 ++-- .../overlay_armature_sphere_outline_vert.glsl | 4 +- .../overlay_armature_sphere_solid_frag.glsl | 6 +- .../overlay_armature_sphere_solid_vert.glsl | 2 +- .../shaders/overlay_background_frag.glsl | 8 +- .../overlay/shaders/overlay_common_lib.glsl | 2 +- ...lay_depth_only_mesh_conservative_vert.glsl | 18 ++-- .../overlay_edit_curve_handle_vert.glsl | 16 +-- .../overlay_edit_curve_normals_vert.glsl | 16 +-- .../overlay_edit_curves_handle_vert.glsl | 16 +-- .../shaders/overlay_edit_mesh_edge_vert.glsl | 16 +-- .../overlay_edit_mesh_normal_vert.glsl | 16 +-- .../shaders/overlay_edit_uv_edges_vert.glsl | 16 +-- .../shaders/overlay_edit_uv_verts_vert.glsl | 2 +- .../overlay/shaders/overlay_extra_vert.glsl | 2 +- .../shaders/overlay_extra_wire_frag.glsl | 4 +- .../overlay_motion_path_line_vert.glsl | 16 +-- .../shaders/overlay_outline_detect_frag.glsl | 2 +- .../overlay_outline_prepass_wire_vert.glsl | 16 +-- .../shaders/overlay_paint_weight_frag.glsl | 4 +- .../shaders/overlay_paint_wire_vert.glsl | 2 +- .../overlay_point_varying_color_frag.glsl | 2 +- .../overlay_volume_gridlines_vert.glsl | 10 +- .../shaders/overlay_volume_velocity_vert.glsl | 10 +- .../shaders/workbench_common_lib.glsl | 16 +-- .../shaders/workbench_shadow_caps_vert.glsl | 22 ++--- .../shaders/workbench_shadow_debug_frag.glsl | 2 +- .../shaders/workbench_shadow_vert.glsl | 18 ++-- .../shaders/workbench_volume_frag.glsl | 10 +- .../common/gpu_shader_common_color_ramp.glsl | 6 +- .../common/gpu_shader_math_matrix_lib.glsl | 2 +- .../common/gpu_shader_math_rotation_lib.glsl | 2 +- .../common/gpu_shader_math_vector_lib.glsl | 36 +++---- .../gpu_shader_shared_exponent_lib.glsl | 2 +- .../common/gpu_shader_utildefines_lib.glsl | 6 +- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 99 +++++++++++-------- .../gpu_shader_2D_node_socket_frag.glsl | 4 +- .../shaders/gpu_shader_2D_nodelink_vert.glsl | 4 +- .../gpu_shader_2D_widget_base_frag.glsl | 2 +- .../gpu_shader_2D_widget_base_vert.glsl | 2 +- .../gpu_shader_2D_widget_shadow_vert.glsl | 74 +++++++------- .../shaders/gpu_shader_3D_polyline_vert.glsl | 14 +-- .../gpu_shader_gpencil_stroke_frag.glsl | 2 +- .../gpu_shader_gpencil_stroke_vert.glsl | 19 ++-- .../gpu/shaders/gpu_shader_icon_frag.glsl | 6 +- .../gpu_shader_point_varying_color_frag.glsl | 2 +- .../gpu/shaders/gpu_shader_text_frag.glsl | 4 +- .../material/gpu_shader_material_tex_sky.glsl | 2 +- .../shaders/opengl/glsl_shader_defines.glsl | 6 +- .../gpu/tests/shaders/gpu_math_test.glsl | 6 +- 118 files changed, 476 insertions(+), 452 deletions(-) diff --git a/source/blender/compositor/shaders/compositor_kuwahara_anisotropic.glsl b/source/blender/compositor/shaders/compositor_kuwahara_anisotropic.glsl index 666e467a0ac..78e662e8747 100644 --- a/source/blender/compositor/shaders/compositor_kuwahara_anisotropic.glsl +++ b/source/blender/compositor/shaders/compositor_kuwahara_anisotropic.glsl @@ -105,7 +105,7 @@ void main() /* Compute the overlap polynomial parameters for 8-sector ellipse based on the equations in * section "3 Alternative Weighting Functions" of the polynomial weights paper. More on this * later in the code. */ - const int number_of_sectors = 8; + constexpr int number_of_sectors = 8; float sector_center_overlap_parameter = 2.0f / radius; float sector_envelope_angle = ((3.0f / 2.0f) * M_PI) / number_of_sectors; float cross_sector_overlap_parameter = (sector_center_overlap_parameter + diff --git a/source/blender/compositor/shaders/compositor_kuwahara_anisotropic_compute_structure_tensor.glsl b/source/blender/compositor/shaders/compositor_kuwahara_anisotropic_compute_structure_tensor.glsl index 1ae019dcc9d..fb8156a9dc1 100644 --- a/source/blender/compositor/shaders/compositor_kuwahara_anisotropic_compute_structure_tensor.glsl +++ b/source/blender/compositor/shaders/compositor_kuwahara_anisotropic_compute_structure_tensor.glsl @@ -19,8 +19,8 @@ void main() /* The weight kernels of the filter optimized for rotational symmetry described in section * "3.2.1 Gradient Calculation". */ - const float corner_weight = 0.182f; - const float center_weight = 1.0f - 2.0f * corner_weight; + constexpr float corner_weight = 0.182f; + constexpr float center_weight = 1.0f - 2.0f * corner_weight; float3 x_partial_derivative = texture_load(input_tx, texel + int2(-1, 1)).rgb * -corner_weight + texture_load(input_tx, texel + int2(-1, 0)).rgb * -center_weight + diff --git a/source/blender/compositor/shaders/library/gpu_shader_compositor_color_correction.glsl b/source/blender/compositor/shaders/library/gpu_shader_compositor_color_correction.glsl index 339c4b17a0a..965287fde1e 100644 --- a/source/blender/compositor/shaders/library/gpu_shader_compositor_color_correction.glsl +++ b/source/blender/compositor/shaders/library/gpu_shader_compositor_color_correction.glsl @@ -33,8 +33,8 @@ void node_composite_color_correction(float4 color, const float3 luminance_coefficients, out float4 result) { - const float margin = 0.10f; - const float margin_divider = 0.5f / margin; + constexpr float margin = 0.10f; + constexpr float margin_divider = 0.5f / margin; float level = (color.r + color.g + color.b) / 3.0f; float level_shadows = 0.0f; float level_midtones = 0.0f; diff --git a/source/blender/compositor/shaders/library/gpu_shader_compositor_color_to_luminance.glsl b/source/blender/compositor/shaders/library/gpu_shader_compositor_color_to_luminance.glsl index 7017758879e..b12e36dce0e 100644 --- a/source/blender/compositor/shaders/library/gpu_shader_compositor_color_to_luminance.glsl +++ b/source/blender/compositor/shaders/library/gpu_shader_compositor_color_to_luminance.glsl @@ -4,7 +4,7 @@ #include "gpu_shader_common_color_utils.glsl" -void color_to_luminance(float4 color, const float3 luminance_coefficients, out float result) +void color_to_luminance(float4 color, float3 luminance_coefficients, out float result) { result = get_luminance(color.rgb, luminance_coefficients); } diff --git a/source/blender/compositor/shaders/library/gpu_shader_compositor_hue_correct.glsl b/source/blender/compositor/shaders/library/gpu_shader_compositor_hue_correct.glsl index 5d1f0fbf68b..3128122d8fd 100644 --- a/source/blender/compositor/shaders/library/gpu_shader_compositor_hue_correct.glsl +++ b/source/blender/compositor/shaders/library/gpu_shader_compositor_hue_correct.glsl @@ -9,7 +9,7 @@ * parameter in the [0, 1] range. */ float3 compute_hue_curve_map_coordinates(float3 parameters) { - const float sampler_resolution = 257.0f; + constexpr float sampler_resolution = 257.0f; float sampler_offset = 0.5f / sampler_resolution; float sampler_scale = 1.0f - (1.0f / sampler_resolution); return parameters * sampler_scale + sampler_offset; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ambient_occlusion_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ambient_occlusion_lib.glsl index e67a6072f84..6ebfc59781b 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ambient_occlusion_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ambient_occlusion_lib.glsl @@ -124,7 +124,7 @@ float ambient_ambient_occlusion_search_horizon(float3 vI, } /* Bias depth a bit to avoid self shadowing issues. */ - const float bias = 2.0f * 2.4e-7f; + constexpr float bias = 2.0f * 2.4e-7f; depth += (inverted != 0.0f) ? -bias : bias; float3 s = drw_point_screen_to_view(float3(uv, depth)); @@ -193,7 +193,7 @@ float2 ambient_occlusion_clamp_horizons_to_hemisphere(float2 horizons, const float inverted) { /* Add a little bias to fight self shadowing. */ - const float max_angle = M_PI_2 - 0.05f; + constexpr float max_angle = M_PI_2 - 0.05f; if (inverted != 0.0f) { horizons.x = max(horizons.x, angle_N + max_angle); @@ -395,7 +395,7 @@ float ambient_occlusion_specular( float vis_angle = acos_fast(sqrt(1 - visibility)); /* Roughness to cone angle (eq. 26). */ /* A 0.001 min_angle can generate NaNs on Intel GPUs. See D12508. */ - const float min_angle = 0.00990998744964599609375f; + constexpr float min_angle = 0.00990998744964599609375f; float spec_angle = max(min_angle, acos_fast(ambient_occlusion_cone_cosine(roughness))); /* Angle between cone axes. */ float cone_cone_dist = acos_fast(saturate(dot(visibility_dir, specular_dir))); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl index 85ee8652778..76435d59310 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_microfacet_lib.glsl @@ -46,7 +46,7 @@ float bxdf_ggx_smith_G1(float NX, float a2) * * \return: the sampled direction and the pdf of sampling the direction. */ -BsdfSample bxdf_ggx_sample_reflection(float3 rand, float3 Vt, float alpha, const bool do_clamp) +BsdfSample bxdf_ggx_sample_reflection(float3 rand, float3 Vt, float alpha, bool do_clamp) { if (do_clamp && alpha < square(BSDF_ROUGHNESS_THRESHOLD)) { BsdfSample samp; @@ -97,7 +97,7 @@ BsdfSample bxdf_ggx_sample_reflection(float3 rand, float3 Vt, float alpha, const /* Evaluate the GGX BRDF without the Fresnel term, multiplied by the cosine foreshortening term. * Also evaluate the probability of sampling the reflection direction. */ -BsdfEval bxdf_ggx_eval_reflection(float3 N, float3 L, float3 V, float alpha, const bool do_clamp) +BsdfEval bxdf_ggx_eval_reflection(float3 N, float3 L, float3 V, float alpha, bool do_clamp) { float NV = dot(N, V); if (NV <= 0.0f) { diff --git a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl index 3ca2db4c91c..6722d32d1a3 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_bxdf_oren_nayar_lib.glsl @@ -22,7 +22,7 @@ BsdfSample bxdf_oren_nayar_sample(float3 random_point_cos_hemisphere) { /* Bias the rays so we never get really high energy rays almost parallel to the surface. * Also reduces shadow terminator artifacts. */ - const float bias = 0.05f; + constexpr float bias = 0.05f; random_point_cos_hemisphere = normalize(random_point_cos_hemisphere + float3(0.0f, 0.0f, bias)); float cos_theta = random_point_cos_hemisphere.z; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_camera_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_camera_lib.glsl index 4e542cd03b0..e79d31d952a 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_camera_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_camera_lib.glsl @@ -77,7 +77,7 @@ float3 camera_mirror_ball_to_direction(CameraData cam, float2 uv) return float3(0.0f); } dir.z = -safe_sqrt(1.0f - square(dir.x) - square(dir.y)); - const float3 I = float3(0.0f, 0.0f, 1.0f); + constexpr float3 I = float3(0.0f, 0.0f, 1.0f); return reflect(I, dir); } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_deferred_light_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_deferred_light_frag.glsl index 9cd08e2efee..80f98849ac8 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_deferred_light_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_deferred_light_frag.glsl @@ -58,7 +58,7 @@ void main() /* Bias the shading point position because of depth buffer precision. * Constant is taken from https://www.terathon.com/gdc07_lengyel.pdf. */ - const float bias = 2.4e-7f; + constexpr float bias = 2.4e-7f; depth -= bias; float3 P = drw_point_screen_to_world(float3(uvcoordsvar.xy, depth)); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_deferred_thickness_amend_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_deferred_thickness_amend_frag.glsl index 2f5280ac8e2..18a6c3b21e3 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_deferred_thickness_amend_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_deferred_thickness_amend_frag.glsl @@ -115,7 +115,7 @@ void main() /* Bias the shading point position because of depth buffer precision. * Constant is taken from https://www.terathon.com/gdc07_lengyel.pdf. */ - const float bias = 2.4e-7f; + constexpr float bias = 2.4e-7f; depth -= bias; float3 P = drw_point_screen_to_world(float3(uvcoordsvar.xy, depth)); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_accumulator_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_accumulator_lib.glsl index f7bc140e77c..5071cdc6715 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_accumulator_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_accumulator_lib.glsl @@ -158,9 +158,9 @@ void dof_gather_accumulate_sample_pair(DofGatherData pair_data[2], } #if 0 - const float mirroring_threshold = -dof_layer_threshold - dof_layer_offset; + constexpr float mirroring_threshold = -dof_layer_threshold - dof_layer_offset; /* TODO(fclem) Promote to parameter? dither with Noise? */ - const float mirroring_min_distance = 15.0f; + constexpr float mirroring_min_distance = 15.0f; if (pair_data[0].coc < mirroring_threshold && (pair_data[1].coc - mirroring_min_distance) > pair_data[0].coc) { @@ -426,7 +426,7 @@ void dof_gather_init(float base_radius, /* TODO(fclem) Seems like the default lod selection is too big. Bias to avoid blocky moving out * of focus shapes. */ - const float lod_bias = -2.0f; + constexpr float lod_bias = -2.0f; lod = max(floor(log2(base_radius * unit_sample_radius) + 0.5f) + lod_bias, 0.0f); if (no_gather_mipmaps) { @@ -547,8 +547,8 @@ void dof_gather_accumulator(sampler2D color_tx, ring += gather_density_change_ring; /* We need to account for the density change in the weights (slide 62). * For that multiply old kernel data by its area divided by the new kernel area. */ - const float outer_rings_weight = 1.0f / - (radius_downscale_factor * radius_downscale_factor); + constexpr float outer_rings_weight = 1.0f / + (radius_downscale_factor * radius_downscale_factor); /* Samples are already weighted per ring in foreground pass. */ if (!IS_FOREGROUND) { dof_gather_amend_weight(accum_data, outer_rings_weight); @@ -628,7 +628,7 @@ void dof_slight_focus_gather(depth2D depth_tx, int i_radius = clamp(int(radius), 0, int(dof_layer_threshold)); - const float sample_count_max = float(DOF_SLIGHT_FOCUS_SAMPLE_MAX); + constexpr float sample_count_max = float(DOF_SLIGHT_FOCUS_SAMPLE_MAX); /* Scale by search area. */ float sample_count = sample_count_max * saturate(square(radius) / square(dof_layer_threshold)); @@ -657,7 +657,7 @@ void dof_slight_focus_gather(depth2D depth_tx, } float bordering_radius = ring_dist + 0.5f; - const float isect_mul = 1.0f; + constexpr float isect_mul = 1.0f; DofGatherData bg_ring = GATHER_DATA_INIT; dof_gather_accumulate_sample_pair( pair_data, bordering_radius, isect_mul, first_ring, false, false, bg_ring, bg_accum); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_lib.glsl index 65faee52093..2d0eb12910c 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_lib.glsl @@ -74,7 +74,7 @@ float dof_hdr_color_weight(float4 color) /* Very fast "luma" weighting. */ float luma = (color.g * 2.0f) + (color.r + color.b); /* TODO(fclem) Pass correct exposure. */ - const float exposure = 1.0f; + constexpr float exposure = 1.0f; return 1.0f / (luma * exposure + 4.0f); } @@ -99,7 +99,7 @@ float4 dof_bilateral_coc_weights(float4 cocs) { float chosen_coc = dof_coc_select(cocs); - const float scale = 4.0f; /* TODO(fclem) revisit. */ + constexpr float scale = 4.0f; /* TODO(fclem) revisit. */ /* NOTE: The difference between the cocs should be inside a abs() function, * but we follow UE4 implementation to improve how dithered transparency looks (see slide 19). */ return saturate(1.0f - (chosen_coc - cocs) * scale); @@ -162,7 +162,7 @@ float dof_sample_weight(float coc) return min(1.0f, 1.0f / square(coc)); #else /* Full intensity if CoC radius is below the pixel footprint. */ - const float min_coc = 1.0f; + constexpr float min_coc = 1.0f; coc = max(min_coc, abs(coc)); return (M_PI * min_coc * min_coc) / (M_PI * coc * coc); #endif @@ -173,7 +173,7 @@ float4 dof_sample_weight(float4 coc) return min(float4(1.0f), 1.0f / square(coc)); #else /* Full intensity if CoC radius is below the pixel footprint. */ - const float min_coc = 1.0f; + constexpr float min_coc = 1.0f; coc = max(float4(min_coc), abs(coc)); return (M_PI * min_coc * min_coc) / (M_PI * coc * coc); #endif diff --git a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_reduce_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_reduce_comp.glsl index 5ff18672c93..a9a70c9ac35 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_reduce_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_reduce_comp.glsl @@ -40,7 +40,7 @@ float dof_scatter_neighborhood_rejection(float3 color) ref = min(float3(dof_buf.scatter_neighbor_max_color), ref); float diff = reduce_max(max(float3(0.0f), abs(ref - color))); - const float rejection_threshold = 0.7f; + constexpr float rejection_threshold = 0.7f; diff = saturate(diff / rejection_threshold - 1.0f); validity = max(validity, diff); } @@ -59,19 +59,19 @@ float dof_scatter_screen_border_rejection(float coc, int2 texel) /* Full-resolution to half-resolution CoC. */ coc *= 0.5f; /* Allow 10px transition. */ - const float rejection_hardness = 1.0f / 10.0f; + constexpr float rejection_hardness = 1.0f / 10.0f; return saturate((min_screen_border_distance - abs(coc)) * rejection_hardness + 1.0f); } float dof_scatter_luminosity_rejection(float3 color) { - const float rejection_hardness = 1.0f; + constexpr float rejection_hardness = 1.0f; return saturate(reduce_max(color - dof_buf.scatter_color_threshold) * rejection_hardness); } float dof_scatter_coc_radius_rejection(float coc) { - const float rejection_hardness = 0.3f; + constexpr float rejection_hardness = 0.3f; return saturate((abs(coc) - dof_buf.scatter_coc_threshold) * rejection_hardness); } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_resolve_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_resolve_comp.glsl index 37698bea558..5a490fd665d 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_resolve_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_resolve_comp.glsl @@ -84,7 +84,7 @@ float3 dof_neighborhood_clamp(float2 frag_coord, float3 color, float center_coc, { /* Stabilize color by clamping with the stable half res neighborhood. */ float3 neighbor_min, neighbor_max; - const float2 corners[4] = float2_array( + constexpr float2 corners[4] = float2_array( float2(-1, -1), float2(1, -1), float2(-1, 1), float2(1, 1)); for (int i = 0; i < 4; i++) { /** @@ -152,11 +152,11 @@ void main() float4 layer_color; float layer_weight; - const float3 hole_fill_color = float3(0.2f, 0.1f, 1.0f); - const float3 background_color = float3(0.1f, 0.2f, 1.0f); - const float3 slight_focus_color = float3(1.0f, 0.2f, 0.1f); - const float3 focus_color = float3(1.0f, 1.0f, 0.1f); - const float3 foreground_color = float3(0.2f, 1.0f, 0.1f); + constexpr float3 hole_fill_color = float3(0.2f, 0.1f, 1.0f); + constexpr float3 background_color = float3(0.1f, 0.2f, 1.0f); + constexpr float3 slight_focus_color = float3(1.0f, 0.2f, 0.1f); + constexpr float3 focus_color = float3(1.0f, 1.0f, 0.1f); + constexpr float3 foreground_color = float3(0.2f, 1.0f, 0.1f); if (!no_hole_fill_pass && prediction.do_hole_fill) { layer_color = textureLod(color_hole_fill_tx, uv_halfres, 0.0f); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_scatter_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_scatter_frag.glsl index 7480bb66ca9..948868f949d 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_scatter_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_scatter_frag.glsl @@ -53,7 +53,7 @@ void main() float2 uv = gl_FragCoord.xy / float2(textureSize(occlusion_tx, 0).xy); float2 occlusion_data = texture(occlusion_tx, uv).rg; /* Fix tilling artifacts. (Slide 90) */ - const float correction_fac = 1.0f - DOF_FAST_GATHER_COC_ERROR; + constexpr float correction_fac = 1.0f - DOF_FAST_GATHER_COC_ERROR; /* Occlude the sprite with geometry from the same field using a chebychev test (slide 85). */ float mean = occlusion_data.x; float variance = occlusion_data.y; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_stabilize_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_stabilize_comp.glsl index b34ea09a236..cc304f306ef 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_stabilize_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_depth_of_field_stabilize_comp.glsl @@ -113,7 +113,7 @@ float dof_luma_weight(float luma) { /* Slide 20 of "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014. */ /* To preserve more details in dark areas, we use a bigger bias. */ - const float exposure_scale = 1.0f; /* TODO. */ + constexpr float exposure_scale = 1.0f; /* TODO. */ return 1.0f / (4.0f + luma * exposure_scale); } @@ -129,7 +129,7 @@ float dof_bilateral_weight(float reference_coc, float sample_coc) DofSample dof_spatial_filtering() { /* Plus (+) shape offsets. */ - const int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1)); + constexpr int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1)); DofSample center = dof_fetch_input_sample(int2(0)); DofSample accum = DofSample(float4(0.0f), 0.0f); float accum_weight = 0.0f; @@ -169,7 +169,7 @@ struct DofNeighborhoodMinMax { DofNeighborhoodMinMax dof_neighbor_boundbox() { /* Plus (+) shape offsets. */ - const int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1)); + constexpr int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1)); /** * Simple bounding box calculation in YCoCg as described in: * "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014 @@ -187,7 +187,7 @@ DofNeighborhoodMinMax dof_neighbor_boundbox() * Round bbox shape by averaging 2 different min/max from 2 different neighborhood. */ DofSample min_c_3x3 = min_c; DofSample max_c_3x3 = max_c; - const int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1)); + constexpr int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1)); for (int i = 0; i < 4; i++) { DofSample samp = dof_fetch_input_sample(corners[i]); min_c_3x3.color = min(min_c_3x3.color, samp.color); @@ -210,7 +210,7 @@ float2 dof_pixel_history_motion_vector(int2 texel_sample) * Dilate velocity by using the nearest pixel in a cross pattern. * "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014 (Slide 27) */ - const int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2)); + constexpr int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2)); float min_depth = dof_fetch_half_depth(int2(0)); int2 nearest_texel = int2(0); for (int i = 0; i < 4; i++) { diff --git a/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_planar_vert.glsl b/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_planar_vert.glsl index f63ca812bf1..d4fe768ac77 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_planar_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_planar_vert.glsl @@ -13,13 +13,13 @@ void main() { /* Constant array moved inside function scope. * Minimizes local register allocation in MSL. */ - const float2 pos[6] = float2_array(float2(-1.0f, -1.0f), - float2(1.0f, -1.0f), - float2(-1.0f, 1.0f), + constexpr float2 pos[6] = float2_array(float2(-1.0f, -1.0f), + float2(1.0f, -1.0f), + float2(-1.0f, 1.0f), - float2(1.0f, -1.0f), - float2(1.0f, 1.0f), - float2(-1.0f, 1.0f)); + float2(1.0f, -1.0f), + float2(1.0f, 1.0f), + float2(-1.0f, 1.0f)); float2 lP = pos[gl_VertexID % 6]; int display_index = gl_VertexID / 6; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_sphere_vert.glsl b/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_sphere_vert.glsl index ef74a589b53..0687c087cc0 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_sphere_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_sphere_vert.glsl @@ -13,13 +13,13 @@ void main() { /* Constant array moved inside function scope. * Minimizes local register allocation in MSL. */ - const float2 pos[6] = float2_array(float2(-1.0f, -1.0f), - float2(1.0f, -1.0f), - float2(-1.0f, 1.0f), + constexpr float2 pos[6] = float2_array(float2(-1.0f, -1.0f), + float2(1.0f, -1.0f), + float2(-1.0f, 1.0f), - float2(1.0f, -1.0f), - float2(1.0f, 1.0f), - float2(-1.0f, 1.0f)); + float2(1.0f, -1.0f), + float2(1.0f, 1.0f), + float2(-1.0f, 1.0f)); lP = pos[gl_VertexID % 6]; int display_index = gl_VertexID / 6; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_volume_vert.glsl b/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_volume_vert.glsl index 9d4e9ee6a5b..92b6213cce7 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_volume_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_display_lightprobe_volume_vert.glsl @@ -13,13 +13,13 @@ void main() { /* Constant array moved inside function scope. * Minimizes local register allocation in MSL. */ - const float2 pos[6] = float2_array(float2(-1.0f, -1.0f), - float2(1.0f, -1.0f), - float2(-1.0f, 1.0f), + constexpr float2 pos[6] = float2_array(float2(-1.0f, -1.0f), + float2(1.0f, -1.0f), + float2(-1.0f, 1.0f), - float2(1.0f, -1.0f), - float2(1.0f, 1.0f), - float2(-1.0f, 1.0f)); + float2(1.0f, -1.0f), + float2(1.0f, 1.0f), + float2(-1.0f, 1.0f)); lP = pos[gl_VertexID % 6]; int cell_index = gl_VertexID / 6; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_film_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_film_lib.glsl index 65f543b05de..89c02aa4ae7 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_film_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_film_lib.glsl @@ -251,7 +251,7 @@ float2 film_pixel_history_motion_vector(int2 texel_sample) * Dilate velocity by using the nearest pixel in a cross pattern. * "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014 (Slide 27) */ - const int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2)); + constexpr int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2)); float min_depth = texelFetch(depth_tx, texel_sample, 0).x; int2 nearest_texel = texel_sample; for (int i = 0; i < 4; i++) { @@ -347,11 +347,11 @@ float4 film_sample_catmull_rom(sampler2D color_tx, float2 input_texel) void film_combined_neighbor_boundbox(int2 texel, out float4 min_c, out float4 max_c) { /* Plus (+) shape offsets. */ - const int2 plus_offsets[5] = int2_array(int2(0, 0), /* Center */ - int2(-1, 0), - int2(0, -1), - int2(1, 0), - int2(0, 1)); + constexpr int2 plus_offsets[5] = int2_array(int2(0, 0), /* Center */ + int2(-1, 0), + int2(0, -1), + int2(1, 0), + int2(0, 1)); #if 0 /** * Compute Variance of neighborhood as described in: @@ -372,7 +372,7 @@ void film_combined_neighbor_boundbox(int2 texel, out float4 min_c, out float4 ma /* Extent scaling. Range [0.75..1.25]. * Balance between more flickering (0.75) or more ghosting (1.25). */ - const float gamma = 1.25f; + constexpr float gamma = 1.25f; /* Standard deviation. */ float4 sigma = sqrt(abs(mu2 - square(mu1))); /* eq. 6 in "A Survey of Temporal Anti-aliasing Techniques". */ @@ -394,7 +394,7 @@ void film_combined_neighbor_boundbox(int2 texel, out float4 min_c, out float4 ma * Round bbox shape by averaging 2 different min/max from 2 different neighborhood. */ float4 min_c_3x3 = min_c; float4 max_c_3x3 = max_c; - const int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1)); + constexpr int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1)); for (int i = 0; i < 4; i++) { float4 color = film_texelfetch_as_YCoCg_opacity(combined_tx, texel + corners[i]); min_c_3x3 = min(min_c_3x3, color); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_filter_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_filter_lib.glsl index 10451f29dde..6f8d71d7bde 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_filter_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_filter_lib.glsl @@ -27,7 +27,7 @@ float filter_gaussian_factor(float linear_distance, float standard_deviation) { /* Account for `filter_gaussian_factor` using `exp2` for speed (`exp(x) = exp2(x / log(2))`). */ - const float log_2_inv = 1.442695041f; + constexpr float log_2_inv = 1.442695041f; return log_2_inv * standard_deviation / square(linear_distance); } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_gbuffer_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_gbuffer_lib.glsl index 597b38dbdc5..8c383a9abdb 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_gbuffer_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_gbuffer_lib.glsl @@ -312,7 +312,7 @@ bool gbuffer_is_refraction(float4 gbuffer) uint gbuffer_geometry_normal_pack(float3 Ng, float3 N) { /* This is a threshold that minimizes the error over the sphere. */ - const float quantization_multiplier = 1.360f; + constexpr float quantization_multiplier = 1.360f; /* Normalize for comparison. */ float3 Ng_quantize = normalize(round(quantization_multiplier * Ng)); /* Note: Comparing the error using cosines. The greater the cosine value, the lower the error. */ @@ -915,7 +915,7 @@ GBufferWriter gbuffer_pack(GBufferData data_in, float3 Ng) int gbuffer_closure_count(uint header) { /* NOTE: Need to be adjusted for different global GBUFFER_LAYER_MAX. */ - const uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER); + constexpr uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER); uint3 closure_types = (uint3(header) >> (uint3(0u, 1u, 2u) * bits_per_layer)) & ((1u << bits_per_layer) - 1); return reduce_add(int3(not(equal(closure_types, uint3(0u))))); @@ -924,10 +924,10 @@ int gbuffer_closure_count(uint header) bool gbuffer_has_transmission(uint header) { /* NOTE: Need to be adjusted for different global GBUFFER_LAYER_MAX. */ - const uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER); - const uint header_mask = (GBUF_TRANSMISSION_BIT << (bits_per_layer * 0)) | - (GBUF_TRANSMISSION_BIT << (bits_per_layer * 1)) | - (GBUF_TRANSMISSION_BIT << (bits_per_layer * 2)); + constexpr uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER); + constexpr uint header_mask = (GBUF_TRANSMISSION_BIT << (bits_per_layer * 0)) | + (GBUF_TRANSMISSION_BIT << (bits_per_layer * 1)) | + (GBUF_TRANSMISSION_BIT << (bits_per_layer * 2)); return (header & header_mask) != 0; } @@ -949,7 +949,7 @@ ClosureType gbuffer_closure_type_get_by_bin(uint header, uchar bin_index) { /* TODO(fclem): Doesn't take GBUF_METAL_CLEARCOAT into account or other mode that could merge two * bins into one layer. */ - const int bits_per_layer = GBUFFER_HEADER_BITS_PER_LAYER; + constexpr int bits_per_layer = GBUFFER_HEADER_BITS_PER_LAYER; uint mode = (header >> (bin_index * bits_per_layer)) & ((1u << bits_per_layer) - 1); return gbuffer_mode_to_closure_type(mode); } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_horizon_denoise_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_horizon_denoise_comp.glsl index 63c66464223..b36da702a1b 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_horizon_denoise_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_horizon_denoise_comp.glsl @@ -58,7 +58,7 @@ SphericalHarmonicL1 load_spherical_harmonic(int2 texel) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_horizon_resolve_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_horizon_resolve_comp.glsl index 95e4810edda..1effaca0a9a 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_horizon_resolve_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_horizon_resolve_comp.glsl @@ -68,7 +68,7 @@ SphericalHarmonicL1 load_spherical_harmonic(int2 texel, bool valid) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_comp.glsl index 820a1bda858..a704897fddb 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_comp.glsl @@ -14,7 +14,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_horizon_scan) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl index 5b8bbe2b0e1..a4c3549e1a2 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_eval_lib.glsl @@ -160,7 +160,7 @@ HorizonScanResult horizon_scan_eval(float3 vP, } /* Bias depth a bit to avoid self shadowing issues. */ - const float bias = 2.0f * 2.4e-7f; + constexpr float bias = 2.0f * 2.4e-7f; sample_depth += reversed ? -bias : bias; float3 vP_sample_front = drw_point_screen_to_view(float3(sample_uv, sample_depth)); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_lib.glsl index 81af60f1757..2bb11606ff2 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_lib.glsl @@ -22,7 +22,7 @@ */ uint horizon_scan_angles_to_bitmask(float2 theta) { - const int bitmask_len = 32; + constexpr int bitmask_len = 32; /* Algorithm 1, line 18. Re-ordered to make sure to clamp to the hemisphere range. */ float2 ratio = saturate(theta * M_1_PI + 0.5f); uint a = uint(floor(float(bitmask_len) * ratio.x)); @@ -34,7 +34,7 @@ uint horizon_scan_angles_to_bitmask(float2 theta) float horizon_scan_bitmask_to_visibility_uniform(uint bitmask) { - const int bitmask_len = 32; + constexpr int bitmask_len = 32; /* Algorithm 1, line 26. */ return float(bitCount(bitmask)) / float(bitmask_len); } @@ -59,7 +59,7 @@ float horizon_scan_bitmask_to_occlusion_cosine(uint bitmask) * distribution in `horizon_scan_angles_to_bitmask()` but that requires more computation per * samples. The quality difference does not justify it currently. */ #if 0 /* Reference. */ - const int bitmask_len = 32; + constexpr int bitmask_len = 32; float visibility = 0.0f; for (int bit = 0; bit < bitmask_len; bit++) { float angle = (((float(bit) + 0.5f) / float(bitmask_len)) - 0.5f) * M_PI; @@ -73,8 +73,8 @@ float horizon_scan_bitmask_to_occlusion_cosine(uint bitmask) /* The precomputed weights are the accumulated weights from the reference loop for each of the * samples in the mask. The weight is distributed evenly for each sample inside a mask. * This is like a 4 piecewise linear approximation of the cosine lobe. */ - const float4 weights = float4(0.0095061f, 0.0270951f, 0.0405571f, 0.0478421f); - const uint4 masks = uint4(0xF000000Fu, 0x0F0000F0u, 0x00F00F00u, 0x000FF000u); + constexpr float4 weights = float4(0.0095061f, 0.0270951f, 0.0405571f, 0.0478421f); + constexpr uint4 masks = uint4(0xF000000Fu, 0x0F0000F0u, 0x00F00F00u, 0x000FF000u); return saturate(1.0f - dot(float4(bitCount(uint4(bitmask) & masks)), weights)); #endif } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_test.glsl b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_test.glsl index 66e04d1c979..87c9b704f97 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_test.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_horizon_scan_test.glsl @@ -34,7 +34,7 @@ void main() TEST(eevee_horizon_scan, UniformOcclusion) { - const float esp = 1e-4f; + constexpr float esp = 1e-4f; EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_uniform(0x00000000u), 1.0f, esp); EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_uniform(0xFFFFFFFFu), 0.0f, esp); EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_uniform(0xFFFF0000u), 0.5f, esp); @@ -45,7 +45,7 @@ void main() TEST(eevee_horizon_scan, CosineOcclusion) { - const float esp = 1e-5f; + constexpr float esp = 1e-5f; EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_cosine(0x00000000u), 1.0f, esp); EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_cosine(0xFFFFFFFFu), 0.0f, esp); EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_cosine(0xFFFF0000u), 0.5f, esp); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_light_culling_tile_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_light_culling_tile_comp.glsl index 86b2f12dbdd..d315dd48440 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_light_culling_tile_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_light_culling_tile_comp.glsl @@ -58,7 +58,7 @@ float4 tile_bound_cylinder(float3 v00, float3 v01, float3 v10, float3 v11) float2 tile_to_ndc(float2 tile_co, float2 offset) { /* Add a margin to prevent culling too much if the frustum becomes too much unstable. */ - const float margin = 0.02f; + constexpr float margin = 0.02f; tile_co += margin * (offset * 2.0f - 1.0f); tile_co += offset; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_light_culling_zbin_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_light_culling_zbin_comp.glsl index 9fcafb07f0b..18dc1e656ea 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_light_culling_zbin_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_light_culling_zbin_comp.glsl @@ -22,7 +22,7 @@ shared uint zbin_min[CULLING_ZBIN_COUNT]; void main() { - const uint zbin_iter = CULLING_ZBIN_COUNT / gl_WorkGroupSize.x; + constexpr uint zbin_iter = CULLING_ZBIN_COUNT / gl_WorkGroupSize.x; const uint zbin_local = gl_LocalInvocationID.x * zbin_iter; for (uint i = 0u, l = zbin_local; i < zbin_iter; i++, l++) { diff --git a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_convolve_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_convolve_comp.glsl index bbb0e6fab00..6c5b22a7c51 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_convolve_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_convolve_comp.glsl @@ -26,7 +26,7 @@ float roughness_from_relative_mip(float prev_mip_roughness, float curr_mip_rough return curr_mip_roughness; #else /* The exponent should be 2 but result is a bit less blurry than expected in practice. */ - const float exponent = 3.0f; + constexpr float exponent = 3.0f; /* From linear roughness to GGX roughness input. */ float m_prev = pow(prev_mip_roughness, exponent); float m_curr = pow(curr_mip_roughness, exponent); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_irradiance_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_irradiance_comp.glsl index a38129e8cdc..c691fe73a8c 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_irradiance_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_irradiance_comp.glsl @@ -26,7 +26,7 @@ void main() /* First sum onto the local memory. */ uint valid_data_len = probe_remap_dispatch_size.x * probe_remap_dispatch_size.y; - const uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x; + constexpr uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x; for (uint i = 0; i < iter_count; i++) { uint index = gl_WorkGroupSize.x * i + gl_LocalInvocationIndex; if (index >= valid_data_len) { @@ -48,7 +48,7 @@ void main() local_sh_coefs[local_index][3] = sh.L1.Mp1; /* Parallel sum. */ - const uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y; + constexpr uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y; uint stride = group_size / 2; for (int i = 0; i < 10; i++) { barrier(); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_mapping_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_mapping_lib.glsl index 51d4d37632c..91bfd907b21 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_mapping_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_mapping_lib.glsl @@ -97,8 +97,9 @@ float2 sphere_probe_direction_to_uv(float3 L, float lod, SphereProbeUvArea uv_ar float sphere_probe_roughness_to_mix_fac(float roughness) { - const float scale = 1.0f / (SPHERE_PROBE_MIX_END_ROUGHNESS - SPHERE_PROBE_MIX_START_ROUGHNESS); - const float bias = scale * SPHERE_PROBE_MIX_START_ROUGHNESS; + constexpr float scale = 1.0f / + (SPHERE_PROBE_MIX_END_ROUGHNESS - SPHERE_PROBE_MIX_START_ROUGHNESS); + constexpr float bias = scale * SPHERE_PROBE_MIX_START_ROUGHNESS; return square(saturate(roughness * scale - bias)); } @@ -119,8 +120,8 @@ float sphere_probe_lod_to_roughness(float lod) /* Inverse of sphere_probe_roughness_to_lod. */ float mip_ratio = lod / float(SPHERE_PROBE_MIPMAP_LEVELS - 1); float a = mip_ratio; - const float b = 0.6f; /* Factor of ratio. */ - const float c = 0.4f; /* Factor of ratio_sqrt. */ + constexpr float b = 0.6f; /* Factor of ratio. */ + constexpr float c = 0.4f; /* Factor of ratio_sqrt. */ float b2 = square(b); float c2 = square(c); float c4 = square(c2); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_remap_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_remap_comp.glsl index 20b2b0fb286..59a2ea93e36 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_remap_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_remap_comp.glsl @@ -115,7 +115,7 @@ void main() { uint work_group_index = gl_NumWorkGroups.x * gl_WorkGroupID.y + gl_WorkGroupID.x; const uint local_index = gl_LocalInvocationIndex; - const uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y; + constexpr uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y; SphereProbeUvArea world_coord = reinterpret_as_atlas_coord(world_coord_packed); SphereProbeUvArea sample_coord = reinterpret_as_atlas_coord(probe_coord_packed); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_sunlight_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_sunlight_comp.glsl index cd5ae5fe16c..f2ea5a481a3 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_sunlight_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_lightprobe_sphere_sunlight_comp.glsl @@ -26,7 +26,7 @@ void main() /* First sum onto the local memory. */ uint valid_data_len = probe_remap_dispatch_size.x * probe_remap_dispatch_size.y; - const uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x; + constexpr uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x; for (uint i = 0; i < iter_count; i++) { uint index = gl_WorkGroupSize.x * i + gl_LocalInvocationIndex; if (index >= valid_data_len) { @@ -42,7 +42,7 @@ void main() local_direction[local_index] = sun.direction; /* Parallel sum. */ - const uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y; + constexpr uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y; uint stride = group_size / 2; for (int i = 0; i < 10; i++) { barrier(); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ltc_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ltc_lib.glsl index 0a1e3aa87aa..00d803d7f2e 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ltc_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ltc_lib.glsl @@ -230,8 +230,8 @@ float ltc_evaluate_disk( float d11 = dot(V1, V1); float d22 = dot(V2, V2); float d12 = dot(V1, V2); - float a, inv_b; /* Eigenvalues */ - const float threshold = 0.0007f; /* Can be adjusted. Fix artifacts. */ + float a, inv_b; /* Eigenvalues */ + constexpr float threshold = 0.0007f; /* Can be adjusted. Fix artifacts. */ if (abs(d12) / sqrt(d11 * d22) > threshold) { float tr = d11 + d22; float det = -d12 * d12 + d11 * d22; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_lut_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_lut_comp.glsl index 6a2488e3917..80f9af64cf5 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_lut_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_lut_comp.glsl @@ -37,7 +37,7 @@ float4 ggx_brdf_split_sum(float3 lut_coord) float scale = 0.0f; float bias = 0.0f; float metal_bias = 0.0f; - const uint sample_count = 512u * 512u; + constexpr uint sample_count = 512u * 512u; for (uint i = 0u; i < sample_count; i++) { float2 rand = hammersley_2d(i, sample_count); float3 Xi = sample_cylinder(rand); @@ -98,7 +98,7 @@ float4 ggx_bsdf_split_sum(float3 lut_coord) float scale = 0.0f; float bias = 0.0f; float transmission_factor = 0.0f; - const uint sample_count = 512u * 512u; + constexpr uint sample_count = 512u * 512u; for (uint i = 0u; i < sample_count; i++) { float2 rand = hammersley_2d(i, sample_count); float3 Xi = sample_cylinder(rand); @@ -163,7 +163,7 @@ float4 ggx_btdf_gt_one(float3 lut_coord) /* Integrating BTDF. */ float transmission_factor = 0.0f; - const uint sample_count = 512u * 512u; + constexpr uint sample_count = 512u * 512u; for (uint i = 0u; i < sample_count; i++) { float2 rand = hammersley_2d(i, sample_count); float3 Xi = sample_cylinder(rand); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl index 6d5915010b9..c2ae119fdcb 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_nodetree_lib.glsl @@ -486,9 +486,9 @@ void brdf_f82_tint_lut(float3 F0, * model multiplied by the tint input. * Therefore, the factor follows by setting `F82Tint(cosI) = FSchlick(cosI) - b*cosI*(1-cosI)^6` * and `F82Tint(acos(1/7)) = FSchlick(acos(1/7)) * f82_tint` and solving for `b`. */ - const float f = 6.0f / 7.0f; - const float f5 = (f * f) * (f * f) * f; - const float f6 = (f * f) * (f * f) * (f * f); + constexpr float f = 6.0f / 7.0f; + constexpr float f5 = (f * f) * (f * f) * f; + constexpr float f6 = (f * f) * (f * f) * (f * f); float3 F_schlick = mix(F0, float3(1.0f), f5); float3 b = F_schlick * (7.0f / f6) * (1.0f - F82); reflectance -= b * split_sum.z; @@ -624,7 +624,7 @@ float3 displacement_bump() # if defined(GPU_FRAGMENT_SHADER) && !defined(MAT_GEOM_CURVES) /* This is the filter width for automatic displacement + bump mapping, which is fixed. * NOTE: keep the same as default bump node filter width. */ - const float bump_filter_width = 0.1f; + constexpr float bump_filter_width = 0.1f; float2 dHd; dF_branch(dot(nodetree_displacement(), g_data.N + dF_impl(g_data.N)), bump_filter_width, dHd); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_bilateral_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_bilateral_comp.glsl index f65bd854315..92110782671 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_bilateral_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_bilateral_comp.glsl @@ -40,7 +40,7 @@ float3 from_accumulation_space(float3 color) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); float2 center_uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_spatial_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_spatial_comp.glsl index 92d491647af..4b79a2fd0f4 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_spatial_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_spatial_comp.glsl @@ -52,7 +52,7 @@ void invalid_pixel_write(int2 texel) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_temporal_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_temporal_comp.glsl index dc73b2e5ba9..dcd8367e95b 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_temporal_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_denoise_temporal_comp.glsl @@ -167,7 +167,7 @@ float2 variance_history_sample(float3 P) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); float2 uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_comp.glsl index a7859187515..d04a715b049 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_comp.glsl @@ -18,7 +18,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_generate) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_lib.glsl index bc515439da6..6c9d9f517bc 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_generate_lib.glsl @@ -22,7 +22,7 @@ BsdfSample ray_generate_direction(float2 noise, ClosureUndetermined cl, float3 V { float3 random_point_on_cylinder = sample_cylinder(noise); /* Bias the rays so we never get really high energy rays almost parallel to the surface. */ - const float rng_bias = 0.08f; + constexpr float rng_bias = 0.08f; /* When modeling object thickness as a sphere, the outgoing rays are distributed uniformly * over the sphere. We don't want the RAY_BIAS in this case. */ if (cl.type != CLOSURE_BSDF_TRANSLUCENT_ID || thickness <= 0.0f) { diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_fallback_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_fallback_comp.glsl index 92171fee78a..4fdc69f6c3a 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_fallback_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_fallback_comp.glsl @@ -21,7 +21,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_fallback) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_planar_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_planar_comp.glsl index 030bd0d9ee6..e895ebdeab8 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_planar_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_planar_comp.glsl @@ -23,7 +23,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_planar) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_comp.glsl index 82ad0adfb57..71c20b1532f 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_comp.glsl @@ -22,7 +22,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_screen) void main() { - const uint tile_size = RAYTRACE_GROUP_SIZE; + constexpr uint tile_size = RAYTRACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_lib.glsl index 45cb640ac3c..75c2cee8127 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_trace_screen_lib.glsl @@ -108,7 +108,7 @@ METAL_ATTR ScreenTraceHitData raytrace_screen(RayTraceData rt_data, #ifdef METAL_AMD_RAYTRACE_WORKAROUND bool hit_failsafe = true; #endif - const int max_steps = 255; + constexpr int max_steps = 255; for (int iter = 1; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) { float stride = 1.0f + float(iter) * rt_data.quality; float lod = log2(stride) * lod_fac; @@ -191,7 +191,7 @@ ScreenTraceHitData raytrace_planar(RayTraceData rt_data, float t = 0.0f, time = 0.0f; bool hit = false; - const int max_steps = 32; + constexpr int max_steps = 32; for (int iter = 1; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) { float stride = 1.0f + float(iter) * rt_data.quality; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl index 42b9e46fe5a..a48896058c9 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_ray_types_lib.glsl @@ -24,7 +24,7 @@ void raytrace_screenspace_ray_finalize(inout ScreenSpaceRay ray, float2 pixel_si /* Constant bias (due to depth buffer precision). Helps with self intersection. */ /* Magic numbers for 24bits of precision. * From http://terathon.com/gdc07_lengyel.pdf (slide 26) */ - const float bias = -2.4e-7f * 2.0f; + constexpr float bias = -2.4e-7f * 2.0f; ray.origin.zw += bias; ray.direction.zw += bias; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_debug_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_debug_frag.glsl index 68abc8ed2ac..c645268df06 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_debug_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_debug_frag.glsl @@ -125,7 +125,7 @@ LightData debug_light_get() /** Return true if a pixel was written. */ bool debug_tilemaps(float3 P, LightData light, bool do_debug_sample_tile) { - const int debug_tile_size_px = 4; + constexpr int debug_tile_size_px = 4; int2 px = int2(gl_FragCoord.xy) / debug_tile_size_px; int tilemap = px.x / SHADOW_TILEMAP_RES; int tilemap_index = light.tilemap_index + tilemap; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl index e573eda7767..5384d531fc3 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_lib.glsl @@ -25,8 +25,8 @@ float shadow_read_depth(SHADOW_ATLAS_TYPE atlas_tx, return -1.0f; } /* Using bitwise ops is way faster than integer ops. */ - const uint page_shift = uint(SHADOW_PAGE_LOD); - const uint page_mask = ~(0xFFFFFFFFu << uint(SHADOW_PAGE_LOD)); + constexpr uint page_shift = uint(SHADOW_PAGE_LOD); + constexpr uint page_mask = ~(0xFFFFFFFFu << uint(SHADOW_PAGE_LOD)); uint2 texel = coord.tilemap_texel; /* Shift LOD0 pixels so that they get wrapped at the right position for the given LOD. */ diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_page_mask_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_page_mask_comp.glsl index e166e193b38..9d42896fd00 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_page_mask_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_page_mask_comp.glsl @@ -34,7 +34,7 @@ int shadow_tile_offset_lds(int2 tile, int lod) * coordinate fits the given tilemap LOD. */ bool thread_mask(int2 tile_co, int lod) { - const uint lod_size = uint(SHADOW_TILEMAP_RES); + constexpr uint lod_size = uint(SHADOW_TILEMAP_RES); return all(lessThan(tile_co, int2(lod_size >> lod))); } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tag_update_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tag_update_comp.glsl index 61ff18a968c..e356e43d89c 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tag_update_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tag_update_comp.glsl @@ -96,7 +96,7 @@ void main() } /* Raster the bounding rectangle of the Box projection. */ - const float tilemap_half_res = float(SHADOW_TILEMAP_RES / 2); + constexpr float tilemap_half_res = float(SHADOW_TILEMAP_RES / 2); int2 box_min = int2(aabb_tag.min.xy * tilemap_half_res + tilemap_half_res); int2 box_max = int2(aabb_tag.max.xy * tilemap_half_res + tilemap_half_res); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_amend_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_amend_comp.glsl index 93f0450f712..dff834bae9b 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_amend_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_amend_comp.glsl @@ -115,7 +115,7 @@ void main() if (lod_min > 0) { /* Override the effective lod min distance in absolute mode (negative). * Note that this only changes the sampling for this AA sample. */ - const float projection_diagonal = 2.0f * M_SQRT2; + constexpr float projection_diagonal = 2.0f * M_SQRT2; light_buf[l_idx].lod_min = -(projection_diagonal / float(SHADOW_MAP_MAX_RES >> lod_min)); } } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_lib.glsl index 7bd3764cec0..2b798debba4 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tilemap_lib.glsl @@ -55,17 +55,17 @@ int shadow_tile_offset(uint2 tile, int tiles_index, int lod) #if SHADOW_TILEMAP_LOD > 5 # error This needs to be adjusted #endif - const int lod0_width = SHADOW_TILEMAP_RES / 1; - const int lod1_width = SHADOW_TILEMAP_RES / 2; - const int lod2_width = SHADOW_TILEMAP_RES / 4; - const int lod3_width = SHADOW_TILEMAP_RES / 8; - const int lod4_width = SHADOW_TILEMAP_RES / 16; - const int lod5_width = SHADOW_TILEMAP_RES / 32; - const int lod0_size = lod0_width * lod0_width; - const int lod1_size = lod1_width * lod1_width; - const int lod2_size = lod2_width * lod2_width; - const int lod3_size = lod3_width * lod3_width; - const int lod4_size = lod4_width * lod4_width; + constexpr int lod0_width = SHADOW_TILEMAP_RES / 1; + constexpr int lod1_width = SHADOW_TILEMAP_RES / 2; + constexpr int lod2_width = SHADOW_TILEMAP_RES / 4; + constexpr int lod3_width = SHADOW_TILEMAP_RES / 8; + constexpr int lod4_width = SHADOW_TILEMAP_RES / 16; + constexpr int lod5_width = SHADOW_TILEMAP_RES / 32; + constexpr int lod0_size = lod0_width * lod0_width; + constexpr int lod1_size = lod1_width * lod1_width; + constexpr int lod2_size = lod2_width * lod2_width; + constexpr int lod3_size = lod3_width * lod3_width; + constexpr int lod4_size = lod4_width * lod4_width; /* TODO(fclem): Convert everything to uint. */ int offset = tiles_index; @@ -132,7 +132,7 @@ int shadow_directional_tilemap_index(LightData light, float3 lP) int lvl; if (light.type == LIGHT_SUN) { /* We need to hide one tile worth of data to hide the moving transition. */ - const float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f); + constexpr float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f); /* Avoid using log2 when we can just get the exponent from the floating point. */ frexp(reduce_max(abs(lP)) * narrowing * 2.0f, lvl); } @@ -158,7 +158,7 @@ float shadow_directional_level_fractional(LightData light, float3 lP) float lod; if (light.type == LIGHT_SUN) { /* We need to hide one tile worth of data to hide the moving transition. */ - const float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f); + constexpr float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f); /* Since the distance is centered around the camera (and thus by extension the tile-map), * we need to multiply by 2 to get the lod level which covers the following range: * [-coverage_get(lod)/2..coverage_get(lod)/2] */ @@ -168,7 +168,7 @@ float shadow_directional_level_fractional(LightData light, float3 lP) } else { /* The narrowing need to be stronger since the tile-map position is not rounded but floored. */ - const float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 2.5001f); + constexpr float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 2.5001f); /* Since we want half of the size, bias the level by -1. */ float clipmap_lod_min_minus_one = float(light_sun_data_get(light).clipmap_lod_min - 1); float lod_min_half_size = exp2(clipmap_lod_min_minus_one); @@ -214,7 +214,7 @@ float shadow_punctual_pixel_ratio(LightData light, /* Clamp in shadow space. */ film_pixel_footprint = max(film_pixel_footprint, -light.lod_min); /* Cube-face diagonal divided by LOD0 resolution. */ - const float shadow_pixel_radius = (2.0f * M_SQRT2) / SHADOW_MAP_MAX_RES; + constexpr float shadow_pixel_radius = (2.0f * M_SQRT2) / SHADOW_MAP_MAX_RES; return saturate(shadow_pixel_radius / film_pixel_footprint); } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tracing_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tracing_lib.glsl index 0f503792d03..bde1d4e9862 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_shadow_tracing_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_shadow_tracing_lib.glsl @@ -393,7 +393,7 @@ float shadow_texel_radius_at_position(LightData light, const bool is_directional } /* Pixel bounding radius inside a tilemap of unit scale. * Take only half of it because we want the radius and not the diameter. */ - const float texel_radius = M_SQRT2 / SHADOW_MAP_MAX_RES; + constexpr float texel_radius = M_SQRT2 / SHADOW_MAP_MAX_RES; return texel_radius * scale; } diff --git a/source/blender/draw/engines/eevee/shaders/eevee_spherical_harmonics_lib.glsl b/source/blender/draw/engines/eevee/shaders/eevee_spherical_harmonics_lib.glsl index 40703c63332..ea8be43a1a1 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_spherical_harmonics_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_spherical_harmonics_lib.glsl @@ -468,7 +468,7 @@ SphericalHarmonicL1 spherical_harmonics_triple_product(SphericalHarmonicL1 a, /* Adapted from: * "Code Generation and Factoring for Fast Evaluation of Low-order Spherical Harmonic Products * and Squares" Function "SH_product_3". */ - const float L0_M0_coef = 0.282094792f; + constexpr float L0_M0_coef = 0.282094792f; SphericalHarmonicL1 sh; sh.L0.M0 = a.L0.M0 * b.L0.M0; sh.L0.M0 += a.L1.Mn1 * b.L1.Mn1; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_subsurface_convolve_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_subsurface_convolve_comp.glsl index b99c911246f..d4a1e3cdb5b 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_subsurface_convolve_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_subsurface_convolve_comp.glsl @@ -84,7 +84,7 @@ SubSurfaceSample sample_neighborhood(float2 sample_uv) void main() { - const uint tile_size = SUBSURFACE_GROUP_SIZE; + constexpr uint tile_size = SUBSURFACE_GROUP_SIZE; uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]); int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size); diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl index 27ffa410d42..4df43244088 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_deferred_frag.glsl @@ -76,9 +76,9 @@ void main() int2 out_texel = int2(gl_FragCoord.xy); #ifdef MAT_SUBSURFACE - const bool use_sss = true; + constexpr bool use_sss = true; #else - const bool use_sss = false; + constexpr bool use_sss = false; #endif ObjectInfos object_infos = drw_infos[drw_resource_id()]; @@ -140,7 +140,7 @@ void main() gbuf.N[layer].xyyy); } if (use_sss || use_light_linking) { - const int layer = GBUF_HEADER_FB_LAYER_COUNT; + constexpr int layer = GBUF_HEADER_FB_LAYER_COUNT; /* NOTE: The image view start at layer GBUF_HEADER_FB_LAYER_COUNT so all destination layer is * `layer - GBUF_HEADER_FB_LAYER_COUNT`. */ imageStoreFast(out_gbuf_header_img, diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl index e1373e617c1..b87d0e70975 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_hybrid_frag.glsl @@ -79,9 +79,9 @@ void main() int2 out_texel = int2(gl_FragCoord.xy); #ifdef MAT_SUBSURFACE - const bool use_sss = true; + constexpr bool use_sss = true; #else - const bool use_sss = false; + constexpr bool use_sss = false; #endif ObjectInfos object_infos = drw_infos[drw_resource_id()]; @@ -143,7 +143,7 @@ void main() gbuf.N[layer].xyyy); } if (use_sss || use_light_linking) { - const int layer = GBUF_HEADER_FB_LAYER_COUNT; + constexpr int layer = GBUF_HEADER_FB_LAYER_COUNT; /* NOTE: The image view start at layer GBUF_HEADER_FB_LAYER_COUNT so all destination layer is * `layer - GBUF_HEADER_FB_LAYER_COUNT`. */ imageStoreFast(out_gbuf_header_img, diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl index 76526967b1e..d011653d0fb 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surf_shadow_frag.glsl @@ -70,8 +70,8 @@ void main() int2 texel_co = int2(gl_FragCoord.xy); /* Using bitwise ops is way faster than integer ops. */ - const int page_shift = SHADOW_PAGE_LOD; - const int page_mask = ~(0xFFFFFFFF << SHADOW_PAGE_LOD); + constexpr int page_shift = SHADOW_PAGE_LOD; + constexpr int page_mask = ~(0xFFFFFFFF << SHADOW_PAGE_LOD); int2 tile_co = texel_co >> page_shift; int2 texel_page = texel_co & page_mask; diff --git a/source/blender/draw/engines/eevee/shaders/eevee_surfel_ray_comp.glsl b/source/blender/draw/engines/eevee/shaders/eevee_surfel_ray_comp.glsl index 6d5d773b87c..c2f64b7b72c 100644 --- a/source/blender/draw/engines/eevee/shaders/eevee_surfel_ray_comp.glsl +++ b/source/blender/draw/engines/eevee/shaders/eevee_surfel_ray_comp.glsl @@ -34,7 +34,7 @@ void radiance_transfer(inout Surfel surfel, float3 in_radiance, float in_visibil float NL = dot(surfel.normal, L); /* Lambertian BSDF. Albedo applied later depending on which side of the surfel was hit. */ - const float bsdf = M_1_PI; + constexpr float bsdf = M_1_PI; /* From "Global Illumination using Parallel Global Ray-Bundles" * Eq. 3: Outgoing light */ float transfert_fn = (M_TAU / capture_info_buf.sample_count) * bsdf * abs(NL); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl index 375de87116f..868b5104a4f 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl @@ -43,7 +43,7 @@ float3x3 compute_mat(float4 sphere, float3 bone_vec, out float z_ofs) * can be bigger than the center disc. Compute the * max angular size and compensate by sliding the disc * towards the camera and scale it accordingly. */ - const float half_pi = 3.1415926f * 0.5f; + constexpr float half_pi = 3.1415926f * 0.5f; float rad = sphere.w; /* Let be : * V the view vector origin. diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_frag.glsl index 03f163d1433..8ca953066de 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_frag.glsl @@ -17,7 +17,7 @@ void main() } else { /* Smooth lighting factor. */ - const float s = 0.2f; /* [0.0f-0.5f] range */ + constexpr float s = 0.2f; /* [0.0f-0.5f] range */ float fac = clamp((n * (1.0f - s)) + s, 0.0f, 1.0f); fragColor.rgb = mix(finalStateColor, finalBoneColor, fac * fac); fragColor.a = alpha; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl index e4fd8d55b40..3f1f3a10dc4 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_vert.glsl @@ -22,7 +22,7 @@ void main() float sinb = (data_buf[gl_InstanceID].tail_sphere.w - data_buf[gl_InstanceID].head_sphere.w) * bone_lenrcp; #else - const float sinb = 0.0f; + constexpr float sinb = 0.0f; #endif float3 y_axis = bone_vec * bone_lenrcp; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert.glsl index e1b2a1f4e22..7e5812c6054 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert.glsl @@ -164,15 +164,15 @@ void main() select_id_set(in_select_buf[gl_InstanceID]); /* Line Adjacency primitive. */ - const uint input_primitive_vertex_count = 4u; + constexpr uint input_primitive_vertex_count = 4u; /* Line list primitive. */ - const uint ouput_primitive_vertex_count = 2u; - const uint ouput_primitive_count = 1u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 2u; + constexpr uint ouput_primitive_count = 1u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl index 93dcf4dd57c..39e5d9907a6 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_vert.glsl @@ -27,11 +27,11 @@ void main() inverted = int(dot(cross(model_mat[0].xyz, model_mat[1].xyz), model_mat[2].xyz) < 0.0f); /* Do lighting at an angle to avoid flat shading on front facing bone. */ - const float3 light = float3(0.1f, 0.1f, 0.8f); + constexpr float3 light = float3(0.1f, 0.1f, 0.8f); float n = dot(normal, light); /* Smooth lighting factor. */ - const float s = 0.2f; /* [0.0f-0.5f] range */ + constexpr float s = 0.2f; /* [0.0f-0.5f] range */ float fac = clamp((n * (1.0f - s)) + s, 0.0f, 1.0f); finalColor.rgb = mix(state_color.rgb, bone_color.rgb, fac * fac); finalColor.a = 1.0f; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_frag.glsl index f863a5d9159..d1ead191dbe 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_frag.glsl @@ -6,6 +6,7 @@ FRAGMENT_SHADER_CREATE_INFO(overlay_armature_shape_wire) +#include "gpu_shader_utildefines_lib.glsl" #include "select_lib.glsl" /** @@ -37,7 +38,7 @@ void main() float half_size = (do_smooth_wire ? wire_width - 0.5f : wire_width) / 2.0f; float dist = abs(edgeCoord) - half_size; - const float mix_w = clamp(edge_step(dist), 0.0f, 1.0f); + float mix_w = saturate(edge_step(dist)); fragColor = mix(float4(finalColor.rgb, alpha), float4(0), mix_w); fragColor.a *= 1.0f - mix_w; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_vert.glsl index 055239bb2e9..ba49a88b0a5 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_wire_vert.glsl @@ -187,18 +187,18 @@ void main() /* Line primitive. */ #ifdef FROM_LINE_STRIP - const uint input_primitive_vertex_count = 1u; + constexpr uint input_primitive_vertex_count = 1u; #else - const uint input_primitive_vertex_count = 2u; + constexpr uint input_primitive_vertex_count = 2u; #endif /* Triangle list primitive. */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 2u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 2u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl index b4969f7a139..f72f83e1bf6 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl @@ -49,8 +49,8 @@ void main() * can be bigger than the center disc. Compute the * max angular size and compensate by sliding the disc * towards the camera and scale it accordingly. */ - const float half_pi = 3.1415926f * 0.5f; - const float rad = 0.05f; + constexpr float half_pi = 3.1415926f * 0.5f; + constexpr float rad = 0.05f; /* Let be (in local space): * V the view vector origin. * O the sphere origin. diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_frag.glsl index 1829770ee78..7b9aa910a7c 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_frag.glsl @@ -11,7 +11,7 @@ FRAGMENT_SHADER_CREATE_INFO(overlay_armature_sphere_solid) void main() { - const float sphere_radius = 0.05f; + constexpr float sphere_radius = 0.05f; bool is_perp = (drw_view().winmat[3][3] == 0.0f); float3 ray_ori_view = (is_perp) ? float3(0.0f) : viewPosition.xyz; @@ -32,7 +32,7 @@ void main() ray_dir /= ray_len; /* Line to sphere intersect */ - const float sphere_radius_sqr = sphere_radius * sphere_radius; + constexpr float sphere_radius_sqr = sphere_radius * sphere_radius; float b = dot(ray_ori, ray_dir); float c = dot(ray_ori, ray_ori) - sphere_radius_sqr; float h = b * b - c; @@ -44,7 +44,7 @@ void main() float3 l = normalize(sphereMatrix[2].xyz); /* Just the view Z axis in the sphere space. */ /* Smooth lighting factor. */ - const float s = 0.2f; /* [0.0f-0.5f] range */ + constexpr float s = 0.2f; /* [0.0f-0.5f] range */ float fac = clamp((dot(n, l) * (1.0f - s)) + s, 0.0f, 1.0f); fragColor.rgb = mix(finalStateColor, finalBoneColor, fac * fac); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_vert.glsl index a315ff7ce63..320ba2dbf3f 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_vert.glsl @@ -47,7 +47,7 @@ void main() * can be bigger than the center disc. Compute the * max angular size and compensate by sliding the disc * towards the camera and scale it accordingly. */ - const float half_pi = 3.1415926f * 0.5f; + constexpr float half_pi = 3.1415926f * 0.5f; /* Let be (in local space): * V the view vector origin. * O the sphere origin. diff --git a/source/blender/draw/engines/overlay/shaders/overlay_background_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_background_frag.glsl index eea3f6b97ab..e2c6b55c679 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_background_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_background_frag.glsl @@ -15,10 +15,10 @@ float dither() { /* NOTE(Metal): Declaring constant array in function scope to avoid increasing local shader * memory pressure. */ - const float4 dither_mat4x4[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)), - float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)), - float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)), - float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f))); + constexpr float4 dither_mat4x4[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)), + float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)), + float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)), + float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f))); int2 co = int2(gl_FragCoord.xy) % 4; return dither_mat4x4[co.x][co.y]; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_common_lib.glsl b/source/blender/draw/engines/overlay/shaders/overlay_common_lib.glsl index 29d10c4dbf3..5c12ed6dc1f 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_common_lib.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_common_lib.glsl @@ -24,7 +24,7 @@ float4x4 extract_matrix_packed_data(float4x4 mat, out float4 dataA, out float4 dataB) { - const float div = 1.0f / 255.0f; + constexpr float div = 1.0f / 255.0f; int a = int(mat[0][3]); int b = int(mat[1][3]); int c = int(mat[2][3]); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_depth_only_mesh_conservative_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_depth_only_mesh_conservative_vert.glsl index 615b17f086f..4c978225d87 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_depth_only_mesh_conservative_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_depth_only_mesh_conservative_vert.glsl @@ -89,7 +89,7 @@ void geometry_main(VertOut geom_in[3], /* Detect failure cases where triangles would produce no fragments. */ bool2 is_subpixel = lessThan(bbox.zw - bbox.xy, float2(1.0f)); /* View aligned triangle. */ - const float threshold = 0.00001f; + constexpr float threshold = 0.00001f; bool is_coplanar = abs(plane.z) < threshold; do_vertex(0, out_vertex_id, out_primitive_id, geom_in[0], is_subpixel, is_coplanar); @@ -102,15 +102,15 @@ void main() select_id_set(drw_custom_id()); /* Triangle list primitive. */ - const uint input_primitive_vertex_count = 3u; + constexpr uint input_primitive_vertex_count = 3u; /* Triangle list primitive. */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 1u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 1u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_vert.glsl index 1ecf2efb07a..a2c449d28b0 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_vert.glsl @@ -192,15 +192,15 @@ void geometry_main(VertOut geom_in[2], void main() { /* Line list primitive. */ - const uint input_primitive_vertex_count = 2u; + constexpr uint input_primitive_vertex_count = 2u; /* Triangle list primitive (emulating triangle strip). */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 8u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 8u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_normals_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_normals_vert.glsl index 16a96a3cac4..bdf1ed51828 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_normals_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_normals_vert.glsl @@ -15,15 +15,15 @@ VERTEX_SHADER_CREATE_INFO(overlay_edit_curve_normals) void main() { /* Line list primitive. */ - const uint input_primitive_vertex_count = 2u; + constexpr uint input_primitive_vertex_count = 2u; /* Line list primitive. */ - const uint ouput_primitive_vertex_count = 2u; - const uint ouput_primitive_count = 2u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 2u; + constexpr uint ouput_primitive_count = 2u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_curves_handle_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_curves_handle_vert.glsl index c530c67a94a..094d409b8d6 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_curves_handle_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_curves_handle_vert.glsl @@ -201,15 +201,15 @@ void geometry_main(VertOut geom_in[2], void main() { /* Line list primitive. */ - const uint input_primitive_vertex_count = 2u; + constexpr uint input_primitive_vertex_count = 2u; /* Triangle list primitive (emulating triangle strip). */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 8u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 8u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_edge_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_edge_vert.glsl index 92c7a442278..c0448e1e9eb 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_edge_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_edge_vert.glsl @@ -148,15 +148,15 @@ void geometry_main(VertOut geom_in[2], uint out_vert_id, uint out_prim_id, uint void main() { /* Line list primitive. */ - const uint input_primitive_vertex_count = 2u; + constexpr uint input_primitive_vertex_count = 2u; /* Triangle list primitive. */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 2u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 2u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_normal_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_normal_vert.glsl index ab11a4310db..1e0f8b39a63 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_normal_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_normal_vert.glsl @@ -30,16 +30,16 @@ void main() #if defined(FACE_NORMAL) || defined(VERT_NORMAL) || defined(LOOP_NORMAL) /* Point primitive. */ - const uint input_primitive_vertex_count = 1u; + constexpr uint input_primitive_vertex_count = 1u; /* Line list primitive. */ - const uint ouput_primitive_vertex_count = 2u; - const uint ouput_primitive_count = 1u; - const uint ouput_invocation_count = 1u; + constexpr uint ouput_primitive_vertex_count = 2u; + constexpr uint ouput_primitive_count = 1u; + constexpr uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl index 94a7baa3857..7fcc002562a 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl @@ -156,16 +156,16 @@ void geometry_main(VertOut geom_in[2], void main() { /* Line list primitive. */ - const uint input_primitive_vertex_count = 2u; + constexpr uint input_primitive_vertex_count = 2u; /* Triangle list primitive. */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 2u; - const uint ouput_invocation_count = 1u; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 2u; + constexpr uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_verts_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_verts_vert.glsl index 076d3352bac..d7155f11b22 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_verts_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_verts_vert.glsl @@ -12,7 +12,7 @@ VERTEX_SHADER_CREATE_INFO(overlay_edit_uv_verts) void main() { /* TODO: Theme? */ - const float4 pinned_col = float4(1.0f, 0.0f, 0.0f, 1.0f); + constexpr float4 pinned_col = float4(1.0f, 0.0f, 0.0f, 1.0f); bool is_selected = (flag & (VERT_UV_SELECT | FACE_UV_SELECT)) != 0u; bool is_pinned = (flag & VERT_UV_PINNED) != 0u; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl index 158e5f0e480..fe8b97cd8bb 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl @@ -205,7 +205,7 @@ void main() if ((vclass & VCLASS_LIGHT_SPOT_CONE) != 0) { /* Compute point on the cone before and after this one. */ float2 perp = float2(pos.y, -pos.x); - const float incr_angle = 2.0f * 3.1415f / 32.0f; + constexpr float incr_angle = 2.0f * 3.1415f / 32.0f; const float2 slope = float2(cos(incr_angle), sin(incr_angle)); float3 p0 = float3((pos.xy * slope.x + perp * slope.y) * lamp_spot_sine, -lamp_spot_cosine); float3 p1 = float3((pos.xy * slope.x - perp * slope.y) * lamp_spot_sine, -lamp_spot_cosine); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_frag.glsl index 660a807c839..0790f538148 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_frag.glsl @@ -14,8 +14,8 @@ void main() fragColor = finalColor; /* Stipple */ - const float dash_width = 6.0f; - const float dash_factor = 0.5f; + constexpr float dash_width = 6.0f; + constexpr float dash_factor = 0.5f; lineOutput = pack_line_data(gl_FragCoord.xy, stipple_start, stipple_coord); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl index b77b36eb99e..b3e052a9e74 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert.glsl @@ -134,16 +134,16 @@ void geometry_main(VertOut geom_in[2], void main() { /* Point list primitive. */ - const uint input_primitive_vertex_count = 1u; + constexpr uint input_primitive_vertex_count = 1u; /* Triangle list primitive. */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 2u; - const uint ouput_invocation_count = 1u; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 2u; + constexpr uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl index c4ae67813a5..b7249744753 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl @@ -249,7 +249,7 @@ void main() float scene_depth = textureLod(sceneDepth, depth_uv, 0.0f).r; /* Avoid bad cases of Z-fighting for occlusion only. */ - const float epsilon = 3.0f / 8388608.0f; + constexpr float epsilon = 3.0f / 8388608.0f; bool occluded = (ref_depth > scene_depth + epsilon); /* NOTE: We never set alpha to 1.0 to avoid Anti-aliasing destroying the line. */ diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_wire_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_wire_vert.glsl index 83cfae8c7eb..035dca23ac2 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_wire_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_wire_vert.glsl @@ -112,15 +112,15 @@ void geometry_main(VertOut geom_in[4], void main() { /* Line adjacency list primitive. */ - const uint input_primitive_vertex_count = 4u; + constexpr uint input_primitive_vertex_count = 4u; /* Line list primitive. */ - const uint ouput_primitive_vertex_count = 2u; - const uint ouput_primitive_count = 1u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 2u; + constexpr uint ouput_primitive_count = 1u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_paint_weight_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_paint_weight_frag.glsl index fb7620a25c0..752c41147cd 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_paint_weight_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_paint_weight_frag.glsl @@ -9,9 +9,9 @@ FRAGMENT_SHADER_CREATE_INFO(overlay_paint_weight) float contours(float value, float steps, float width_px, float max_rel_width, float gradient) { /* Minimum visible and minimum full strength line width in screen space for fade out. */ - const float min_width_px = 1.3f, fade_width_px = 2.3f; + constexpr float min_width_px = 1.3f, fade_width_px = 2.3f; /* Line is thinner towards the increase in the weight gradient by this factor. */ - const float hi_bias = 2.0f; + constexpr float hi_bias = 2.0f; /* Don't draw lines at 0 or 1. */ float rel_value = value * steps; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_paint_wire_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_paint_wire_vert.glsl index 4433fdbb0bc..541dc8c7510 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_paint_wire_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_paint_wire_vert.glsl @@ -25,7 +25,7 @@ void main() gl_Position = float4(-2.0f, -2.0f, -2.0f, 1.0f); } - const float4 colSel = float4(1.0f); + constexpr float4 colSel = float4(1.0f); finalColor = (is_select) ? colSel : colorWire; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_point_varying_color_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_point_varying_color_frag.glsl index 6328423f50d..cd0e6b25011 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_point_varying_color_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_point_varying_color_frag.glsl @@ -12,7 +12,7 @@ void main() { float2 centered = gl_PointCoord - float2(0.5f); float dist_squared = dot(centered, centered); - const float rad_squared = 0.25f; + constexpr float rad_squared = 0.25f; /* Round point with jagged edges. */ if (dist_squared > rad_squared) { diff --git a/source/blender/draw/engines/overlay/shaders/overlay_volume_gridlines_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_volume_gridlines_vert.glsl index 78c9ff99107..336d67e3901 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_volume_gridlines_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_volume_gridlines_vert.glsl @@ -93,14 +93,14 @@ void main() #endif /* NOTE(Metal): Declaring constant arrays in function scope to avoid increasing local shader * memory pressure. */ - const int indices[8] = int_array(0, 1, 1, 2, 2, 3, 3, 0); + constexpr int indices[8] = int_array(0, 1, 1, 2, 2, 3, 3, 0); /* Corners for cell outlines. 0.45 is arbitrary. Any value below 0.5f can be used to avoid * overlapping of the outlines. */ - const float3 corners[4] = float3_array(float3(-0.45f, 0.45f, 0.0f), - float3(0.45f, 0.45f, 0.0f), - float3(0.45f, -0.45f, 0.0f), - float3(-0.45f, -0.45f, 0.0f)); + constexpr float3 corners[4] = float3_array(float3(-0.45f, 0.45f, 0.0f), + float3(0.45f, 0.45f, 0.0f), + float3(0.45f, -0.45f, 0.0f), + float3(-0.45f, -0.45f, 0.0f)); float3 pos = domainOriginOffset + cellSize * (float3(cell_co + adaptiveCellOffset) + cell_offset); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_volume_velocity_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_volume_velocity_vert.glsl index b887d3ef99d..be7bf17e0b9 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_volume_velocity_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_volume_velocity_vert.glsl @@ -183,12 +183,12 @@ void main() # ifdef USE_NEEDLE /* NOTE(Metal): Declaring constant arrays in function scope to avoid increasing local shader * memory pressure. */ - const float3 corners[4] = float3_array(float3(0.0f, 0.2f, -0.5f), - float3(-0.2f * 0.866f, -0.2f * 0.5f, -0.5f), - float3(0.2f * 0.866f, -0.2f * 0.5f, -0.5f), - float3(0.0f, 0.0f, 0.5f)); + constexpr float3 corners[4] = float3_array(float3(0.0f, 0.2f, -0.5f), + float3(-0.2f * 0.866f, -0.2f * 0.5f, -0.5f), + float3(0.2f * 0.866f, -0.2f * 0.5f, -0.5f), + float3(0.0f, 0.0f, 0.5f)); - const int indices[12] = int_array(0, 1, 1, 2, 2, 0, 0, 3, 1, 3, 2, 3); + constexpr int indices[12] = int_array(0, 1, 1, 2, 2, 0, 0, 3, 1, 3, 2, 3); float3 rotated_pos = rot_mat * corners[indices[gl_VertexID % 12]]; pos += rotated_pos * vector_length * displaySize * cellSize; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl index f3eb3cadcff..c94f461abab 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl @@ -41,11 +41,11 @@ float2 workbench_normal_encode(bool front_face, float3 n) /* Encode 2 float into 1 with the desired precision. */ float workbench_float_pair_encode(float v1, float v2) { - // const uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS); - // const uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS); + // constexpr uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS); + // constexpr uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS); /* Same as above because some compiler are very dumb and think we use medium int. */ - const int v1_mask = 0x1F; - const int v2_mask = 0x7; + constexpr int v1_mask = 0x1F; + constexpr int v2_mask = 0x7; int iv1 = int(v1 * float(v1_mask)); int iv2 = int(v2 * float(v2_mask)) << int(ROUGHNESS_BITS); return float(iv1 | iv2); @@ -53,11 +53,11 @@ float workbench_float_pair_encode(float v1, float v2) void workbench_float_pair_decode(float data, out float v1, out float v2) { - // const uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS); - // const uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS); + // constexpr uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS); + // constexpr uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS); /* Same as above because some compiler are very dumb and think we use medium int. */ - const int v1_mask = 0x1F; - const int v2_mask = 0x7; + constexpr int v1_mask = 0x1F; + constexpr int v2_mask = 0x7; int idata = int(data); v1 = float(idata & v1_mask) * (1.0f / float(v1_mask)); v2 = float(idata >> int(ROUGHNESS_BITS)) * (1.0f / float(v2_mask)); diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_caps_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_caps_vert.glsl index 69a093814d2..13eb30e8454 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_shadow_caps_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_caps_vert.glsl @@ -63,10 +63,10 @@ void geometry_main(VertOut geom_in[3], uint out_vertex_id, uint out_invocation_i /* In case of non manifold geom, we only increase/decrease * the stencil buffer by one but do every faces as they were facing the light. */ bool invert = backface; - const bool is_manifold = false; + constexpr bool is_manifold = false; #else - const bool invert = false; - const bool is_manifold = true; + constexpr bool invert = false; + constexpr bool is_manifold = true; #endif if (!is_manifold || !backface) { @@ -78,16 +78,16 @@ void geometry_main(VertOut geom_in[3], uint out_vertex_id, uint out_invocation_i void main() { /* Triangle list primitive. */ - const uint input_primitive_vertex_count = 3u; + constexpr uint input_primitive_vertex_count = 3u; /* Triangle list primitive. */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 1u; - const uint ouput_invocation_count = 2u; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 1u; + constexpr uint ouput_invocation_count = 2u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_debug_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_debug_frag.glsl index 6c6fb257139..0a2b74708db 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_shadow_debug_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_debug_frag.glsl @@ -8,7 +8,7 @@ FRAGMENT_SHADER_CREATE_INFO(workbench_shadow_debug) void main() { - const float a = 0.1f; + constexpr float a = 0.1f; #ifdef SHADOW_PASS out_debug_color.rgb = gl_FrontFacing ? float3(a, -a, 0.0f) : float3(-a, a, 0.0f); #else diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl index 0a08177a8fe..b82f63c51d5 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl @@ -112,19 +112,19 @@ void geometry_main(VertOut geom_in[4], void main() { /* Line adjacency primitive. */ - const uint input_primitive_vertex_count = 4u; + constexpr uint input_primitive_vertex_count = 4u; /* Triangle list primitive. */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 2u; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 2u; #ifdef DOUBLE_MANIFOLD - const uint ouput_invocation_count = 2u; + constexpr uint ouput_invocation_count = 2u; #else - const uint ouput_invocation_count = 1u; + constexpr uint ouput_invocation_count = 1u; #endif - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl index 09d5d4ad965..287368fe122 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl @@ -201,10 +201,10 @@ float4 volume_integration( { /* NOTE: Constant array declared inside function scope to reduce shader core thread memory * pressure on Apple Silicon. */ - const float4 dither_mat[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)), - float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)), - float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)), - float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f))); + constexpr float4 dither_mat[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)), + float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)), + float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)), + float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f))); /* Start with full transmittance and no scattered light. */ float3 final_scattering = float3(0.0f); float final_transmittance = 1.0f; @@ -237,7 +237,7 @@ float4 volume_integration( void main() { uint stencil = texelFetch(stencil_tx, int2(gl_FragCoord.xy), 0).r; - const uint in_front_stencil_bits = 1u << 1; + constexpr uint in_front_stencil_bits = 1u << 1; if (do_depth_test && (stencil & in_front_stencil_bits) != 0) { /* Don't draw on top of "in front" objects. */ discard; diff --git a/source/blender/gpu/shaders/common/gpu_shader_common_color_ramp.glsl b/source/blender/gpu/shaders/common/gpu_shader_common_color_ramp.glsl index 181347b1004..ca0f9b52b6c 100644 --- a/source/blender/gpu/shaders/common/gpu_shader_common_color_ramp.glsl +++ b/source/blender/gpu/shaders/common/gpu_shader_common_color_ramp.glsl @@ -37,9 +37,9 @@ float compute_color_map_coordinate(float coordinate) { /* Color maps have a fixed width of 257. We offset by the equivalent of half a pixel and scale * down such that the normalized coordinate 1.0 corresponds to the center of the last pixel. */ - const float sampler_resolution = 257.0f; - const float sampler_offset = 0.5f / sampler_resolution; - const float sampler_scale = 1.0f - (1.0f / sampler_resolution); + constexpr float sampler_resolution = 257.0f; + constexpr float sampler_offset = 0.5f / sampler_resolution; + constexpr float sampler_scale = 1.0f - (1.0f / sampler_resolution); return coordinate * sampler_scale + sampler_offset; } diff --git a/source/blender/gpu/shaders/common/gpu_shader_math_matrix_lib.glsl b/source/blender/gpu/shaders/common/gpu_shader_math_matrix_lib.glsl index bbf75bcb3bf..a1adf8dc87e 100644 --- a/source/blender/gpu/shaders/common/gpu_shader_math_matrix_lib.glsl +++ b/source/blender/gpu/shaders/common/gpu_shader_math_matrix_lib.glsl @@ -1521,7 +1521,7 @@ bool is_uniformly_scaled(float3x3 mat) if (!is_orthogonal(mat)) { return false; } - const float eps = 1e-7f; + constexpr float eps = 1e-7f; float x = length_squared(mat[0]); float y = length_squared(mat[1]); float z = length_squared(mat[2]); diff --git a/source/blender/gpu/shaders/common/gpu_shader_math_rotation_lib.glsl b/source/blender/gpu/shaders/common/gpu_shader_math_rotation_lib.glsl index 0eab7861c76..1476ebbdb6d 100644 --- a/source/blender/gpu/shaders/common/gpu_shader_math_rotation_lib.glsl +++ b/source/blender/gpu/shaders/common/gpu_shader_math_rotation_lib.glsl @@ -87,7 +87,7 @@ float2 interpolate_dot_slerp(float t, float cosom) { float2 w = float2(1.0f - t, t); /* Within [-1..1] range, avoid aligned axis. */ - const float eps = 1e-4f; + constexpr float eps = 1e-4f; if (abs(cosom) < 1.0f - eps) { float omega = acos(cosom); w = sin(w * omega) / sin(omega); diff --git a/source/blender/gpu/shaders/common/gpu_shader_math_vector_lib.glsl b/source/blender/gpu/shaders/common/gpu_shader_math_vector_lib.glsl index 1ce2f3b5f59..98c86174f5c 100644 --- a/source/blender/gpu/shaders/common/gpu_shader_math_vector_lib.glsl +++ b/source/blender/gpu/shaders/common/gpu_shader_math_vector_lib.glsl @@ -31,9 +31,9 @@ bool is_any_zero(float4 vec); * Return true if the deference between`a` and `b` is below the `epsilon` value. * Epsilon value is scaled by magnitude of `a` before comparison. */ -bool almost_equal_relative(float2 a, float2 b, const float epsilon_factor); -bool almost_equal_relative(float3 a, float3 b, const float epsilon_factor); -bool almost_equal_relative(float4 a, float4 b, const float epsilon_factor); +bool almost_equal_relative(float2 a, float2 b, float epsilon_factor); +bool almost_equal_relative(float3 a, float3 b, float epsilon_factor); +bool almost_equal_relative(float4 a, float4 b, float epsilon_factor); /** * Safe `a` modulo `b`. @@ -209,9 +209,9 @@ int2 orthogonal(int2 v); /** * Return true if the difference between`a` and `b` is below the `epsilon` value. */ -bool is_equal(float2 a, float2 b, const float epsilon); -bool is_equal(float3 a, float3 b, const float epsilon); -bool is_equal(float4 a, float4 b, const float epsilon); +bool is_equal(float2 a, float2 b, float epsilon); +bool is_equal(float3 a, float3 b, float epsilon); +bool is_equal(float4 a, float4 b, float epsilon); /** * Return the maximum component of a vector. @@ -292,7 +292,7 @@ bool is_any_zero(float4 vec) return any(equal(vec, float4(0.0f))); } -bool almost_equal_relative(float2 a, float2 b, const float epsilon_factor) +bool almost_equal_relative(float2 a, float2 b, float epsilon_factor) { for (int i = 0; i < 2; i++) { if (abs(a[i] - b[i]) > epsilon_factor * abs(a[i])) { @@ -301,7 +301,7 @@ bool almost_equal_relative(float2 a, float2 b, const float epsilon_factor) } return true; } -bool almost_equal_relative(float3 a, float3 b, const float epsilon_factor) +bool almost_equal_relative(float3 a, float3 b, float epsilon_factor) { for (int i = 0; i < 3; i++) { if (abs(a[i] - b[i]) > epsilon_factor * abs(a[i])) { @@ -310,7 +310,7 @@ bool almost_equal_relative(float3 a, float3 b, const float epsilon_factor) } return true; } -bool almost_equal_relative(float4 a, float4 b, const float epsilon_factor) +bool almost_equal_relative(float4 a, float4 b, float epsilon_factor) { for (int i = 0; i < 4; i++) { if (abs(a[i] - b[i]) > epsilon_factor * abs(a[i])) { @@ -547,7 +547,7 @@ float3 project(float3 p, float3 v_proj) float2 normalize_and_get_length(float2 vector, out float out_length) { out_length = length_squared(vector); - const float threshold = 1e-35f; + constexpr float threshold = 1e-35f; if (out_length > threshold) { out_length = sqrt(out_length); return vector / out_length; @@ -559,7 +559,7 @@ float2 normalize_and_get_length(float2 vector, out float out_length) float3 normalize_and_get_length(float3 vector, out float out_length) { out_length = length_squared(vector); - const float threshold = 1e-35f; + constexpr float threshold = 1e-35f; if (out_length > threshold) { out_length = sqrt(out_length); return vector / out_length; @@ -571,7 +571,7 @@ float3 normalize_and_get_length(float3 vector, out float out_length) float4 normalize_and_get_length(float4 vector, out float out_length) { out_length = length_squared(vector); - const float threshold = 1e-35f; + constexpr float threshold = 1e-35f; if (out_length > threshold) { out_length = sqrt(out_length); return vector / out_length; @@ -584,7 +584,7 @@ float4 normalize_and_get_length(float4 vector, out float out_length) float2 safe_normalize_and_get_length(float2 vector, out float out_length) { out_length = length_squared(vector); - const float threshold = 1e-35f; + constexpr float threshold = 1e-35f; if (out_length > threshold) { out_length = sqrt(out_length); return vector / out_length; @@ -596,7 +596,7 @@ float2 safe_normalize_and_get_length(float2 vector, out float out_length) float3 safe_normalize_and_get_length(float3 vector, out float out_length) { out_length = length_squared(vector); - const float threshold = 1e-35f; + constexpr float threshold = 1e-35f; if (out_length > threshold) { out_length = sqrt(out_length); return vector / out_length; @@ -608,7 +608,7 @@ float3 safe_normalize_and_get_length(float3 vector, out float out_length) float4 safe_normalize_and_get_length(float4 vector, out float out_length) { out_length = length_squared(vector); - const float threshold = 1e-35f; + constexpr float threshold = 1e-35f; if (out_length > threshold) { out_length = sqrt(out_length); return vector / out_length; @@ -719,15 +719,15 @@ int2 orthogonal(int2 v) return int2(-v.y, v.x); } -bool is_equal(float2 a, float2 b, const float epsilon) +bool is_equal(float2 a, float2 b, float epsilon) { return all(lessThanEqual(abs(a - b), float2(epsilon))); } -bool is_equal(float3 a, float3 b, const float epsilon) +bool is_equal(float3 a, float3 b, float epsilon) { return all(lessThanEqual(abs(a - b), float3(epsilon))); } -bool is_equal(float4 a, float4 b, const float epsilon) +bool is_equal(float4 a, float4 b, float epsilon) { return all(lessThanEqual(abs(a - b), float4(epsilon))); } diff --git a/source/blender/gpu/shaders/common/gpu_shader_shared_exponent_lib.glsl b/source/blender/gpu/shaders/common/gpu_shader_shared_exponent_lib.glsl index 772668b865f..0e7d6b561fd 100644 --- a/source/blender/gpu/shaders/common/gpu_shader_shared_exponent_lib.glsl +++ b/source/blender/gpu/shaders/common/gpu_shader_shared_exponent_lib.glsl @@ -46,7 +46,7 @@ struct rgb9e5_t { rgb9e5_t rgb9e5_from_float3(float3 color) { - const float max_rgb9e5 = float(0xFF80u); + constexpr float max_rgb9e5 = float(0xFF80u); color = clamp(color, 0.0f, max_rgb9e5); float max_component = max(max(color.r, color.g), color.b); diff --git a/source/blender/gpu/shaders/common/gpu_shader_utildefines_lib.glsl b/source/blender/gpu/shaders/common/gpu_shader_utildefines_lib.glsl index b119e06beb9..1811a41c005 100644 --- a/source/blender/gpu/shaders/common/gpu_shader_utildefines_lib.glsl +++ b/source/blender/gpu/shaders/common/gpu_shader_utildefines_lib.glsl @@ -147,9 +147,9 @@ float orderedIntBitsToFloat(int int_value) */ float3 offset_ray(float3 P, float3 Ng) { - const float origin = 1.0f / 32.0f; - const float float_scale = 1.0f / 65536.0f; - const float int_scale = 256.0f; + constexpr float origin = 1.0f / 32.0f; + constexpr float float_scale = 1.0f / 65536.0f; + constexpr float int_scale = 256.0f; int3 of_i = int3(int_scale * Ng); of_i = int3((P.x < 0.0f) ? -of_i.x : of_i.x, diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 927b3b7a036..dc671a4e70b 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -224,6 +224,11 @@ template struct VecBase { }; template struct VecBase : VecOp { + private: + /* Weird non-zero value to avoid error about division by zero in constexpr. */ + static constexpr T V = T(0.123f); + + public: union { struct { T x, y; @@ -237,11 +242,17 @@ template struct VecBase : VecOp { VecBase() = default; template explicit VecBase(VecOp) {} - explicit VecBase(T) {} - explicit VecBase(T, T) {} + constexpr explicit VecBase(T) : x(V), y(V) {} + /* Implemented correctly for GCC to compile the constexpr float2 arrays. */ + constexpr explicit VecBase(T x_, T y_) : x(x_), y(y_) {} }; template struct VecBase : VecOp { + private: + /* Weird non-zero value to avoid error about division by zero in constexpr. */ + static constexpr T V = T(0.123f); + + public: union { struct { T x, y, z; @@ -255,14 +266,19 @@ template struct VecBase : VecOp { VecBase() = default; template explicit VecBase(VecOp) {} - explicit VecBase(T) {} + constexpr explicit VecBase(T) : x(V), y(V), z(V) {} /* Implemented correctly for GCC to compile the constexpr gl_WorkGroupSize. */ constexpr explicit VecBase(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {} - explicit VecBase(VecOp, T) {} - explicit VecBase(T, VecOp) {} + constexpr explicit VecBase(VecOp, T) : x(V), y(V), z(V) {} + constexpr explicit VecBase(T, VecOp) : x(V), y(V), z(V) {} }; template struct VecBase : VecOp { + private: + /* Weird non-zero value to avoid error about division by zero in constexpr. */ + static constexpr T V = T(0.123f); + + public: union { struct { T x, y, z, w; @@ -276,14 +292,15 @@ template struct VecBase : VecOp { VecBase() = default; template explicit VecBase(VecOp) {} - explicit VecBase(T) {} - explicit VecBase(T, T, T, T) {} - explicit VecBase(VecOp, T, T) {} - explicit VecBase(T, VecOp, T) {} - explicit VecBase(T, T, VecOp) {} - explicit VecBase(VecOp, VecOp) {} - explicit VecBase(VecOp, T) {} - explicit VecBase(T, VecOp) {} + constexpr explicit VecBase(T) : x(V), y(V), z(V), w(V) {} + /* Implemented correctly for GCC to compile the constexpr. */ + constexpr explicit VecBase(T x_, T y_, T z_, T w_) : x(x_), y(y_), z(z_), w(w_) {} + constexpr explicit VecBase(VecOp, T, T) : x(V), y(V), z(V), w(V) {} + constexpr explicit VecBase(T, VecOp, T) : x(V), y(V), z(V), w(V) {} + constexpr explicit VecBase(T, T, VecOp) : x(V), y(V), z(V), w(V) {} + constexpr explicit VecBase(VecOp, VecOp) : x(V), y(V), z(V), w(V) {} + constexpr explicit VecBase(VecOp, T) : x(V), y(V), z(V), w(V) {} + constexpr explicit VecBase(T, VecOp) : x(V), y(V), z(V), w(V) {} }; /* Boolean vectors do not have operators and are not convertible from other types. */ @@ -692,12 +709,12 @@ int findMSB(uint) RET; /* NOTE: Declared inside a namespace and exposed behind macros to prevent * errors on VS2019 due to `corecrt_math` conflicting functions. */ namespace glsl { -template T abs(T) RET; +template constexpr T abs(T) RET; /* TODO(fclem): These should be restricted to floats. */ -template T ceil(T) RET; -template T exp(T) RET; -template T exp2(T) RET; -template T floor(T) RET; +template constexpr T ceil(T) RET; +template constexpr T exp(T) RET; +template constexpr T exp2(T) RET; +template constexpr T floor(T) RET; template T fma(T, T, T) RET; float fma(float, float, float) RET; template T frexp(T, T) RET; @@ -705,25 +722,25 @@ bool isinf(float) RET; template VecBase isinf(VecOp) RET; bool isnan(float) RET; template VecBase isnan(VecOp) RET; -template T log(T) RET; -template T log2(T) RET; +template constexpr T log(T) RET; +template constexpr T log2(T) RET; template T modf(T, T); -template T pow(T, U) RET; -template T round(T) RET; -template T sqrt(T) RET; -template T trunc(T) RET; +template constexpr T pow(T, U) RET; +template constexpr T round(T) RET; +template constexpr T sqrt(T) RET; +template constexpr T trunc(T) RET; template T ldexp(T, U) RET; -template T acos(T) RET; +template constexpr T acos(T) RET; template T acosh(T) RET; -template T asin(T) RET; +template constexpr T asin(T) RET; template T asinh(T) RET; template T atan(T, T) RET; template T atan(T) RET; template T atanh(T) RET; -template T cos(T) RET; +template constexpr T cos(T) RET; template T cosh(T) RET; -template T sin(T) RET; +template constexpr T sin(T) RET; template T sinh(T) RET; template T tan(T) RET; template T tanh(T) RET; @@ -759,19 +776,19 @@ template T tanh(T) RET; #define tan glsl::tan #define tanh glsl::tanh -template T max(T, T) RET; -template T min(T, T) RET; -template T sign(T) RET; -template T clamp(T, U, U) RET; -template T clamp(T, float, float) RET; -template T max(T, U) RET; -template T min(T, U) RET; +template constexpr T max(T, T) RET; +template constexpr T min(T, T) RET; +template constexpr T sign(T) RET; +template constexpr T clamp(T, U, U) RET; +template constexpr T clamp(T, float, float) RET; +template constexpr T max(T, U) RET; +template constexpr T min(T, U) RET; /* TODO(fclem): These should be restricted to floats. */ template T fract(T) RET; -template T inversesqrt(T) RET; -float mod(float, float) RET; -template VecBase mod(VecOp, float) RET; -template VecBase mod(VecOp, VecOp) RET; +template constexpr T inversesqrt(T) RET; +constexpr float mod(float, float) RET; +template VecBase constexpr mod(VecOp, float) RET; +template VecBase constexpr mod(VecOp, VecOp) RET; template T smoothstep(T, T, T) RET; float step(float, float) RET; template VecBase step(VecOp, VecOp) RET; @@ -779,8 +796,8 @@ template VecBase step(float, VecOp) RET; float smoothstep(float, float, float) RET; template VecBase smoothstep(float, float, VecOp) RET; -template T degrees(T) RET; -template T radians(T) RET; +template constexpr T degrees(T) RET; +template constexpr T radians(T) RET; /* Declared explicitly to avoid type errors. */ float mix(float, float, float) RET; diff --git a/source/blender/gpu/shaders/gpu_shader_2D_node_socket_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_node_socket_frag.glsl index 25e35d64afe..2b0dae60900 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_node_socket_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_node_socket_frag.glsl @@ -53,10 +53,10 @@ void main() float alpha_threshold = 0.0f; float dot_threshold = -1.0f; - const float circle_radius = 0.5f; + constexpr float circle_radius = 0.5f; const float square_radius = 0.5f / sqrt(2.0f / M_PI) * M_SQRT1_2; const float diamond_radius = 0.5f / sqrt(2.0f / M_PI) * M_SQRT1_2; - const float corner_rounding = 0.0f; + constexpr float corner_rounding = 0.0f; switch (finalShape) { default: diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl index acd723c7c25..94a940d7986 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl @@ -21,8 +21,8 @@ VERTEX_SHADER_CREATE_INFO(gpu_shader_2D_nodelink) void main() { - const float start_gradient_threshold = 0.35f; - const float end_gradient_threshold = 0.65f; + constexpr float start_gradient_threshold = 0.35f; + constexpr float end_gradient_threshold = 0.65f; #ifdef USE_INSTANCE # define colStart (colid_doarrow[0] < 3u ? start_color : node_link_data.colors[colid_doarrow[0]]) diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl index ff2b762c72b..614d671cff2 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl @@ -45,7 +45,7 @@ float3 compute_masks(float2 uv) * has been scaled (i.e: Node editor)... */ float line_width = (lineWidth > 0.0f) ? max(fwidth(uv.y), lineWidth) : 0.0f; - const float aa_radius = 0.5f; + constexpr float aa_radius = 0.5f; float3 masks; masks.x = smoothstep(-aa_radius, aa_radius, sdf); masks.y = smoothstep(-aa_radius, aa_radius, sdf - line_width); diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl index d6cc187b7b8..63d25bd57f1 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl @@ -32,7 +32,7 @@ VERTEX_SHADER_CREATE_INFO(gpu_shader_2D_widget_base) float2 do_widget() { /* Offset to avoid losing pixels (mimics conservative rasterization). */ - const float2 ofs = float2(0.5f, -0.5f); + constexpr float2 ofs = float2(0.5f, -0.5f); lineWidth = abs(rect.x - recti.x); float2 emboss_ofs = float2(0.0f, -lineWidth); diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl index a4dfbe187c4..c335b503c36 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl @@ -34,44 +34,44 @@ void main() { /* NOTE(Metal): Declaring constant array in function scope to avoid increasing local shader * memory pressure. */ - const float2 cornervec[36] = float2_array(float2(0.0f, 1.0f), - float2(0.02f, 0.805f), - float2(0.067f, 0.617f), - float2(0.169f, 0.45f), - float2(0.293f, 0.293f), - float2(0.45f, 0.169f), - float2(0.617f, 0.076f), - float2(0.805f, 0.02f), - float2(1.0f, 0.0f), - float2(-1.0f, 0.0f), - float2(-0.805f, 0.02f), - float2(-0.617f, 0.067f), - float2(-0.45f, 0.169f), - float2(-0.293f, 0.293f), - float2(-0.169f, 0.45f), - float2(-0.076f, 0.617f), - float2(-0.02f, 0.805f), - float2(0.0f, 1.0f), - float2(0.0f, -1.0f), - float2(-0.02f, -0.805f), - float2(-0.067f, -0.617f), - float2(-0.169f, -0.45f), - float2(-0.293f, -0.293f), - float2(-0.45f, -0.169f), - float2(-0.617f, -0.076f), - float2(-0.805f, -0.02f), - float2(-1.0f, 0.0f), - float2(1.0f, 0.0f), - float2(0.805f, -0.02f), - float2(0.617f, -0.067f), - float2(0.45f, -0.169f), - float2(0.293f, -0.293f), - float2(0.169f, -0.45f), - float2(0.076f, -0.617f), - float2(0.02f, -0.805f), - float2(0.0f, -1.0f)); + constexpr float2 cornervec[36] = float2_array(float2(0.0f, 1.0f), + float2(0.02f, 0.805f), + float2(0.067f, 0.617f), + float2(0.169f, 0.45f), + float2(0.293f, 0.293f), + float2(0.45f, 0.169f), + float2(0.617f, 0.076f), + float2(0.805f, 0.02f), + float2(1.0f, 0.0f), + float2(-1.0f, 0.0f), + float2(-0.805f, 0.02f), + float2(-0.617f, 0.067f), + float2(-0.45f, 0.169f), + float2(-0.293f, 0.293f), + float2(-0.169f, 0.45f), + float2(-0.076f, 0.617f), + float2(-0.02f, 0.805f), + float2(0.0f, 1.0f), + float2(0.0f, -1.0f), + float2(-0.02f, -0.805f), + float2(-0.067f, -0.617f), + float2(-0.169f, -0.45f), + float2(-0.293f, -0.293f), + float2(-0.45f, -0.169f), + float2(-0.617f, -0.076f), + float2(-0.805f, -0.02f), + float2(-1.0f, 0.0f), + float2(1.0f, 0.0f), + float2(0.805f, -0.02f), + float2(0.617f, -0.067f), + float2(0.45f, -0.169f), + float2(0.293f, -0.293f), + float2(0.169f, -0.45f), + float2(0.076f, -0.617f), + float2(0.02f, -0.805f), + float2(0.0f, -1.0f)); - const float2 center_offset[4] = float2_array( + constexpr float2 center_offset[4] = float2_array( float2(1.0f, 1.0f), float2(-1.0f, 1.0f), float2(-1.0f, -1.0f), float2(1.0f, -1.0f)); uint cflag = vflag & CNR_FLAG_RANGE; diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl index 5449ff0d23c..fef6be5fa9d 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl @@ -179,13 +179,13 @@ void main() /* Line list primitive. */ uint input_primitive_vertex_count = uint(gpu_vert_stride_count_offset.x); /* Triangle list primitive (emulating triangle strip). */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 2u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 2u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl index 4ce6418564a..6d389bc9f26 100644 --- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_frag.glsl @@ -8,7 +8,7 @@ FRAGMENT_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke) void main() { - const float2 center = float2(0, 0.5f); + constexpr float2 center = float2(0, 0.5f); float4 tColor = interp.mColor; /* if alpha < 0, then encap */ if (tColor.a < 0) { diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl index b1feb1baae4..e3d4cc0a236 100644 --- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_vert.glsl @@ -116,7 +116,7 @@ void strip_EmitVertex(const uint strip_index, void geometry_main(VertOut geom_in[4], uint out_vertex_id, uint out_primitive_id) { - const float MiterLimit = 0.75f; + constexpr float MiterLimit = 0.75f; float4 P0 = geom_in[0].gpu_position; float4 P1 = geom_in[1].gpu_position; @@ -313,15 +313,16 @@ void geometry_main(VertOut geom_in[4], uint out_vertex_id, uint out_primitive_id void main() { /* Line Strip Adjacency primitive. */ - const uint input_primitive_vertex_count = 1u; /* We read 4 but advance 1. Assume no restart. */ + constexpr uint input_primitive_vertex_count = + 1u; /* We read 4 but advance 1. Assume no restart. */ /* Triangle list primitive (emulating triangle strip). */ - const uint ouput_primitive_vertex_count = 3u; - const uint ouput_primitive_count = 12u; - const uint ouput_invocation_count = 1u; - const uint output_vertex_count_per_invocation = ouput_primitive_count * - ouput_primitive_vertex_count; - const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * - ouput_invocation_count; + constexpr uint ouput_primitive_vertex_count = 3u; + constexpr uint ouput_primitive_count = 12u; + constexpr uint ouput_invocation_count = 1u; + constexpr uint output_vertex_count_per_invocation = ouput_primitive_count * + ouput_primitive_vertex_count; + constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation * + ouput_invocation_count; uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive; uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count; diff --git a/source/blender/gpu/shaders/gpu_shader_icon_frag.glsl b/source/blender/gpu/shaders/gpu_shader_icon_frag.glsl index a98afaebe5a..accdc45e3ad 100644 --- a/source/blender/gpu/shaders/gpu_shader_icon_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_icon_frag.glsl @@ -21,13 +21,13 @@ void main() #ifdef DO_CORNER_MASKING /* Top-left rounded corner parameters. */ - const float circle_radius_outer = 0.1f; - const float circle_radius_inner = 0.075f; + constexpr float circle_radius_outer = 0.1f; + constexpr float circle_radius_inner = 0.075f; /** * Add a bit transparency to see a bit of the icon, without * getting on the way of readability. */ - const float mask_transparency = 0.25f; + constexpr float mask_transparency = 0.25f; float2 circle_center = float2(circle_radius_outer - text_width, 0.5f); diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl index 6972a5257bf..3c28ff083c0 100644 --- a/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl @@ -10,7 +10,7 @@ void main() { float2 centered = gl_PointCoord - float2(0.5f); float dist_squared = dot(centered, centered); - const float rad_squared = 0.25f; + constexpr float rad_squared = 0.25f; /* Round point with jagged edges. */ if (dist_squared > rad_squared) { diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl index 76f544138ad..562dff4d9c5 100644 --- a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl @@ -135,7 +135,7 @@ void main() /* 3x3 blur */ /* clang-format off */ - const float weights3x3[16] = float_array( + constexpr float weights3x3[16] = float_array( 1.0f, 2.0f, 1.0f, 0.0f, 2.0f, 4.0f, 2.0f, 0.0f, 1.0f, 2.0f, 1.0f, 0.0f, @@ -171,7 +171,7 @@ void main() /* 5x5 blur */ /* clang-format off */ - const float weights5x5[36] = float_array( + constexpr float weights5x5[36] = float_array( 1.0f, 2.0f, 2.0f, 2.0f, 1.0f, 0.0f, 2.0f, 5.0f, 6.0f, 5.0f, 2.0f, 0.0f, 2.0f, 6.0f, 8.0f, 6.0f, 2.0f, 0.0f, diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl index b097a989c2d..8d0fd5ed5ff 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl @@ -166,7 +166,7 @@ void node_tex_sky_nishita(float3 co, } else { /* evaluate longitudinal position on the map */ - const float tau = 6.28318530717958647692f; + constexpr float tau = 6.28318530717958647692f; float x = (spherical.y + M_PI + sun_rotation) / tau; if (x > 1.0f) { x -= 1.0f; diff --git a/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl index d5c16751be7..7dd043384ae 100644 --- a/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl +++ b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl @@ -26,6 +26,10 @@ RESHAPE(float3x3, mat3x3, mat3x4) #undef RESHAPE +/* constexpr is equivalent to const in GLSL + special chaining rules. + * See "GLSL Specification section 4.3.3. Constant Expressions". */ +#define constexpr const + /* Boolean in GLSL are 32bit in interface structs. */ #define bool32_t bool #define bool2 bvec2 @@ -157,5 +161,5 @@ RESHAPE(float3x3, mat3x3, mat3x4) #define _enum_dummy /* Needed to please `glslang`. */ #define _enum_type(name) uint -#define _enum_decl(name) const uint +#define _enum_decl(name) constexpr uint #define _enum_end _enum_dummy; diff --git a/source/blender/gpu/tests/shaders/gpu_math_test.glsl b/source/blender/gpu/tests/shaders/gpu_math_test.glsl index eec7e07d092..d511cc0952a 100644 --- a/source/blender/gpu/tests/shaders/gpu_math_test.glsl +++ b/source/blender/gpu/tests/shaders/gpu_math_test.glsl @@ -113,7 +113,7 @@ void main() TEST(math_matrix, MatrixModify) { - const float epsilon = 1e-6f; + constexpr float epsilon = 1e-6f; float4x4 result, expect; float4x4 m1 = float4x4( float4(0, 3, 0, 0), float4(2, 0, 0, 0), float4(0, 0, 2, 0), float4(0, 0, 0, 1)); @@ -241,7 +241,7 @@ void main() float4(0.000000f, 0.000000f, 0.000000f, 1.000000f))); float4x4 m1 = mat4x4_identity(); float4x4 result; - const float epsilon = 2e-5f; + constexpr float epsilon = 2e-5f; result = interpolate_fast(m1, m2, 0.0f); EXPECT_NEAR(result, m1, epsilon); result = interpolate_fast(m1, m2, 1.0f); @@ -260,7 +260,7 @@ void main() TEST(math_matrix, MatrixTransform) { float3 expect, result; - const float3 p = float3(1, 2, 3); + constexpr float3 p = float3(1, 2, 3); float4x4 m4 = from_loc_rot(float3(10, 0, 0), EulerXYZ(M_PI_2, M_PI_2, M_PI_2)); float3x3 m3 = from_rotation(EulerXYZ(M_PI_2, M_PI_2, M_PI_2)); float4x4 pers4 = projection_perspective(-0.1f, 0.1f, -0.1f, 0.1f, -0.1f, -1.0f);