extends ColorRect
-# Called every frame. 'delta' is the elapsed time since the previous frame.
+const squareLenghtMax := 50
+var blackBlock := false
+
+
func _process(_delta):
+ # edit noise level
material.set("shader_parameter/cell_amount", randf_range(100, 250))
+
+ # black squares from time to time
+ var current_time := Time.get_ticks_msec()
+ if (((current_time / 100) % 5 == 0) and (randf() < .1)): # put a square
+ blackBlock = true
+ material.set("shader_parameter/square_position", generate_square_points())
+ elif blackBlock: # remove the square
+ blackBlock = false
+ material.set("shader_parameter/square_position", Vector4())
+
+
+func generate_square_points() -> Vector4:
+ var res := get_viewport_rect().size
+
+ var x := randi_range(0, res.x)
+ var y := randi_range(x, x + squareLenghtMax)
+ var z := randi_range(0, res.y)
+ var w := randi_range(z, z + squareLenghtMax)
+
+ return Vector4(x, y, z, w)
uniform vec2 g_displacement = vec2(0.0, 0.0);
uniform vec2 b_displacement = vec2(-3.0, 0.0);
-vec2 modulo(vec2 divident, vec2 divisor){
+// Uniforms corruption squares
+uniform vec4 square_position = vec4(10., 200., 20., 50.); // x, y, z, w
+
+vec2 modulo(vec2 divident, vec2 divisor) {
vec2 positiveDivident = mod(divident, divisor) + divisor;
return mod(positiveDivident, divisor);
}
-vec2 random(vec2 value){
+vec2 random(vec2 value) {
value = vec2( dot(value, vec2(127.1,311.7) ),
dot(value, vec2(269.5,183.3) ) );
return -1.0 + 2.0 * fract(sin(value) * 43758.5453123);
}
void fragment() {
+
// Generate random noise
// float noise = (fract(sin(dot(UV, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) * 2.0;
float noise = seamless_noise(UV, period);
float g = clamp(texture(screen_texture, SCREEN_UV + vec2(SCREEN_PIXEL_SIZE*g_displacement), 0.0).g + noise * grain_amount * grain_size, 0.0, 1.0);
float b = clamp(texture(screen_texture, SCREEN_UV + vec2(SCREEN_PIXEL_SIZE*b_displacement), 0.0).b + noise * grain_amount * grain_size, 0.0, 1.0);
- COLOR = vec4(r, g, b, 1.0);
+ if (FRAGCOORD.x > square_position.x && FRAGCOORD.x < square_position.y && FRAGCOORD.y > square_position.z && FRAGCOORD.y < square_position.w) {
+ COLOR = vec4(0, 0, 0, 1.0);
+ } else {
+ COLOR = vec4(r, g, b, 1.0);
+ }
}
\ No newline at end of file