Created
June 9, 2025 01:13
-
-
Save partybusiness/5e3c959d61a3911406c52d7643e782a9 to your computer and use it in GitHub Desktop.
An attempt to make a wrapper that could accept custom Canvas textures as a parameter and turn it into something a material can accept as a uniform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tool | |
extends PortableCompressedTexture2D | |
class_name CanvasWrapper | |
@export var source_texture:Texture2D: | |
get: | |
return source_texture | |
set(new_value): | |
if source_texture != new_value: | |
new_value.changed.connect(_on_source_texture_changed) | |
if source_texture != null && source_texture.changed.is_connected(_on_source_texture_changed): | |
source_texture.changed.disconnect(_on_source_texture_changed) | |
source_texture = new_value | |
request_update() | |
@export var update_now:bool: | |
get: | |
return update_now | |
set(new_value): | |
update_now = false | |
request_update() | |
var image:Image | |
func request_update() -> void: | |
if source_texture == null: | |
return | |
if image == null || image.get_size() != Vector2i(source_texture.get_size()): | |
image = Image.create(source_texture.get_width(), source_texture.get_height(), true, Image.FORMAT_R8) | |
image = source_texture.get_image() | |
#source_texture.draw() | |
#image.generate_mipmaps() # not using mipmaps because this is sampled over time not space | |
create_from_image(image, PortableCompressedTexture2D.COMPRESSION_MODE_LOSSLESS) | |
emit_changed() | |
func _on_source_texture_changed() -> void: | |
request_update() | |
func _init(): | |
request_update() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added the update_now boolean because sometimes it doesn't auto update from changes in the source texture. And it still has problems with AtlasTexture because not all the parameters are showing up in the interface? But it seems okay for noise textures.