diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 77ddb9e..7341ef9 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -20,13 +20,16 @@ func get_type_name() -> String: return "Buffer" func get_parameter_defs() -> Array: - return [ { name="size", type="size", first=4, last=12, default=4 } ] + return [ + { name="size", type="size", first=4, last=12, default=4 }, + { name="lod", type="float", min=0, max=10.0, step=0.01, default=0 } + ] func get_input_defs() -> Array: return [ { name="in", type="rgba" } ] func get_output_defs() -> Array: - return [ { type="rgba" } ] + return [ { type="rgba" }, { type="rgba" } ] func source_changed(input_port_index : int): updated = false @@ -40,9 +43,9 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) - result = yield(result, "completed") result.copy_to_texture(texture) result.release() - texture.flags = 0 + texture.flags = Texture.FLAG_MIPMAPS updated = true - var rv = ._get_shader_code(uv, output_index, context) + var rv = ._get_shader_code_lod(uv, output_index, context, 0 if output_index == 0 else parameters.lod) while rv is GDScriptFunctionState: rv = yield(rv, "completed") return rv diff --git a/addons/material_maker/engine/gen_texture.gd b/addons/material_maker/engine/gen_texture.gd index 7daef7b..0803ad2 100644 --- a/addons/material_maker/engine/gen_texture.gd +++ b/addons/material_maker/engine/gen_texture.gd @@ -11,14 +11,20 @@ var texture : ImageTexture = ImageTexture.new() func get_output_defs() -> Array: return [ { rgba="" } ] -func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary: +func _get_shader_code_lod(uv : String, output_index : int, context : MMGenContext, lod : float = 0.0) -> Dictionary: var genname = "o"+str(get_instance_id()) var rv = { globals=[], defs="", code="" } var texture_name = genname+"_tex" var variant_index = context.get_variant(self, uv) if variant_index == -1: variant_index = context.get_variant(self, uv) - rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ genname, variant_index, texture_name, uv ] + if lod == 0.0: + rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ genname, variant_index, texture_name, uv ] + else: + rv.code = "vec4 %s_%d = textureLod(%s, %s, %.9f);\n" % [ genname, variant_index, texture_name, uv, lod ] rv.rgba = "%s_%d" % [ genname, variant_index ] rv.textures = { texture_name:texture } return rv + +func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary: + return _get_shader_code_lod(uv, output_index, context) \ No newline at end of file