xiandie/asset/art/tool/point_light_gen.gd
2025-05-29 14:14:02 +08:00

23 lines
650 B
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Sprite2D
@export var size := 512
@export var export_path = ""
func _ready() -> void:
var image = Image.create_empty(size, size, false, Image.FORMAT_RGBA8)
# 放射性 point light圆心 alpha 通道为 1随半径增加逐渐接近 0
var r = size / 2.0
for x in range(size):
for y in range(size):
var rate = pow(pow(x - r, 2) + pow(y - r, 2), 0.5) / r
if rate > 1:
image.set_pixel(x, y, Color.TRANSPARENT)
else:
# var a = 1 - rate
var a = smoothstep(1.0, 0.0, rate)
image.set_pixel(x, y, Color(1, 1, 1, a))
if export_path:
image.save_png(export_path)
texture = ImageTexture.create_from_image(image)