Godot Version
4.6.2
Question
I have a TextureRect with this code that has it display regions from an AtlasTexture
extends TextureRect
@export var atlas_texture: Texture2D
@export var x_index:int = 0
@export var y_index:int = 0
@export var icon_size:int = 50
var atlas: AtlasTexture
func _ready():
atlas = AtlasTexture.new()
atlas.atlas = atlas_texture
texture = atlas
update_region()
func _on_button_pressed() → void:
x_index += 1
update_region()
func update_region():
var x = x_index * icon_size
var y = y_index * icon_size
atlas.region = Rect2(x, y, icon_size, icon_size)
and I need to have the displayed region converted into some format that I can use as the mask parameter for this shader, such as Texture2D. Some other way of slicing up the atlas would also work. The shader takes atlastextures, but it uses the whole atlas even with parameters set, and thst’s not usable for me.
shader_type canvas_item;
uniform sampler2D mask;
void fragment( )
{
vec4 mask_color = texture(mask, UV).rgba;
vec4 sprite_color = texture(TEXTURE, UV).rgba;
if (mask_color.a == 0.0)
{
sprite_color.a = 0.0;
}
COLOR = sprite_color;
}