mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Added an output and a parameter to support LOD in buffer
This commit is contained in:
parent
c7c1e61597
commit
c375c7e23e
@ -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
|
||||
|
@ -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)
|
||||
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)
|
Loading…
Reference in New Issue
Block a user