Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hi agdg, this is the scene node's script that is setting stuff on a sprite2d:
- extends Node2D
- var bg_seed_timer = 0
- const bg_seed_change_duration = 2.0
- var bg_next_texture
- var bg
- func _ready():
- bg = get_node("background")
- bg_next_texture = bg.texture.duplicate()
- bg_next_texture.noise = FastNoiseLite.new()
- bg_next_texture.noise.seed = randi()
- bg.material.set_shader_parameter("next_texture",bg_next_texture)
- #bg.material.set_shader_parameter("starttime",fmod(Time.get_unix_time_from_system(),3600))
- return
- func _physics_process(delta):
- bg_seed_timer += delta
- if bg_seed_timer >= bg_seed_change_duration:
- bg_seed_timer -= bg_seed_change_duration
- bg.texture.noise.seed = bg_next_texture.noise.seed
- bg_next_texture.noise.seed = randi()
- #await bg_next_texture.changed
- #await bg.texture.changed
- bg.material.set_shader_parameter("timebump",bg_seed_timer/bg_seed_change_duration)
- return
- and this is the shader for that sprite (trimmed some stuff that's not running during tests):
- shader_type canvas_item;
- uniform float starttime;
- uniform sampler2D next_texture;
- uniform float timebump;
- void fragment() {
- vec2 uv = UV;
- COLOR = mix(texture(TEXTURE,uv),texture(next_texture,uv),timebump);
- }
- i am passing a float "timebump" on every frame instead of passing the initial time to the shader for testing purposes, i know it can be frowned at...
Advertisement
Add Comment
Please, Sign In to add comment