• 3 Posts
  • 16 Comments
Joined 1 year ago
cake
Cake day: June 18th, 2023

help-circle
  • This worked perfectly - thank you!!

    For anyone else looking here later, the final shader code (confirmed working Godot 4.2) is:

    shader_type canvas_item;
    
    uniform sampler2D screen_texture : hint_screen_texture;
    uniform vec4 water_color : source_color;
    uniform sampler2D wave_noise : repeat_enable;
    
    void fragment() {
    	vec2 water_wave = (texture(wave_noise, UV * TIME * 0.02).rg - 0.5) * 0.02;
    	vec2 uv = vec2(SCREEN_UV.x , SCREEN_UV.y - UV.y) + water_wave;
    	vec4 color = texture(screen_texture, uv);
    	float mix_value = 1.0 - UV.y;
    
    	float avg_color = (color.r + color.g + color.b) / 3.0;
    	avg_color = pow(avg_color, 1.4);
    	mix_value += avg_color;
    
    	mix_value = clamp(mix_value, 0.0, 0.7);
    	COLOR = vec4(mix(water_color, color, mix_value).rgb, texture(TEXTURE, UV).a);
    }
    

    Credits to Single-mindedRyan for creating this shader in the first place.











  • Managed to fix it by using await get_tree().process_frame instead. It seems that idle_frame appears to no longer exist in Godot 4.1?

    So my full code for triggering the screenshot function is:

    func _on_SaveReport_pressed():
    	await get_tree().process_frame
    	$"%SaveReport".visible = false
    	$"%BackMainMenu".visible = false
    	await get_tree().process_frame
    	
    	take_screenshot()
    
    	$"%SaveReport".visible = true
    	$"%BackMainMenu".visible = true
    

    For some reason, I have to await before I turn the interface elements off, and after I’ve turned them off. It now works a treat for my app. Thank you for your assistance!


  • await get_tree().idle_frame

    Thank you for this! I just tried it out but unfortunately Godot throws an error on await get_tree().idle_frame : Invalid get index 'idle_frame' (on base: 'SceneTree').

    Could it be because I’m running in application mode, which only refreshes the screen if there’s an update?

    As an alternative, I’ve put the code to turn things off into its own function:

    func turn_off():
    	$"%SaveReport".visible = false
    	$"%BackMainMenu".visible = false
    

    I’ve then tried an await turn_off()

    The code runs, but doesn’t do anything and the screenshot still gets saved with the buttons visible.

    I’m trying both await functions just before the take_screenshot() function like so:

    	await turn_off()
    	await get_tree().idle_frame
    	
    	take_screenshot()
    

    Am I missing something very obvious here? Any help would be much appreciated!