I have recently been working on an OSL lens-flare shader for Cycles that is highly customisable and offers real time preview in the 3D viewport.
This shader has been ported from an original version written for the Renderman shading language by Larry Gritz and Tony Apodaca.
In the transfer to OSL a few new features, such as user definable lens-flare elements based on image textures, have been added.
The images above shows a hexagonal lensflare render. The setup is shown below.
The ‘Empty’ visible at the top right may be moved to change the position of the lens flare - the resulting image can be seen to update in the 3D viewport in real time.
The shader can be directly connected to the material output node of a plane parented to the front of a camera.
An example scene set up is available on BlendSwap here:
This blend file also contains a compositing ‘noodle’ that allows the lens-flare to automatically attenuate in intensity as it passes behind objects. The method for achieving this will be the subject of a future video and blog post (the noodle is available from the blog site too).
An example video is here:
Tutorials are available here:
- LensFlare Tutorial Part 1 of 4: Blender Real Time Lens Flare Shader Introduction
- LensFlare Tutorial Part 2 of 4: How To Set Up a LensFlare Shader in Blender
- LensFlare Tutorial Part 3 of 4:Automatically Masking the lens flare using the compositor
- Parts 4 is yet to be completed.
A note not presently in the video
Set the aspect ration of the rendered camera viewport to be approximately the same as for your final image to get the best preview match (this does not affect the final render however).
Blog notes are available here:
Features of the lens-flare shader include the following.
- Real time 3D viewport preview.
- Shader output may be connected directly to a Material’s “Surface” node connection (easy node setup).
- Lens-flare light source position co-ordinates may be set by the user.
- Highly customisable Bloom, Starburst, Rainbow, Disk, RIng,Blot and Hole elements.
- Number of spots, and the distribution of spot type, may be varied by the user.
- Optional user definable images for all lens-flare elements (new feature).
- Full control to mix between synthesised lens-flare and user image based lens flare.
- Lens flare elements may be drawn in GIMP - Photoshop - Downloaded - or other.
- Easy color tinting.
- Simple random color variation user settings.
- Automatic or user definable aspect ratio setting (e.g. for anamorphic lens-flare).
- An Extensive selection of Color outputs allow all of the lens flare elements to be further proceed in the node editor if desired.
I hope you enjoy this shader. I look forward to seeing user images - and hopefully some tutorials from people better at making them than me!