broken_seals/game/addons/mat_maker_gd/nodes/sdf3d/sdf3d.gd

59 lines
1.1 KiB
GDScript3
Raw Normal View History

tool
extends TextureRect
2021-10-03 10:10:56 +02:00
var SDF3D = preload("res://addons/mat_maker_gd/nodes/common/sdf3d.gd")
2021-10-01 23:32:11 +02:00
var image : Image
var tex : ImageTexture
export(Vector2) var bmin : Vector2 = Vector2(0.1, 0.1)
export(Vector2) var bmax : Vector2 = Vector2(1, 1)
export(bool) var refresh setget reff,reffg
func _ready():
if !Engine.editor_hint:
gen()
func gen() -> void:
if !image:
image = Image.new()
image.create(300, 300, false, Image.FORMAT_RGBA8)
if !tex:
tex = ImageTexture.new()
# var bmin : Vector2 = Vector2(0.1, 0.1)
# var bmax : Vector2 = Vector2(1, 1)
image.lock()
var w : float = image.get_width()
var h : float = image.get_width()
var pseed : float = randf() + randi()
for x in range(image.get_width()):
for y in range(image.get_height()):
var v : Vector2 = Vector2(x / w, y / h)
2021-10-03 10:10:56 +02:00
var col : Color = SDF3D.raymarch(v)
# var col : Color = SDF3D.raymarch2(v)
# var col : Color = SDF3D.raymarch3(v)
image.set_pixel(x, y, col)
image.unlock()
tex.create_from_image(image)
texture = tex
func reffg():
return false
func reff(bb):
if bb:
gen()