Add brush alpha discard option

This commit is contained in:
luboslenco
2025-11-24 16:28:14 +01:00
parent a93b1e8a09
commit 7138bfe282
4 changed files with 27 additions and 17 deletions
+9
View File
@@ -473,6 +473,15 @@ function box_preferences_usage_tab() {
make_material_parse_paint_material();
}
ui.enabled = true;
let alpha_discard_handle: ui_handle_t = ui_handle(__ID__);
if (alpha_discard_handle.init) {
alpha_discard_handle.f = config_raw.brush_alpha_discard;
}
config_raw.brush_alpha_discard = ui_slider(alpha_discard_handle, tr("Alpha Discard"), 0.0, 1.0, true);
if (alpha_discard_handle.changed) {
make_material_parse_paint_material();
}
}
function box_preferences_pen_tab() {
+3
View File
@@ -94,6 +94,7 @@ function config_save() {
json_encode_bool("material_live", config_raw.material_live);
json_encode_bool("brush_depth_reject", config_raw.brush_depth_reject);
json_encode_bool("brush_angle_reject", config_raw.brush_angle_reject);
json_encode_f32("brush_alpha_discard", config_raw.brush_alpha_discard);
json_encode_i32("dilate_radius", config_raw.dilate_radius);
json_encode_string("blender", config_raw.blender);
json_encode_i32("scene_atlas_res", config_raw.scene_atlas_res);
@@ -197,6 +198,7 @@ function config_init() {
/// end
config_raw.brush_depth_reject = true;
config_raw.brush_angle_reject = true;
config_raw.brush_alpha_discard = 0.1;
config_raw.brush_live = false;
config_raw.show_asset_names = false;
config_raw.dilate_radius = 2;
@@ -470,6 +472,7 @@ type config_t = {
material_live?: bool;
brush_depth_reject?: bool;
brush_angle_reject?: bool;
brush_alpha_discard?: f32;
dilate_radius?: i32;
blender?: string;
scene_atlas_res?: i32;
+2 -4
View File
@@ -1,6 +1,4 @@
let make_mesh_preview_opacity_discard_decal: f32 = 0.05;
function make_mesh_preview_run(data: material_t, matcon: material_context_t): node_shader_context_t {
let context_id: string = "mesh";
let props: shader_context_t = {
@@ -58,8 +56,8 @@ function make_mesh_preview_run(data: material_t, matcon: material_context_t): no
}
}
if (decal) {
let opac: f32 = make_mesh_preview_opacity_discard_decal;
node_shader_write_frag(kong, "if (opacity < " + opac + ") { discard; }");
let opac: f32 = config_raw.brush_alpha_discard;
node_shader_write_frag(kong, "if (opacity <= float(" + opac + ")) { discard; }");
}
kong.frag_out = "float4[2]";
+2 -2
View File
@@ -336,7 +336,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
}
}
node_shader_write_frag(kong, "if (opacity == 0.0) { discard; }");
node_shader_write_frag(kong, "if (opacity <= float(" + config_raw.brush_alpha_discard + ")) { discard; }");
if (context_raw.tool == tool_type_t.PARTICLE) { // Particle mask
make_particle_mask(kong);
@@ -356,7 +356,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
node_shader_add_texture(kong, "paintmask");
node_shader_write_frag(kong, "var sample_mask: float = sample_lod(paintmask, sampler_linear, sample_tc, 0.0).r;");
node_shader_write_frag(kong, "str = max(str, sample_mask);");
// write(frag, "str = clamp(str + sample_mask, 0.0, 1.0);");
// node_shader_write_frag(kong, "str = clamp(str + sample_mask, 0.0, 1.0);");
node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo");
node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, sampler_linear, sample_tc, 0.0);");