material-maker/addons/procedural_material/nodes/image.gd
RodZill4 10ea905090 Many changes & fixes...
- shader updates are delayed by .25 seconds to avouid UI freeze
- fixed GraphNode initialization upon loading
- started obsoleting get_source_rgb and get_source_f functions
- updated colorize node to use gradient
- image node can now be loaded/saved
- removed iqnoise node
- rewrote perlin shader to support a seed parameter (seed is calculated from the node's position, so just move it to reseed)
- Added voronoi noise node
- updated code to use % formats instead of concatenating strings (should solve type problems in shaders)
- reworked the context menu (now has submenus)
- fixes in the gradient editor
2018-07-28 09:37:51 +02:00

51 lines
1.4 KiB
GDScript

tool
extends "res://addons/procedural_material/node_base.gd"
var file_path
func _ready():
set_slot(0, false, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1))
func set_texture(path):
file_path = path
var texture = ImageTexture.new()
texture.load(path)
$TextureButton.texture_normal = texture
get_parent().get_parent().generate_shader()
func get_textures():
var list = {}
list[name] = $TextureButton.texture_normal
return list
func _get_shader_code(uv):
var rv = { defs="", code="" }
if generated_variants.empty():
rv.defs = "uniform sampler2D "+name+"_tex;\n"
var variant_index = generated_variants.find(uv)
if variant_index == -1:
variant_index = generated_variants.size()
generated_variants.append(uv)
rv.code = "vec3 "+name+"_"+str(variant_index)+"_rgb = texture("+name+"_tex, "+uv+").rgb;\n"
rv.rgb = name+"_"+str(variant_index)+"_rgb"
return rv
func _on_TextureButton_pressed():
var dialog = EditorFileDialog.new()
add_child(dialog)
dialog.access = EditorFileDialog.ACCESS_FILESYSTEM
dialog.mode = EditorFileDialog.MODE_OPEN_FILE
dialog.add_filter("*.png;PNG image")
dialog.add_filter("*.jpg;JPG image")
dialog.connect("file_selected", self, "set_texture")
dialog.popup_centered()
func serialize():
var data = .serialize()
data.file_path = file_path
return data
func deserialize(data):
set_texture(data.file_path)
.deserialize(data)