paint: add viewport mask to picker tool
This commit is contained in:
@@ -35,13 +35,21 @@ void make_discard_uv_island(node_shader_t *kong) {
|
||||
node_shader_write_frag(kong, "if (sample_lod(texuvislandmap, sampler_linear, input.tex_coord_pick, 0.0).r == 0.0) { discard; }");
|
||||
}
|
||||
|
||||
void make_discard_material_id(node_shader_t *kong) {
|
||||
kong->frag_wvpposition = true;
|
||||
node_shader_write_frag(
|
||||
kong, "var picker_sample_tc: float2 = float2(input.wvpposition.x / input.wvpposition.w, input.wvpposition.y / input.wvpposition.w) * 0.5 + 0.5;");
|
||||
node_shader_write_frag(kong, "picker_sample_tc.y = 1.0 - picker_sample_tc.y;");
|
||||
void make_discard_material_id(node_shader_t *kong, char *tex_coord) {
|
||||
char *tc;
|
||||
if (tex_coord == NULL) {
|
||||
kong->frag_wvpposition = true;
|
||||
node_shader_write_frag(
|
||||
kong, "var picker_sample_tc: float2 = float2(input.wvpposition.x / input.wvpposition.w, input.wvpposition.y / input.wvpposition.w) * 0.5 + 0.5;");
|
||||
node_shader_write_frag(kong, "picker_sample_tc.y = 1.0 - picker_sample_tc.y;");
|
||||
tc = "picker_sample_tc";
|
||||
}
|
||||
else {
|
||||
tc = string("input.%s", tex_coord);
|
||||
}
|
||||
node_shader_add_texture(kong, "texpaint_nor_undo", "_texpaint_nor_undo");
|
||||
i32 matid = g_context->materialid_picked / 255.0;
|
||||
node_shader_write_frag(kong,
|
||||
string("if (%s != sample_lod(texpaint_nor_undo, sampler_linear, picker_sample_tc, 0.0).a) { discard; }", i32_to_string(matid)));
|
||||
node_shader_write_frag(kong, string("var picker_sample_a: float = sample_lod(texpaint_nor_undo, sampler_linear, %s, 0.0).a;", tc));
|
||||
// material_id * 3 + (0 - normal, 1 - emission, 2 - subsurface)
|
||||
node_shader_write_frag(kong, "var picker_sample_id: float = floor(floor(picker_sample_a * 255.0 + 0.5) / 3.0);");
|
||||
node_shader_write_frag(kong, string("if (abs(picker_sample_id - %s) > 0.5) { discard; }", f32_to_string_with_zeros((f32)g_context->materialid_picked)));
|
||||
}
|
||||
|
||||
@@ -179,6 +179,10 @@ node_shader_context_t *make_mesh_run(material_t *data, i32 layer_pass) {
|
||||
make_discard_color_id(kong, "tex_coord");
|
||||
}
|
||||
|
||||
if (g_context->picker_viewport_mask && g_context->tool != TOOL_TYPE_PICKER) {
|
||||
make_discard_material_id(kong, "tex_coord");
|
||||
}
|
||||
|
||||
if (g_context->tool == TOOL_TYPE_COLORID) {
|
||||
texture_count++;
|
||||
node_shader_add_texture(kong, "texcolorid", "_texcolorid");
|
||||
|
||||
@@ -295,8 +295,8 @@ node_shader_context_t *make_paint_run(material_t *data, material_context_t *matc
|
||||
}
|
||||
}
|
||||
|
||||
if (g_context->picker_mask == PICKER_MASK_MATERIAL) {
|
||||
make_discard_material_id(kong);
|
||||
if (g_context->picker_paint_mask) {
|
||||
make_discard_material_id(kong, NULL);
|
||||
}
|
||||
|
||||
make_texcoord_run(kong);
|
||||
@@ -484,7 +484,7 @@ node_shader_context_t *make_paint_run(material_t *data, material_context_t *matc
|
||||
node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, sampler_linear, sample_tc, 0.0);");
|
||||
|
||||
f32 matid = g_context->material->id / 255.0;
|
||||
if (g_context->picker_mask == PICKER_MASK_MATERIAL) {
|
||||
if (g_context->picker_paint_mask) {
|
||||
matid = g_context->materialid_picked / 255.0; // Keep existing material id in place when mask is set
|
||||
}
|
||||
char *matid_string = parser_material_vec1(matid * 3.0);
|
||||
|
||||
@@ -296,14 +296,16 @@ void render_path_paint_commands_paint(bool dilation) {
|
||||
g_context->picked_color->height = buffer_get_u8(c, i3) / 255.0;
|
||||
|
||||
// Pick material
|
||||
if (g_context->picker_select_material && g_context->color_picker_callback == NULL) {
|
||||
if (g_context->color_picker_callback == NULL) {
|
||||
// matid % 3 == 0 - normal, 1 - emission, 2 - subsurface
|
||||
i32 id = buffer_get_u8(b, 3);
|
||||
i32 matid = math_floor((id - (id % 3)) / 3.0);
|
||||
for (i32 i = 0; i < g_project->_->materials->length; ++i) {
|
||||
slot_material_t *m = g_project->_->materials->buffer[i];
|
||||
if (m->id == matid) {
|
||||
context_set_material(m);
|
||||
if (g_context->picker_select_material) {
|
||||
context_set_material(m);
|
||||
}
|
||||
g_context->materialid_picked = matid;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user