Skip to content

Commit

Permalink
Fixes for painting
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Dec 11, 2024
1 parent ea852b1 commit 3d752d9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions addons/material_maker/engine/pipeline/rendering_pipeline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions addons/material_maker/engine/shader_material.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions material_maker/panels/paint/paint.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions material_maker/tools/painter/painter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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])
Expand All @@ -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())
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 3d752d9

Please sign in to comment.