Accumulation Motion Blur

This is a visual effect that simulates the characteristic accumulation motion blur effect found in many PlayStation 2 games.

GDScript Only

## Creates a PlayStation 2-like accumulation motion blur effect.
##
## Add to _process(). The frame blending effect is applied to the area 
## within the boundaries of the texture_rect node.
## It is recommended to only set the alpha from 0 to less than 1.
func accumulation_motion_blur(texture_rect: TextureRect, alpha: float = 0.5, use_frame_post_draw: bool = true, viewport: Viewport = get_tree().root.get_viewport()) -> void:
    alpha = clamp(alpha, 0.0, 1.0) # Alpha values are 0 through 1

    var image: Image = Image.new()
    var texture: ImageTexture = ImageTexture.new()

    image = viewport.get_texture().get_data() # FORMAT_RGBAH
    image.flip_y() # Images start out upside-down. This turns it rightside-up.
    if use_frame_post_draw:
        yield(VisualServer, "frame_post_draw") # Changes when the effect is rendered. Changes the vibe.
    texture.create_from_image(image) # Turn Image to ImageTexture
    texture_rect.modulate.a = alpha # Changes the opacity of the frame blending
    texture_rect.texture = texture # Applies the image of the previous frame to the texture_rect

GDScript + Godot Shader Language

## Godot Accumulation Motion Blur
## By Lamb; MIT license
##
## Use in conjunction with the accumulation_motion_blur shader material.
func accumulation_motion_blur_shader(material: ShaderMaterial, viewport: Viewport = get_tree().root.get_viewport(), post_frame_draw: bool = true) -> void:
	var image: Image = Image.new()
	var texture: ImageTexture = ImageTexture.new()

	image = viewport.get_texture().get_data()
	texture.create_from_image(image)

	if post_frame_draw:
		yield(VisualServer, "frame_post_draw")

	material.set_shader_param("framebuffer", texture)
// Godot Accumulation Motion Blur
// Use in conjunction with the accumulation_motion_blur_shader() GDScript method
// to feed this shader the framebuffer texture.
// Apply this shader material to a ColorRect node to affect visuals underneath it.

shader_type canvas_item;


uniform float alpha: hint_range(0.0, 1.0, 0.001) = 0.5;
uniform float blur = 0.0;
uniform sampler2D framebuffer;


void fragment() {
	COLOR = texture(framebuffer, SCREEN_UV, blur);
	COLOR.a = alpha;
}
Shader code
// Godot Accumulation Motion Blur
// By Lamb; MIT license
//
// Use in conjunction with the accumulation_motion_blur_shader() GDScript method
// to feed this shader the framebuffer texture.
// Apply this shader material to a ColorRect node to affect visuals underneath it.

shader_type canvas_item;


uniform float alpha: hint_range(0.0, 1.0, 0.001) = 0.5;
uniform float blur = 0.0;
uniform sampler2D framebuffer;


void fragment() {
	COLOR = texture(framebuffer, SCREEN_UV, blur);
	COLOR.a = alpha;
}
Live Preview
Tags
blur, frame blend, frame blending, frameblending, motion blur, playstation 2, PS2
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments