Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Nov 9, 2024
1 parent f735fd6 commit 9222656
Show file tree
Hide file tree
Showing 32 changed files with 398 additions and 496 deletions.
12 changes: 3 additions & 9 deletions armorlab/sources/nodes/inpaint_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,10 @@ function inpaint_node_get_as_image(self: inpaint_node_t, from: i32): image_t {
function inpaint_node_get_cached_image(self: inpaint_node_t): image_t {
app_notify_on_next_frame(function (self: inpaint_node_t) {
let source: image_t = logic_node_input_get_as_image(self.base.inputs[0]);
if (base_pipe_copy == null) {
base_make_pipe();
}
if (const_data_screen_aligned_vb == null) {
const_data_create_screen_aligned_data();
}
g4_begin(inpaint_node_image);
g4_set_pipeline(base_pipe_inpaint_preview);
g4_set_tex(base_tex0_inpaint_preview, source);
g4_set_tex(base_texa_inpaint_preview, inpaint_node_mask);
g4_set_pipeline(pipes_inpaint_preview);
g4_set_tex(pipes_tex0_inpaint_preview, source);
g4_set_tex(pipes_texa_inpaint_preview, inpaint_node_mask);
g4_set_vertex_buffer(const_data_screen_aligned_vb);
g4_set_index_buffer(const_data_screen_aligned_ib);
g4_draw();
Expand Down
23 changes: 10 additions & 13 deletions armorlab/sources/render_path_paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,23 @@ function render_path_paint_commands_cursor() {
function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f32 = 1.0, tint_g: f32 = 1.0, tint_b: f32 = 1.0) {
let plane: mesh_object_t = scene_get_child(".Plane").ext;
let geom: mesh_data_t = plane.data;
if (base_pipe_cursor == null) {
base_make_cursor_pipe();
}

render_path_set_target("");
g4_set_pipeline(base_pipe_cursor);
g4_set_pipeline(pipes_cursor);
let img: image_t = resource_get("cursor.k");
g4_set_tex(base_cursor_tex, img);
g4_set_tex(pipes_cursor_tex, img);
let gbuffer0: render_target_t = map_get(render_path_render_targets, "gbuffer0");
g4_set_tex_depth(base_cursor_gbufferd, gbuffer0._image);
g4_set_float2(base_cursor_mouse, mx, my);
g4_set_float2(base_cursor_tex_step, 1 / gbuffer0._image.width, 1 / gbuffer0._image.height);
g4_set_float(base_cursor_radius, radius);
g4_set_tex_depth(pipes_cursor_gbufferd, gbuffer0._image);
g4_set_float2(pipes_cursor_mouse, mx, my);
g4_set_float2(pipes_cursor_tex_step, 1 / gbuffer0._image.width, 1 / gbuffer0._image.height);
g4_set_float(pipes_cursor_radius, radius);
let right: vec4_t = vec4_norm(camera_object_right_world(scene_camera));
g4_set_float3(base_cursor_camera_right, right.x, right.y, right.z);
g4_set_float3(base_cursor_tint, tint_r, tint_g, tint_b);
g4_set_mat(base_cursor_vp, scene_camera.vp);
g4_set_float3(pipes_cursor_camera_right, right.x, right.y, right.z);
g4_set_float3(pipes_cursor_tint, tint_r, tint_g, tint_b);
g4_set_mat(pipes_cursor_vp, scene_camera.vp);
let help_mat: mat4_t = mat4_identity();
help_mat = mat4_inv(scene_camera.vp);
g4_set_mat(base_cursor_inv_vp, help_mat);
g4_set_mat(pipes_cursor_inv_vp, help_mat);
///if (arm_metal || arm_vulkan)
let vs: vertex_element_t[] = [
{
Expand Down
18 changes: 4 additions & 14 deletions armorlab/sources/ui_nodes_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,28 @@ function ui_nodes_ext_draw_buttons(ew: f32, start_y: f32) {
g2_end();
}

if (base_pipe_copy == null) {
base_make_pipe();
}
if (base_pipe_copy_a == null) {
base_make_pipe_copy_a();
}
if (const_data_screen_aligned_vb == null) {
const_data_create_screen_aligned_data();
}

let texpaint_pack: render_target_t = map_get(render_path_render_targets, "texpaint_pack");

if (texocc != null) {
g2_begin(texpaint_pack._image);
g2_set_pipeline(base_pipe_copy_r);
g2_set_pipeline(pipes_copy_r);
g2_draw_scaled_image(texocc, 0, 0, config_get_texture_res_x(), config_get_texture_res_y());
g2_set_pipeline(null);
g2_end();
}

if (texrough != null) {
g2_begin(texpaint_pack._image);
g2_set_pipeline(base_pipe_copy_g);
g2_set_pipeline(pipes_copy_g);
g2_draw_scaled_image(texrough, 0, 0, config_get_texture_res_x(), config_get_texture_res_y());
g2_set_pipeline(null);
g2_end();
}

if (texheight != null) {
g4_begin(texpaint_pack._image);
g4_set_pipeline(base_pipe_copy_a);
g4_set_tex(base_pipe_copy_a_tex, texheight);
g4_set_pipeline(pipes_copy_a);
g4_set_tex(pipes_copy_a_tex, texheight);
g4_set_vertex_buffer(const_data_screen_aligned_vb);
g4_set_index_buffer(const_data_screen_aligned_ib);
g4_draw();
Expand Down
71 changes: 33 additions & 38 deletions armorpaint/sources/base_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ function base_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[]
}
base_make_temp_img();
base_make_export_img();
if (base_pipe_merge == null) {
base_make_pipe();
}
if (const_data_screen_aligned_vb == null) {
const_data_create_screen_aligned_data();
}

let empty_rt: render_target_t = map_get(render_path_render_targets, "empty_white");
let empty: image_t = empty_rt._image;

Expand Down Expand Up @@ -70,14 +65,14 @@ function base_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[]
if (l1masks != null) {
if (l1masks.length > 1) {
base_make_temp_mask_img();
g2_begin(base_temp_mask_image);
g2_begin(pipes_temp_mask_image);
g2_clear(0x00000000);
g2_end();
let l1: slot_layer_t = { texpaint: base_temp_mask_image };
let l1: slot_layer_t = { texpaint: pipes_temp_mask_image };
for (let i: i32 = 0; i < l1masks.length; ++i) {
base_merge_layer(l1, l1masks[i]);
}
mask = base_temp_mask_image;
mask = pipes_temp_mask_image;
}
else {
mask = l1masks[0].texpaint;
Expand All @@ -86,19 +81,19 @@ function base_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[]

if (l1.paint_base) {
g2_begin(base_temp_image); // Copy to temp
g2_set_pipeline(base_pipe_copy);
g2_set_pipeline(pipes_copy);
g2_draw_image(base_expa, 0, 0);
g2_set_pipeline(null);
g2_end();

g4_begin(base_expa);
g4_set_pipeline(base_pipe_merge);
g4_set_tex(base_tex0, l1.texpaint);
g4_set_tex(base_tex1, empty);
g4_set_tex(base_texmask, mask);
g4_set_tex(base_texa, base_temp_image);
g4_set_float(base_opac, slot_layer_get_opacity(l1));
g4_set_int(base_blending, layers.length > 1 ? l1.blending : 0);
g4_set_pipeline(pipes_merge);
g4_set_tex(pipes_tex0, l1.texpaint);
g4_set_tex(pipes_tex1, empty);
g4_set_tex(pipes_texmask, mask);
g4_set_tex(pipes_texa, base_temp_image);
g4_set_float(pipes_opac, slot_layer_get_opacity(l1));
g4_set_int(pipes_blending, layers.length > 1 ? l1.blending : 0);
g4_set_vertex_buffer(const_data_screen_aligned_vb);
g4_set_index_buffer(const_data_screen_aligned_ib);
g4_draw();
Expand All @@ -107,19 +102,19 @@ function base_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[]

if (l1.paint_nor) {
g2_begin(base_temp_image);
g2_set_pipeline(base_pipe_copy);
g2_set_pipeline(pipes_copy);
g2_draw_image(base_expb, 0, 0);
g2_set_pipeline(null);
g2_end();

g4_begin(base_expb);
g4_set_pipeline(base_pipe_merge);
g4_set_tex(base_tex0, l1.texpaint);
g4_set_tex(base_tex1, l1.texpaint_nor);
g4_set_tex(base_texmask, mask);
g4_set_tex(base_texa, base_temp_image);
g4_set_float(base_opac, slot_layer_get_opacity(l1));
g4_set_int(base_blending, l1.paint_nor_blend ? -2 : -1);
g4_set_pipeline(pipes_merge);
g4_set_tex(pipes_tex0, l1.texpaint);
g4_set_tex(pipes_tex1, l1.texpaint_nor);
g4_set_tex(pipes_texmask, mask);
g4_set_tex(pipes_texa, base_temp_image);
g4_set_float(pipes_opac, slot_layer_get_opacity(l1));
g4_set_int(pipes_blending, l1.paint_nor_blend ? -2 : -1);
g4_set_vertex_buffer(const_data_screen_aligned_vb);
g4_set_index_buffer(const_data_screen_aligned_ib);
g4_draw();
Expand All @@ -128,23 +123,23 @@ function base_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[]

if (l1.paint_occ || l1.paint_rough || l1.paint_met || l1.paint_height) {
g2_begin(base_temp_image);
g2_set_pipeline(base_pipe_copy);
g2_set_pipeline(pipes_copy);
g2_draw_image(base_expc, 0, 0);
g2_set_pipeline(null);
g2_end();

if (l1.paint_occ && l1.paint_rough && l1.paint_met && l1.paint_height) {
base_commands_merge_pack(base_pipe_merge, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask, l1.paint_height_blend ? -3 : -1);
base_commands_merge_pack(pipes_merge, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask, l1.paint_height_blend ? -3 : -1);
}
else {
if (l1.paint_occ) {
base_commands_merge_pack(base_pipe_merge_r, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask);
base_commands_merge_pack(pipes_merge_r, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask);
}
if (l1.paint_rough) {
base_commands_merge_pack(base_pipe_merge_g, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask);
base_commands_merge_pack(pipes_merge_g, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask);
}
if (l1.paint_met) {
base_commands_merge_pack(base_pipe_merge_b, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask);
base_commands_merge_pack(pipes_merge_b, base_expc, l1.texpaint, l1.texpaint_pack, slot_layer_get_opacity(l1), mask);
}
}
}
Expand All @@ -170,19 +165,19 @@ function base_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[]
if (height_to_normal && make_material_height_used) {

g2_begin(base_temp_image);
g2_set_pipeline(base_pipe_copy);
g2_set_pipeline(pipes_copy);
g2_draw_image(l0.texpaint_nor, 0, 0);
g2_set_pipeline(null);
g2_end();

g4_begin(l0.texpaint_nor);
g4_set_pipeline(base_pipe_merge);
g4_set_tex(base_tex0, base_temp_image);
g4_set_tex(base_tex1, l0.texpaint_pack);
g4_set_tex(base_texmask, empty);
g4_set_tex(base_texa, empty);
g4_set_float(base_opac, 1.0);
g4_set_int(base_blending, -4);
g4_set_pipeline(pipes_merge);
g4_set_tex(pipes_tex0, base_temp_image);
g4_set_tex(pipes_tex1, l0.texpaint_pack);
g4_set_tex(pipes_texmask, empty);
g4_set_tex(pipes_texa, empty);
g4_set_float(pipes_opac, 1.0);
g4_set_int(pipes_blending, -4);
g4_set_vertex_buffer(const_data_screen_aligned_vb);
g4_set_index_buffer(const_data_screen_aligned_ib);
g4_draw();
Expand Down
2 changes: 1 addition & 1 deletion armorpaint/sources/make_brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function make_brush_run(vert: node_shader_t, frag: node_shader_t) {
}

let fill_layer: bool = context_raw.layer.fill_layer != null;
let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
let decal: bool = context_is_decal();
if (decal && !fill_layer) {
node_shader_write(frag, "if (decal_mask.z > 0.0) {");
}
Expand Down
2 changes: 1 addition & 1 deletion armorpaint/sources/make_paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad

let face_fill: bool = context_raw.tool == workspace_tool_t.FILL && context_raw.fill_type_handle.position == fill_type_t.FACE;
let uv_island_fill: bool = context_raw.tool == workspace_tool_t.FILL && context_raw.fill_type_handle.position == fill_type_t.UV_ISLAND;
let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
let decal: bool = context_is_decal();

///if (arm_direct3d11 || arm_direct3d12 || arm_metal || arm_vulkan)
node_shader_write(vert, "vec2 tpos = vec2(tex.x * 2.0 - 1.0, (1.0 - tex.y) * 2.0 - 1.0);");
Expand Down
2 changes: 1 addition & 1 deletion armorpaint/sources/make_texcoord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function make_texcoord_run(vert: node_shader_t, frag: node_shader_t) {

let fill_layer: bool = context_raw.layer.fill_layer != null;
let uv_type: uv_type_t = fill_layer ? context_raw.layer.uv_type : context_raw.brush_paint;
let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
let decal: bool = context_is_decal();
let angle: f32 = context_raw.brush_angle + context_raw.brush_nodes_angle;
let uv_angle: f32 = fill_layer ? context_raw.layer.angle : angle;

Expand Down
3 changes: 1 addition & 2 deletions armorpaint/sources/nodes/input_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function input_node_update(self: float_node_t) {
context_raw.view_index = mouse_view_x() > base_w() / 2 ? 1 : 0;
}

let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
let decal_mask: bool = decal && operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN);
let decal_mask: bool = context_is_decal_mask_paint();

let lazy_paint: bool = context_raw.brush_lazy_radius > 0 &&
(operator_shortcut(map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN) ||
Expand Down
31 changes: 13 additions & 18 deletions armorpaint/sources/render_path_paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ function render_path_paint_commands_live_brush() {

function render_path_paint_commands_cursor() {
if (!config_raw.brush_3d) return;
let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
let decal_mask: bool = decal && operator_shortcut(map_get(config_keymap, "decal_mask"), shortcut_type_t.DOWN);
let decal_mask: bool = context_is_decal_mask();
let tool: workspace_tool_t = context_raw.tool;
if (tool != workspace_tool_t.BRUSH &&
tool != workspace_tool_t.ERASER &&
Expand Down Expand Up @@ -475,29 +474,25 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3
let plane: mesh_object_t = scene_get_child(".Plane").ext;
let geom: mesh_data_t = plane.data;

if (base_pipe_cursor == null) {
base_make_cursor_pipe();
}

render_path_set_target("");
g4_set_pipeline(base_pipe_cursor);
let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
let decal_mask: bool = decal && operator_shortcut(map_get(config_keymap, "decal_mask"), shortcut_type_t.DOWN);
g4_set_pipeline(pipes_cursor);
let decal: bool = context_is_decal();
let decal_mask: bool = context_is_decal_mask();
let img: image_t = (decal && !decal_mask) ? context_raw.decal_image : resource_get("cursor.k");
g4_set_tex(base_cursor_tex, img);
g4_set_tex(pipes_cursor_tex, img);
let rt: render_target_t = map_get(render_path_render_targets, "gbuffer0");
let gbuffer0: image_t = rt._image;
g4_set_tex_depth(base_cursor_gbufferd, gbuffer0);
g4_set_float2(base_cursor_mouse, mx, my);
g4_set_float2(base_cursor_tex_step, 1 / gbuffer0.width, 1 / gbuffer0.height);
g4_set_float(base_cursor_radius, radius);
g4_set_tex_depth(pipes_cursor_gbufferd, gbuffer0);
g4_set_float2(pipes_cursor_mouse, mx, my);
g4_set_float2(pipes_cursor_tex_step, 1 / gbuffer0.width, 1 / gbuffer0.height);
g4_set_float(pipes_cursor_radius, radius);
let right: vec4_t = vec4_norm(camera_object_right_world(scene_camera));
g4_set_float3(base_cursor_camera_right, right.x, right.y, right.z);
g4_set_float3(base_cursor_tint, tint_r, tint_g, tint_b);
g4_set_mat(base_cursor_vp, scene_camera.vp);
g4_set_float3(pipes_cursor_camera_right, right.x, right.y, right.z);
g4_set_float3(pipes_cursor_tint, tint_r, tint_g, tint_b);
g4_set_mat(pipes_cursor_vp, scene_camera.vp);
let help_mat: mat4_t = mat4_identity();
help_mat = mat4_inv(scene_camera.vp);
g4_set_mat(base_cursor_inv_vp, help_mat);
g4_set_mat(pipes_cursor_inv_vp, help_mat);
///if (arm_metal || arm_vulkan)
let vs: vertex_element_t[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion armorsculpt/sources/import_mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function import_mesh_pack_to_texture(mesh: raw_mesh_t) {
let imgmesh: image_t = image_from_bytes(b, config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.RGBA128);
let texpaint: image_t = project_layers[0].texpaint;
g2_begin(texpaint);
g2_set_pipeline(base_pipe_copy128);
g2_set_pipeline(pipes_copy128);
g2_draw_scaled_image(imgmesh, 0, 0, config_get_texture_res_x(), config_get_texture_res_y());
g2_set_pipeline(null);
g2_end();
Expand Down
3 changes: 1 addition & 2 deletions armorsculpt/sources/make_sculpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function make_sculpt_run(data: material_t, matcon: material_context_t): node_sha
let frag: node_shader_t = node_shader_context_make_frag(con_paint);
frag.ins = vert.outs;

let face_fill: bool = context_raw.tool == workspace_tool_t.FILL && context_raw.fill_type_handle.position == fill_type_t.FACE;
let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
let decal: bool = context_is_decal();

node_shader_add_out(vert, "vec2 tex_coord");
node_shader_write(vert, "const vec2 madd = vec2(0.5, 0.5);");
Expand Down
3 changes: 0 additions & 3 deletions armorsculpt/sources/render_path_sculpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ function render_path_sculpt_commands() {
mesh_object_get_contexts(project_paint_objects[0], "paint", mats, material_contexts, shader_contexts);

let cc_context: shader_context_t = shader_contexts[0];
if (const_data_screen_aligned_vb == null) {
const_data_create_screen_aligned_data();
}
g4_set_pipeline(cc_context._.pipe_state);
uniforms_set_context_consts(cc_context,_render_path_bind_params);
uniforms_set_obj_consts(cc_context, project_paint_objects[0].base);
Expand Down
Loading

0 comments on commit 9222656

Please sign in to comment.