Godot Version
4.5
Question
Hello. I have the following script . But I have absolutely no idea how to write a shader. Please suggest resources that would help me understand this.
extends MeshInstance3D
var img : Image # mask
var imageTexture : ImageTexture # Bese texture
var rect : Rect2i
var brush : Image
var pixels : int
@onready var brush_textur = preload(“res://brush_blood.png”)
func _create_image():
var mat = get_active_material(0)
var base_texture = mat.get_shader_parameter(“base_textur”)
img = base_texture.get_image() #copy base texture
pixels = img.get_width()
imageTexture = ImageTexture.create_from_image(img)
mat.set_shader_parameter("Mask_texture", imageTexture)
func _brush():
brush = brush_textur.get_image()
rect = Rect2i(Vector2i(0, 0), Vector2i(3, 3))
func _ready():
_brush()
_create_image()
func draw_on_sprite(coords: Vector2):
if img.is_compressed():
img.decompress()
if img.get_format() != Image.FORMAT_RGBA8:
img.convert(Image.FORMAT_RGBA8)
if brush.get_format() != Image.FORMAT_RGBA8:
brush.convert(Image.FORMAT_RGBA8)
var pixsel_coords = ((coords * pixels) - Vector2(1.5, 1.5)).round()
img.blend_rect(brush, rect, Vector2i(pixsel_coords.x, pixsel_coords.y))
imageTexture = ImageTexture.create_from_image(img)
var mat = get_active_material(0)
if mat:
mat.set_shader_parameter("Mask_texture", imageTexture)
print("обновлена")
else:
print("не найден")