2019-08-25 23:27:07 +02:00
|
|
|
tool
|
|
|
|
extends MMGenBase
|
|
|
|
class_name MMGenTexture
|
|
|
|
|
|
|
|
"""
|
|
|
|
Base class for texture generators that provide a texture as output
|
|
|
|
"""
|
|
|
|
|
|
|
|
var texture : ImageTexture = ImageTexture.new()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_output_defs() -> Array:
|
2019-08-25 23:27:07 +02:00
|
|
|
return [ { rgba="" } ]
|
|
|
|
|
2019-10-29 22:12:14 +01:00
|
|
|
func _get_shader_code_lod(uv : String, output_index : int, context : MMGenContext, lod : float = 0.0) -> Dictionary:
|
2019-09-16 20:45:47 +02:00
|
|
|
var genname = "o"+str(get_instance_id())
|
2020-01-28 22:40:03 +01:00
|
|
|
var rv = { globals=[], defs="", code="", type="rgba" }
|
2019-09-16 20:45:47 +02:00
|
|
|
var texture_name = genname+"_tex"
|
2019-08-25 23:27:07 +02:00
|
|
|
var variant_index = context.get_variant(self, uv)
|
|
|
|
if variant_index == -1:
|
|
|
|
variant_index = context.get_variant(self, uv)
|
2019-10-29 22:12:14 +01:00
|
|
|
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 ]
|
2019-09-16 20:45:47 +02:00
|
|
|
rv.rgba = "%s_%d" % [ genname, variant_index ]
|
2019-08-25 23:27:07 +02:00
|
|
|
rv.textures = { texture_name:texture }
|
2019-10-18 08:35:54 +02:00
|
|
|
return rv
|
2019-10-29 22:12:14 +01:00
|
|
|
|
|
|
|
func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary:
|
2019-11-10 01:19:52 +01:00
|
|
|
return _get_shader_code_lod(uv, output_index, context)
|