Skip to content

Commit e927a27

Browse files
committed
Clamp brush and layer opacity to [0,1] range
Prevent invalid opacity values from propagating through the UI and rendering pipeline by clamping after slider input and in uniform reads. Affected: brush output node, layer mask opacity, swatch opacity, picked color opacity, brush opacity uniform.
1 parent 2964f0e commit e927a27

5 files changed

Lines changed: 6 additions & 2 deletions

File tree

paint/sources/nodes_brush/brush_output_node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void brush_output_node_parse_inputs() {
5656
}
5757
}
5858
else {
59-
g_context->brush_nodes_opacity = opac->_f32;
59+
g_context->brush_nodes_opacity = math_max(0.0, math_min(1.0, opac->_f32));
6060
g_context->brush_mask_image = NULL;
6161
}
6262

paint/sources/ui/tab_layers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ void tab_layers_draw_layer_context_menu_draw() {
712712
ui_handle_t *layer_opac_handle = ui_nest(ui_handle(__ID__), l->id);
713713
layer_opac_handle->f = l->mask_opacity;
714714
ui_slider(layer_opac_handle, tr("Opacity"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
715+
layer_opac_handle->f = math_max(0.0, math_min(1.0, layer_opac_handle->f));
715716
if (layer_opac_handle->changed) {
716717
if (ui->input_started) {
717718
history_layer_opacity();

paint/sources/ui/tab_swatches.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void tab_swatches_draw_edit_menu() {
7676
ui_handle_t *hopacity = ui_handle(__ID__);
7777
hopacity->f = g_context->swatch->opacity;
7878
g_context->swatch->opacity = ui_slider(hopacity, "Opacity", 0, 1, true, 100.0, true, UI_ALIGN_RIGHT, true);
79+
g_context->swatch->opacity = math_max(0.0, math_min(1.0, g_context->swatch->opacity));
7980

8081
if (g_config->workflow == WORKFLOW_PBR) {
8182
ui_handle_t *hocclusion = ui_handle(__ID__);

paint/sources/ui/ui_header.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ void ui_header_draw_tool_properties() {
273273
ui_handle_t *hopac = ui_handle(__ID__);
274274
hopac->f = g_context->picked_color->opacity;
275275
g_context->picked_color->opacity = ui_slider(hopac, tr("Opacity"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
276+
g_context->picked_color->opacity = math_max(0.0, math_min(1.0, g_context->picked_color->opacity));
276277

277278
ui_handle_t *h_select_mat = ui_handle(__ID__);
278279
h_select_mat->b = g_context->picker_select_material;
@@ -369,6 +370,7 @@ void ui_header_draw_tool_properties() {
369370
ui_handle_t *brush_opacity_handle = ui_handle(__ID__);
370371
brush_opacity_handle->f = g_context->brush_opacity;
371372
g_context->brush_opacity = ui_slider(brush_opacity_handle, tr("Opacity"), 0.0, 1.0, true, 100.0, true, UI_ALIGN_RIGHT, true);
373+
g_context->brush_opacity = math_max(0.0, math_min(1.0, g_context->brush_opacity));
372374
if (ui->is_hovered) {
373375
any_map_t *vars = any_map_create();
374376
any_map_set(vars, "brush_opacity", any_map_get(config_keymap, "brush_opacity"));

paint/sources/uniforms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ f32 uniforms_ext_f32_link(object_t *object, material_data_t *mat, char *link) {
6060
if (g_config->pressure_opacity && pen_down("tip") && !slot_layer_is_path(g_context->layer)) {
6161
val *= pen_pressure * g_config->pressure_sensitivity;
6262
}
63-
return val;
63+
return math_max(0.0, math_min(1.0, val));
6464
}
6565
else if (string_equals(link, "_brush_hardness")) {
6666
bool decal_mask = context_is_decal_mask_paint();

0 commit comments

Comments
 (0)