Godot 4 compositor lens effects đ¤ď¸
Lens flares and god rays implemented in a Godot 4 compositor effect.
Should work with Godot 4.4+. If not, please open an issue :)
If you use the shader and enjoy it, I would also appreciate a like on the asset store :)
Usage
- Download the
lens_effectsfolder into your projectsres://addons/folder - Create or select a
WorldEnvironmentnode - Under
Compositor, create a newCompositorand add 1 slot to the effects array - Select the empty slot and create a new
LensFlareEffect(it should show up for you even without activating the plugin) - Add the
world_environment.gdscript (also found in thelens_effectsfolder) to the WorldEnvironment node and assign thesunexported variable to point at yourDirectionalLight3D. Note: You don't have to have the script on the WorldEnvironment itself. I have added some notes inside the script what to modify, if you want to have the script running on some other node. - Reload the scene (via "Scene - Reload saved scene") to load the toolscript
- Tweak some values in the
LensFlareEffectand enjoy :)
I have tried to add some comments here and there and also hover descriptions for the parameters of the effect. Hopefully that helps.
Also check out the demo scene provided.
Note: If you make changes to the GLSL shader file, the easiest way to reload the changes that I found is to click "Scene - Reload Saved Scene".
Tips
- I have added hover descriptions to most settings of the effect, so feel free to use those
- To adjust how visible the rays are, the
weightsetting is useful - If the rays look too noisy for your liking, adjust the
samplesetting (you can try50, 100, 200, ...) - For advanced users: I have added some
#defines at the top of the shader. Those can yield a small performance boost, but are probably not that important. Stuff like the number of samples should be much more important.
Double precision
If you build your engine with double precision (like I do for my project) then you should uncomment the line
#define USE_DOUBLE_PRECISION
inside of addons/lens_effects/lens_flares.glsl
In case of any errors/ weird behaviour
I am not sure why, but I have had strange problems before which I fixed without changing anything in the shader. I am guessing it's some issue with Godot but not sure.
Try these steps:
- select the
lens_flares.glslfile - go to the "Import" tab
- click "Reimport"
- now try "Scene" - "Reload Saved Scene"
- (alternatively, try "Project" - "Reload Current Project")
I hope that fixes some issues you might be having :)
Thanks to
pink-arcana for their amazing example project for compositor effects here:
- https://github.com/pink-arcana/godot-distance-field-outlines
I have reused the
base_compositor_effect.gdfile with some slight modifications.
The following shadertoys:
- https://www.shadertoy.com/view/wlcyzj
- https://www.shadertoy.com/view/XsKGRW
Changelog for version 1.2
No changelog provided for this version.