From 3d752d95ff5f1ab963f2416ac50e9fc1c6dd6032 Mon Sep 17 00:00:00 2001 From: Rodz Labs Date: Wed, 11 Dec 2024 21:02:14 +0100 Subject: [PATCH] Fixes for painting --- .../engine/pipeline/rendering_pipeline.gd | 6 +++--- .../material_maker/engine/shader_material.gd | 6 ++++-- material_maker/panels/paint/paint.gd | 4 ++-- material_maker/tools/painter/painter.gd | 21 ++++++++++--------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/addons/material_maker/engine/pipeline/rendering_pipeline.gd b/addons/material_maker/engine/pipeline/rendering_pipeline.gd index 5b26d647e..31e4369a1 100644 --- a/addons/material_maker/engine/pipeline/rendering_pipeline.gd +++ b/addons/material_maker/engine/pipeline/rendering_pipeline.gd @@ -5,7 +5,6 @@ class_name MMRenderingPipeline var shader : RID = RID() var index_count : int = 0 -var clearColors : PackedColorArray = PackedColorArray([Color.TRANSPARENT]) func create_framebuffer(rd : RenderingDevice, texture_rid : RID, depth_rid : RID = RID()) -> RID: @@ -72,8 +71,9 @@ func in_thread_render(size : Vector2i, texture_type : int, target_texture : MMTe # pre dev6 #var draw_list : int = rd.draw_list_begin(framebuffer, RenderingDevice.INITIAL_ACTION_CLEAR, RenderingDevice.FINAL_ACTION_READ, RenderingDevice.INITIAL_ACTION_CLEAR, RenderingDevice.FINAL_ACTION_READ, clearColors) # dev6 - #var draw_list : int = rd.draw_list_begin(framebuffer, RenderingDevice.INITIAL_ACTION_CLEAR, clearColors, true, 0.0, Rect2(), RenderingDevice.OPAQUE_PASS) - var draw_list : int = rd.draw_list_begin(framebuffer, RenderingDevice.INITIAL_ACTION_CLEAR, clearColors, 1.0, 0) + var clear_colors : PackedColorArray = PackedColorArray([Color(0, 0, 0, 0), Color(0, 0, 0, 0), Color(0, 0, 0, 0)]) + var draw_flags : int = RenderingDevice.DRAW_CLEAR_COLOR_ALL | RenderingDevice.DRAW_IGNORE_COLOR_ALL | RenderingDevice.DRAW_CLEAR_DEPTH | RenderingDevice.DRAW_IGNORE_DEPTH + var draw_list : int = rd.draw_list_begin(framebuffer, draw_flags, clear_colors, 1.0, 0) rd.draw_list_bind_render_pipeline(draw_list, pipeline) diff --git a/addons/material_maker/engine/shader_material.gd b/addons/material_maker/engine/shader_material.gd index 7a8e5a999..d92623105 100644 --- a/addons/material_maker/engine/shader_material.gd +++ b/addons/material_maker/engine/shader_material.gd @@ -12,8 +12,10 @@ func _init(m : ShaderMaterial = null): if material.shader == null: material.shader = Shader.new() -func set_shader(shader : String) -> bool: - material.shader.code = shader +func set_shader(shader_code : String) -> bool: + var shader : Shader = Shader.new() + shader.code = shader_code + material.shader = shader return true func get_parameters() -> Dictionary: diff --git a/material_maker/panels/paint/paint.gd b/material_maker/panels/paint/paint.gd index 6ae7885d2..d9fb32546 100644 --- a/material_maker/panels/paint/paint.gd +++ b/material_maker/panels/paint/paint.gd @@ -458,7 +458,7 @@ func handle_stroke_input(ev : InputEvent, painting_mode : int = PAINTING_MODE_VI painter_update_brush_params( { pattern_scale=brush_parameters.pattern_scale, pattern_angle=brush_parameters.pattern_angle } ) %BrushAngle.set_value(brush_parameters.pattern_angle*57.2957795131) elif current_tool == MODE_FREEHAND_DOTS or current_tool == MODE_FREEHAND_LINE: - paint(mouse_position, pressure, ev.tilt, painting_mode) + await paint(mouse_position, pressure, ev.tilt, painting_mode) last_tilt = ev.tilt painter_update_brush_params( { brush_size=brush_parameters.brush_size, brush_hardness=brush_parameters.brush_hardness } ) else: @@ -684,7 +684,7 @@ func paint(pos : Vector2, pressure : float = 1.0, tilt : Vector2 = Vector2(0, 0) return if current_tool == MODE_FREEHAND_DOTS: previous_position = null - do_paint(pos, pressure, tilt, painting_mode, end_of_stroke, layers.selected_layer.get_layer_type() == MMLayer.LAYER_MASK) + await do_paint(pos, pressure, tilt, painting_mode, end_of_stroke, layers.selected_layer.get_layer_type() == MMLayer.LAYER_MASK) last_painted_position = pos var next_paint_to = null diff --git a/material_maker/tools/painter/painter.gd b/material_maker/tools/painter/painter.gd index 56c435107..d19f813f1 100644 --- a/material_maker/tools/painter/painter.gd +++ b/material_maker/tools/painter/painter.gd @@ -163,8 +163,7 @@ func _ready(): initialized = true - update_view_textures() - + await update_view_textures() func update_view_textures(): if not initialized or mesh == null or viewport_size.x <= 0 or viewport_size.y <= 0: @@ -185,18 +184,18 @@ func update_view_textures(): t2v_texture.get_texture() func update_textures() -> void: - await MMMapGenerator.generate(mesh, "seams", texture_size, mesh_seams_tex) + mesh_seams_tex = await MMMapGenerator.get_map(mesh, "seams", texture_size) await mesh_seams_tex.get_texture() - update_view_textures() + await update_view_textures() # position texture - await MMMapGenerator.generate(mesh, "position", texture_size, mesh_position_tex) + mesh_position_tex = await MMMapGenerator.get_map(mesh, "position", texture_size) # normal texture - await MMMapGenerator.generate(mesh, "normal", texture_size, mesh_normal_tex) + mesh_normal_tex = await MMMapGenerator.get_map(mesh, "normal", texture_size) # tangent texture - await MMMapGenerator.generate(mesh, "tangent", texture_size, mesh_tangent_tex) + mesh_tangent_tex = await MMMapGenerator.get_map(mesh, "tangent", texture_size) mesh_aabb = mesh.get_aabb() func set_mesh(m : Mesh): @@ -329,6 +328,7 @@ func update_brush_params(shader_params : Dictionary) -> void: if brush_preview_material != null: if brush_params[p] is MMTexture: print("Setting texture") + brush_preview_material.set_shader_parameter(p, await brush_params[p].get_texture()) else: brush_preview_material.set_shader_parameter(p, brush_params[p]) paint_shader.set_parameter(p, shader_params[p]) @@ -353,6 +353,7 @@ func update_brush(update_shaders : bool = false): var brush_shader_file : String = "res://material_maker/tools/painter/shaders/brush.gdshader" var output_code : Dictionary = get_output_code(1) update_shader("painter_%d:brush" % get_instance_id(), brush_preview_material, brush_shader_file, { BRUSH_MODE="\""+get_brush_mode()+"\"", GENERATED_CODE = output_code.code }, output_code.uniforms) + print(brush_preview_material.shader.code) brush_preview_material.set_shader_parameter("rect_size", viewport_size) brush_preview_material.set_shader_parameter("view2tex_tex", await v2t_texture.get_texture()) brush_preview_material.set_shader_parameter("mesh_inv_uv_tex", await mesh_position_tex.get_texture()) @@ -584,9 +585,9 @@ func paint(shader_params : Dictionary, end_of_stroke : bool = false, emit_end_of paint_shader.set_parameter(n, shader_params[p], true) await paint_shader.render_ext(paint_textures, Vector2i(texture_size, texture_size)) for i in range(paint_textures.size()/3): - if OS.is_debug_build(): + if false and OS.is_debug_build(): paint_textures[i*3+1].get_texture() # Update stroke texture - paint_textures[i*3+2].get_texture() # Update painted texture + await paint_textures[i*3+2].get_texture() # Update painted texture emit_signal("painted") if end_of_stroke and emit_end_of_stroke: for i in range(paint_textures.size()/3): @@ -607,7 +608,7 @@ func paint(shader_params : Dictionary, end_of_stroke : bool = false, emit_end_of emit_signal("end_of_stroke", stroke_state) func fill(erase : bool, reset : bool = false, emit_end_of_stroke : bool = true) -> void: - paint({ brush_pos=Vector2(0, 0), brush_ppos=Vector2(0, 0), erase=erase, pressure=1.0, fill=true, reset=reset }, true, emit_end_of_stroke) + await paint({ brush_pos=Vector2(0, 0), brush_ppos=Vector2(0, 0), erase=erase, pressure=1.0, fill=true, reset=reset }, true, emit_end_of_stroke) func view_to_texture(position : Vector2) -> Vector2: if view_to_texture_image == null: