Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Material Maker for Godot 4.4 #731

Merged
merged 18 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .github/workflows/dev-desktop-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ on:
default: "true"

env:
GODOT_VERSION: 4.3
GODOT_SUB: stable
GODOT_DOWNLOAD_DIR: https://github.com/godotengine/godot-builds/releases/download/4.3-stable
GODOT_VERSION: 4.4
GODOT_SUB: dev6
GODOT_DOWNLOAD_DIR: https://github.com/godotengine/godot-builds/releases/download/4.4-dev6
EXPORT_NAME: material_maker
MM_RELEASE: 1_4a1
MM_RELEASE: 1_4a2

jobs:
export_windows_linux:
Expand Down
1 change: 1 addition & 0 deletions addons/flexible_layout/flexible_dragger.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dgwcni3ebvc8s
1 change: 1 addition & 0 deletions addons/flexible_layout/flexible_layout.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://crspdrrii0nex
1 change: 1 addition & 0 deletions addons/flexible_layout/flexible_overlay.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bhwlc7y7qgb2v
1 change: 1 addition & 0 deletions addons/flexible_layout/flexible_tab.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://ywxnr7grll4s
2 changes: 1 addition & 1 deletion addons/flexible_layout/flexible_tab.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=3 uid="uid://e06xegp2tp3f"]

[ext_resource type="Script" path="res://addons/flexible_layout/flexible_tab.gd" id="1"]
[ext_resource type="Script" uid="uid://ywxnr7grll4s" path="res://addons/flexible_layout/flexible_tab.gd" id="1"]
[ext_resource type="Texture2D" uid="uid://xuy6dfh1rsne" path="res://addons/flexible_layout/undock.png" id="2_nx0qp"]

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_bok24"]
Expand Down
1 change: 1 addition & 0 deletions addons/flexible_layout/flexible_tabs.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dg1byost6nv7c
1 change: 1 addition & 0 deletions addons/flexible_layout/test.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://pwdjqjokbnju
6 changes: 4 additions & 2 deletions addons/material_maker/engine/dependencies.gd
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ func dependency_update(dependency_name : String, value = null, internal : bool =
var b : Buffer = buffers[dependency_name]
match b.status:
Buffer.Invalidated:
print_debug("Buffer %s (updating) should not be invalidated status" % dependency_name)
is_buffer_just_updated = true
#print_debug("Buffer %s (updating) should not be invalidated" % dependency_name)
#is_buffer_just_updated = true
update()
return
Buffer.UpdatingInvalidated:
#print_debug("Buffer %s (updating) reset to invalidated status" % dependency_name)
b.status = Buffer.Invalidated
Expand Down
1 change: 1 addition & 0 deletions addons/material_maker/engine/dependencies.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://crr3mu66a78bu
1 change: 1 addition & 0 deletions addons/material_maker/engine/io_types.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://coeb0q7f1dfo6
1 change: 1 addition & 0 deletions addons/material_maker/engine/loader.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://ddlcbf6dw2a6p
1 change: 1 addition & 0 deletions addons/material_maker/engine/logger.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://5f5raxatrnnl
86 changes: 81 additions & 5 deletions addons/material_maker/engine/multi_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ var max_viewport_size : int = 2048

var max_buffer_size = 0

var rendering_device : RenderingDevice
var rendering_device_user = null

var shader_error_handler


Expand All @@ -33,8 +30,8 @@ func _ready() -> void:
var renderer = preload("res://addons/material_maker/engine/renderer.tscn").instantiate()
add_child(renderer)
free_renderers.append(renderer)
rendering_device = RenderingServer.create_local_rendering_device()

initialize_rendering_thread()
# Global parameters

func get_global_parameters():
Expand Down Expand Up @@ -108,6 +105,85 @@ func release(renderer : Object) -> void:
free_renderers.append(renderer)
free_renderer.emit()


# rendering thread

const render_in_separate_thread : bool = true
var rendering_thread : Thread
var rendering_mutex : Mutex
var rendering_semaphore : Semaphore
var rendering_callable : Callable
var rendering_parameters : Array
var rendering_return_value
var rendering_thread_running : bool
var rendering_thread_working : bool = false
var rendering_device : RenderingDevice
var rendering_device_user = null

func thread_loop():
while true:
rendering_semaphore.wait()
rendering_mutex.lock()
var running : bool = rendering_thread_running
if not running:
rendering_mutex.unlock()
break
var rv = rendering_callable.callv(rendering_parameters)
rendering_return_value = rv
rendering_thread_running = false
rendering_mutex.unlock()

func thread_run(c : Callable, p : Array = [], stop_thread = false):
if render_in_separate_thread:
if rendering_thread == null:
return
while rendering_thread_working and is_inside_tree():
await get_tree().process_frame
rendering_thread_working = true
while not rendering_mutex.try_lock() and is_inside_tree():
await get_tree().process_frame
rendering_callable = c
rendering_parameters = p
rendering_thread_running = not stop_thread
rendering_mutex.unlock()
rendering_semaphore.post()
var running : bool = true
var rv
while running:
while not rendering_mutex.try_lock():
if is_inside_tree():
await get_tree().process_frame
running = rendering_thread_running
rv = rendering_return_value
rendering_mutex.unlock()
rendering_thread_working = false
return rv
else:
return await c.callv(p)

func create_rendering_device():
rendering_device = RenderingServer.create_local_rendering_device()

func destroy_rendering_device():
pass

func initialize_rendering_thread():
if render_in_separate_thread:
rendering_thread = Thread.new()
rendering_mutex = Mutex.new()
rendering_semaphore = Semaphore.new()
rendering_thread.start(self.thread_loop, 2)
thread_run(self.create_rendering_device)
else:
create_rendering_device()

func stop_rendering_thread():
if render_in_separate_thread:
await thread_run(destroy_rendering_device, [])
await thread_run(destroy_rendering_device, [], true)
rendering_thread.wait_to_finish()
rendering_thread = null

func request_rendering_device(user) -> RenderingDevice:
while ! renderers_enabled or rendering_device_user != null:
await self.free_rendering_device
Expand Down
1 change: 1 addition & 0 deletions addons/material_maker/engine/multi_renderer.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dqcja48n320s4
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_base.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://mcbr328cl01e
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_brush.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b7uvyymfdklls
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_buffer.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://brtutoy18rxq5
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_comment.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://x2lbtdvnuwdt
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_context.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://8dg7g6ubsn61
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_debug.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bcutdsiyw2tuf
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_export.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b2decri0hye1o
5 changes: 5 additions & 0 deletions addons/material_maker/engine/nodes/gen_graph.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ var transmits_seed : bool = true

var current_mesh : Mesh = null


signal graph_changed()
signal connections_changed(removed_connections, added_connections)
signal hierarchy_changed()


func _ready() -> void:
super._ready()

func emit_hierarchy_changed():
var top = self
while top.get_parent() != null and top.get_parent().get_script() == get_script():
Expand Down
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_graph.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://fcw2oyxbk8he
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_image.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://e6sktgaie00t
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_ios.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://04c37eowt30v
2 changes: 1 addition & 1 deletion addons/material_maker/engine/nodes/gen_iterate_buffer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var iteration_param_name : String
var used_named_parameters : Array = []


func _ready():
func _init():
#texture.flags = Texture2D.FLAG_REPEAT
shader_computes.append(MMShaderCompute.new())
shader_computes.append(MMShaderCompute.new())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bflrhcmq2h2oc
12 changes: 5 additions & 7 deletions addons/material_maker/engine/nodes/gen_material.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var preview_parameters : Dictionary = {}
var preview_textures = {}
var preview_texture_dependencies = {}

var external_previews : Array = []
var external_previews : Array[ShaderMaterial] = []
var export_output_def : Dictionary


Expand Down Expand Up @@ -169,16 +169,14 @@ func update_materials(material_list, sequential : bool = false) -> void:
update_material(m, sequential)

func update_material(m, sequential : bool = false) -> void:
if m is StandardMaterial3D:
pass
elif m is ShaderMaterial:
m.shader.code = preview_material.shader.code
if m is ShaderMaterial:
m.shader = preview_material.shader
for p in preview_parameters.keys():
m.set_shader_parameter(p, preview_parameters[p])

func update_external_previews() -> void:
for p in external_previews:
p.shader.code = preview_material.shader.code
p.shader = preview_material.shader
for t in preview_textures.keys():
p.set_shader_parameter(t, await preview_textures[t].texture.get_texture())
for t in preview_texture_dependencies.keys():
Expand Down Expand Up @@ -315,7 +313,7 @@ func process_shader(shader_text : String, custom_script : String = ""):
shader_code += "\n"
return { shader_code = shader_code, uniforms = rv.uniforms }

func set_3d_previews(previews : Array):
func set_3d_previews(previews : Array[ShaderMaterial]):
external_previews = previews
update_external_previews()

Expand Down
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_material.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://duduukbt175gd
2 changes: 2 additions & 0 deletions addons/material_maker/engine/nodes/gen_meshmap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const MESH_MAPS : Array[Dictionary] = [


func _ready() -> void:
super._ready()
if get_parent() is MMGenGraph:
set_current_mesh(get_parent().get_current_mesh())

Expand Down Expand Up @@ -114,6 +115,7 @@ func get_output_defs(_show_hidden : bool = false) -> Array:

func set_current_mesh(m : Mesh) -> void:
if current_mesh != m:
print("Setting mesh ", m)
current_mesh = m
update_map()

Expand Down
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_meshmap.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://do2fhmo51enhf
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_remote.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cn0tf0i8dvgl3
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_reroute.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cheligcykjoqk
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_sdf.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://csqqg3rre416e
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_shader.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bs00xpth2mgrv
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_switch.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://7o1v23p5rmyo
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_text.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://coj5y2ajhbf00
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_texture.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://d0j0hrry8p7yj
1 change: 1 addition & 0 deletions addons/material_maker/engine/nodes/gen_webcam.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bq5dlb02buma1
1 change: 1 addition & 0 deletions addons/material_maker/engine/paths.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dds8sv5t0d8qd
29 changes: 10 additions & 19 deletions addons/material_maker/engine/pipeline/compute_shader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func get_output_texture_declarations() -> String:
return texture_declarations

func set_shader(string : String, output_texture_type : int, replaces : Dictionary = {}) -> bool:
return await set_shader_ext(string, [{name="OUTPUT_TEXTURE", type=output_texture_type}], replaces)
return set_shader_ext(string, [{name="OUTPUT_TEXTURE", type=output_texture_type}], replaces)

func set_shader_ext(string : String, output_textures_desc : Array[Dictionary] = [], replaces : Dictionary = {}) -> bool:
output_textures = []
Expand All @@ -63,9 +63,8 @@ func set_shader_ext(string : String, output_textures_desc : Array[Dictionary] =
replaces["@DECLARATIONS"] += get_input_texture_declarations()+"\n"
replaces["@DECLARATIONS"] += get_output_parameters_declarations()+"\n"

var rd : RenderingDevice = await mm_renderer.request_rendering_device(self)
var rd : RenderingDevice = mm_renderer.rendering_device
shader = do_compile_shader(rd, { compute=string }, replaces)
mm_renderer.release_rendering_device(self)
return shader.is_valid()

func set_parameters_from_shadercode(shader_code : MMGenBase.ShaderCode, parameters_as_constants : bool = false):
Expand Down Expand Up @@ -172,17 +171,19 @@ func render_loop(rd : RenderingDevice, size : Vector2i, chunk_height : int, unif
func render(texture : MMTexture, size : Vector2i, output_parameters_values = null) -> bool:
return await render_ext([texture], size, output_parameters_values)

func render_ext(textures : Array[MMTexture], size : Vector2i, output_parameters_values = null) -> bool:
var rd : RenderingDevice = await mm_renderer.request_rendering_device(self)
func in_thread_render_ext(textures : Array[MMTexture], size : Vector2i, output_parameters_values = null) -> bool:
var rd : RenderingDevice = mm_renderer.rendering_device
var rids : RIDs = RIDs.new()
var start_time = Time.get_ticks_msec()
set_parameter("elapsed_time", 0.001*float(start_time), true)
var status = await render_2(rd, textures, output_parameters_values, size, rids)
var status = render_2(rd, textures, output_parameters_values, size, rids)
rids.free_rids(rd)
render_time = Time.get_ticks_msec() - start_time
mm_renderer.release_rendering_device(self)
return status

func render_ext(textures : Array[MMTexture], size : Vector2i, output_parameters_values = null) -> bool:
return await mm_renderer.thread_run(self.in_thread_render_ext, [textures, size, output_parameters_values])

func render_2(rd : RenderingDevice, textures : Array[MMTexture], output_parameters_values, size : Vector2i, rids : RIDs) -> bool:
if not shader.is_valid():
push_warning("Rendering with invalid shader")
Expand All @@ -201,7 +202,7 @@ func render_2(rd : RenderingDevice, textures : Array[MMTexture], output_paramete
#print("Creating texture for "+output_texture.name)
output_textures_rids.append(create_output_texture(rd, size, output_texture.type))

var status : bool = await do_render(rd, output_textures_rids, size, rids, output_parameters_values)
var status : bool = do_render(rd, output_textures_rids, size, rids, output_parameters_values)
if ! status:
push_warning("Rendering failed")
return false
Expand Down Expand Up @@ -278,17 +279,7 @@ func do_render(rd : RenderingDevice, output_textures_rids : Array[RID], size : V
var chunk_count : int = max(1, size.x*size.y/(max_viewport_size*max_viewport_size))
var chunk_height : int = max(1, size.y/chunk_count)

#await render_loop(rd, size, chunk_height, uniform_set_0, uniform_set_1, uniform_set_2, uniform_set_4)
if true:
# Use threads
var thread : Thread = Thread.new()
thread.start(render_loop.bind(rd, size, chunk_height, uniform_set_0, uniform_set_1, uniform_set_2, uniform_set_4))
while thread.is_alive():
await mm_renderer.get_tree().process_frame

thread.wait_to_finish()
else:
render_loop(rd, size, chunk_height, uniform_set_0, uniform_set_1, uniform_set_2, uniform_set_4)
render_loop(rd, size, chunk_height, uniform_set_0, uniform_set_1, uniform_set_2, uniform_set_4)

if has_output_parameters:
for pn in output_parameters.keys():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cljvoqip731pb
7 changes: 3 additions & 4 deletions addons/material_maker/engine/pipeline/pipeline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ func get_output_parameters_declarations() -> String:
return output_parameters_declarations

func create_texture(rd : RenderingDevice, texture_size : Vector2i, texture_type : int, usage_bits : int):
if texture_size.x == 0 or texture_size.y == 0:
return RID()
var fmt : RDTextureFormat = RDTextureFormat.new()
var texture_type_struct : Dictionary = TEXTURE_TYPE[texture_type]
fmt.width = texture_size.x
Expand All @@ -393,11 +395,8 @@ func create_texture(rd : RenderingDevice, texture_size : Vector2i, texture_type
fmt.texture_type = RenderingDevice.TEXTURE_TYPE_2D

var view : RDTextureView = RDTextureView.new()

var data = PackedByteArray()
data.resize(fmt.height*fmt.width*texture_type_struct.channels*texture_type_struct.bytes_per_channel)

return rd.texture_create(fmt, view, [data])
return rd.texture_create(fmt, view, [])

func create_output_texture(rd : RenderingDevice, texture_size : Vector2i, texture_type : int, is_framebuffer : bool = false) -> RID:
var usage_bits : int
Expand Down
1 change: 1 addition & 0 deletions addons/material_maker/engine/pipeline/pipeline.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cy12cyam077nq
Loading
Loading