godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.13k stars 19.94k forks source link

Motion blur shader #16301

Closed MirceaKitsune closed 4 years ago

MirceaKitsune commented 6 years ago

I noticed that despite offering support for a variety of common post-processing shaders (bloom, depth-of-field, etc) Godot 3.0 doesn't have builtin support for motion blur yet. I believe this to be an important effect for photorealism, and would like to suggest it as a camera or environment option if possible.

For clarification: My suggestion doesn't refer to the conventional method of simulating motion blur, which relies on fading previous frames across the screen (also known as "ghosting"). The modern approach includes directional blurring of textures on surfaces based on the velocity of the camera, which offers a much more immersive and realistic effect. DirectX based engines have had this ability for over a decade, with the Need For Speed series (starting with NFS - Carbon, released in 2006) offering a good example... as far as open-source and OpenGL are concerned, this shader has been implemented into the Ogre based racing sim Stuntrally which may offer an useful example.

I briefly discussed this on IRC. I was told that a reason for the setback in supporting motion blur for Godot 3.0 is the OpenGL version, which is older than the one adding the necessary GLSL functions. Perhaps this can be implemented as more renderer backends are made available in the project settings, thus offered as an option to projects using OpenGL >= 3.2?

Chaosus commented 6 years ago

Godot have Vulkan support in roadmap, maybe after its implementation, all modern things including Motion blur will be implemented.

MirceaKitsune commented 6 years ago

Motion blur should definitely be possible in OpenGL too, at least version >= 3.2 to my understanding. Just saying it doesn't need to be a Vulkan specific feature, which I'd find a bit weird personally... if it otherwise has to come after implementing Vulkan for compatibility or priority reasons, that makes sense.

vnen commented 6 years ago

Just to clarify, Godot uses the OpenGL ES 3.0 standard, which is equivalent to OpenGL 3.3 on desktop platforms. Vulkan is in mind but don't expect it to come anytime soon.

MirceaKitsune commented 6 years ago

Does OpenGL ES 3.0 contain the GLSL functions needed for spatial motion blur? It sounds like it should, since like I said DirectX games got it working over a decade ago.

Zireael07 commented 6 years ago

I think the only function missing to implement a modern motion blur (https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch27.html) is the ability to get previous inverted projection matrix in addition to the current one.

Bauxitedev commented 6 years ago

Here's my attempt at a motion blur shader. Note that it only works when the camera moves. For per-object motion blur I think we need some kind of deferred rendering, so we can store linear velocity per pixel.

kaadmy commented 5 years ago

@Zireael07 Since OpenGL 3.1/GLSL 140 (I think?), matrices must be explicitly passed to the shader (OpenGL matrices are deprecated). Either way, GLSL has an inverse function to invert a matrix since GLSL 140.

Zireael07 commented 4 years ago

@Bauxitedev's motion blur shader is fairly good but it suffers from the same limitation as all other screen-reading shaders - they happen before alpha pass.

Somehow, though, built-in postprocess like DOF Near and Far Blur also work on alpha pass. Can we please get some velocity parameter to simulate motion blur using those?

Zireael07 commented 4 years ago

Found a workaround, but it would have to be used on all alpha things you want to be seen when motion blur is on: https://www.reddit.com/r/godot/comments/bxfyws/heres_a_dithered_opacity_aka_hashed_transparency/ so it's not that tenable for larger projects.

Calinou commented 4 years ago

I think @reduz plans to add a built-in per-object motion blur effect using motion vectors in 4.0 (or maybe 4.1).

Calinou commented 4 years ago

Superseded by https://github.com/godotengine/godot-proposals/issues/2933.