Skip to content

Commit

Permalink
Fixes for material export
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Dec 17, 2024
1 parent 55dc5b7 commit bb9daed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 10 additions & 0 deletions addons/material_maker/engine/nodes/gen_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,16 @@ func render(object: Object, output_index : int, size : int, preview : bool = fal
renderer = await renderer.render_shader(object, shader, size, output_type != "rgba")
return renderer

func render_output_to_texture(output_index : int, size : int) -> MMTexture:
var context : MMGenContext = MMGenContext.new()
var source : ShaderCode = get_shader_code("uv", output_index, context)
var shader_compute : MMShaderCompute = MMShaderCompute.new()
var shader_status : bool = await shader_compute.set_shader_from_shadercode(source, false)
var texture : MMTexture = MMTexture.new()
if shader_status:
var status = await shader_compute.render(texture, size)
return texture

func render_output(output_index : int, size : int) -> Image:
var context : MMGenContext = MMGenContext.new()
var source : ShaderCode = get_shader_code("uv", output_index, context)
Expand Down
19 changes: 7 additions & 12 deletions addons/material_maker/engine/nodes/gen_material.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func on_dep_update_value(buffer_name, parameter_name, value) -> bool:
preview_parameters[parameter_name] = value
for p in external_previews:
if value is MMTexture:
p.set_shader_parameter(parameter_name, await value.get_texture())
var texture = await value.get_texture()
p.set_shader_parameter(parameter_name, texture)
preview_texture_dependencies[parameter_name] = texture
else:
p.set_shader_parameter(parameter_name, value)
if preview_texture_dependencies.has(parameter_name):
preview_texture_dependencies[parameter_name] = value
else:
var texture_name : String = buffer_name.right(-(buffer_name_prefix.length()+1))
preview_textures[texture_name].shader_compute.set_parameter(parameter_name, value)
Expand Down Expand Up @@ -291,7 +291,7 @@ func process_shader(shader_text : String, custom_script : String = ""):
mm_deps.create_buffer(buffer_name, self)
shader_code += l+"\n"
var definitions : String = get_template_text("glsl_defs.tmpl")+"\n"
definitions += rv.uniforms_as_strings()
definitions += rv.uniforms_as_strings("uniform", true)
for d in rv.globals:
definitions += "// #globals: %s\n" % d.source
definitions += d.code+"\n"
Expand Down Expand Up @@ -691,13 +691,8 @@ func export_material(prefix : String, profile : String, size : int = 0) -> void:
saved_files += 1
progress_dialog.set_progress(float(saved_files)/float(total_files))
continue
var result = await render(self, output_index, size)
var is_greyscale : bool = false
var output = get_preprocessed_output_def(output_index)
if output != null:
is_greyscale = output.has("type") and output.type == "f"
result.save_to_file(file_name, is_greyscale)
result.release(self)
var result : MMTexture = await render_output_to_texture(output_index, size)
await result.save_to_file(file_name)
saved_files += 1
progress_dialog.set_progress(float(saved_files)/float(total_files))
"template":
Expand All @@ -716,7 +711,7 @@ func export_material(prefix : String, profile : String, size : int = 0) -> void:
for t in preview_texture_dependencies.keys():
var file_name = subst_string(f.file_name, export_context)
file_name = file_name.replace("$(buffer_index)", str(index))
preview_texture_dependencies[t].get_data().save_png(file_name)
preview_texture_dependencies[t].get_image().save_png(file_name)
index += 1
saved_files += 1
progress_dialog.set_progress(float(saved_files)/float(total_files))
Expand Down

0 comments on commit bb9daed

Please sign in to comment.