Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1

    Lens-flare Shader for Cycles with real time preview.

    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.



    earthFlare1b.png
    The images above shows a hexagonal lensflare render. The setup is shown below.

    setup.png
    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.

    Shader Capture.png
    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:
    • http://www.blendswap.com/blends/view/68257
      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:



    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!

    :-)

    Dylan
    Last edited by iReboot; 13-Jun-13 at 09:48.



  2. #2
    Nice one. Good to see some non texture scripts.
    Charlie

    ArtRage for Art EnergyXT for Music Blender for 3D



  3. #3
    Member
    Join Date
    Aug 2010
    Location
    Adelaide, South Australia
    Posts
    2,667
    Nice, i will be testing this out on some projects later today



  4. #4
    Member
    Join Date
    Aug 2010
    Location
    Adelaide, South Australia
    Posts
    2,667
    Just had a quick play, seems like there isnt any motion blur? is there motionblur avaliable to materials? or is it just object motionblur?



  5. #5
    Member 3pointEdit's Avatar
    Join Date
    Sep 2005
    Location
    Brisbane, Australia
    Posts
    8,597
    I gather that the plane carrying the flare material isn't moving relative to the camera so wouldn't accrue any blur. I was going to suggest gathering motion vectors from a sphere surrounding the camera but on another layer but motion blur on a flare would be quite different as it occurs within the lens. The only part that should streak is the source lamp I think.
    Cheers, David ___________"awesome in space and other places".
    ________Follow me on twitter @3pointedit
    _____________ Check the Youtube Channel for tutorials. Or my Sketchbook



  6. #6
    Member
    Join Date
    Aug 2010
    Location
    Adelaide, South Australia
    Posts
    2,667
    Yeh i am guessing that only bits of geo would get motion blur.... all good i will try some other work arounds



  7. #7
    Member 3pointEdit's Avatar
    Join Date
    Sep 2005
    Location
    Brisbane, Australia
    Posts
    8,597
    Also, a real flare appears in frame before the source, because it enters a round lens and causes refraction and stuff. Then the source lands on the rectangular image field. Would it make sense to make the material plane circular? Could you attenuate the effect close to that circular edge? So that it doesn't just blink into being.
    Cheers, David ___________"awesome in space and other places".
    ________Follow me on twitter @3pointedit
    _____________ Check the Youtube Channel for tutorials. Or my Sketchbook



  8. #8
    Member DingTo's Avatar
    Join Date
    Mar 2008
    Location
    Southern Germany
    Posts
    1,626
    Originally Posted by Charlie View Post
    Nice one. Good to see some non texture scripts.
    I agree, great shader. Thanks for it.
    Blender developer (Cycles / User Interface)
    Blog -- Blender Podcast -- OpenShading -- BlenderDay -- Blender Network profile



  9. #9
    Member
    Join Date
    Aug 2010
    Location
    Adelaide, South Australia
    Posts
    2,667
    I belive that it does take that into account, i just loaded up the example and moved the empty driver offscreen, and loaded up rendered view and it still has the circular effects going on without the bloom visible.

    Originally Posted by 3pointEdit View Post
    Also, a real flare appears in frame before the source, because it enters a round lens and causes refraction and stuff. Then the source lands on the rectangular image field. Would it make sense to make the material plane circular? Could you attenuate the effect close to that circular edge? So that it doesn't just blink into being.



  10. #10
    Member 3pointEdit's Avatar
    Join Date
    Sep 2005
    Location
    Brisbane, Australia
    Posts
    8,597
    Funny thing I was just through some old photos and noticed a long exposure of the sun (vari nd almost opaque). It was a long exposure hand held, so it had a streak of light in the sun ghost image, half way down the flare sequence. So yeah flares do have motion blur but it's track must be quite short for 180 deg shutter of most recordings.
    Cheers, David ___________"awesome in space and other places".
    ________Follow me on twitter @3pointedit
    _____________ Check the Youtube Channel for tutorials. Or my Sketchbook



  11. #11
    Hi everyone -- thanks for the comments and feedback.

    I'm just off to work - so will respond to the motion blur idea tonight. I have not tried motion blur - but it sounds like an excellent idea - and there are probably several ways to achieve this.

    I've just re-loaded the .zip file to BlenderSwap if anyone was having trouble with the down load -- the .osl file was missing (although the shader script could still be loaded via the "Internal" setting in the script node).

    have not been able to confirm the BlendSwap upload however -- as the site has just stopped responding for me!

    Cheers

    Dylan



  12. #12
    Originally Posted by doublebishop View Post
    I belive that it does take that into account, i just loaded up the example and moved the empty driver offscreen, and loaded up rendered view and it still has the circular effects going on without the bloom visible.
    Hi guys,

    Yes -- the shader looks up the camera's field of view and fades out the lens-flare after the "lightPosition" exits this cone using cosine roll off (line 293 of the code if any-one wants a play)

    :-)

    D



  13. #13
    Originally Posted by DingTo View Post
    I agree, great shader. Thanks for it.
    Thanks to you too for all the work with OSL for Blender and publicising its use. I found you tutorials very helpful.



  14. #14
    Originally Posted by doublebishop View Post
    Just had a quick play, seems like there isnt any motion blur? is there motionblur avaliable to materials? or is it just object motionblur?
    Hi I had a quick look this evening at a few motion blur options. There is an OSL global vector called dPdtime that according to the OSL specification should give information about how the pixel being shaded is moving - but when I wrote a quick script - it did not seem to be giving any values for moving objects (I may have made errors though).

    If the shader could get the past position of the camera and "LightObject' then it could shade the blur in itself. I imagine this could be achieved with pynodes/python script that is called post frame render - so that the positions could be saved for the next frame.

    I also tried a few tricks with motion blur enabled in Cycles (such as moving the lens flare plane in various ways - to see if this would 'fool' the shader into drawing the blur frames) - but to no avail.

    Did you have any luck with a 'get around'?
    Last edited by iReboot; 22-May-13 at 16:45.



  15. #15
    Member 3pointEdit's Avatar
    Join Date
    Sep 2005
    Location
    Brisbane, Australia
    Posts
    8,597
    The idea of generating vectors from a previous frame could be useful in other areas too.

    Quick off topic sorry:
    When shooting chromakey video elements for compositing you need to minimize blur at the edges for a clean key. Best way is to decrease the shutter exposure time, but this gives a very strobe like appearance to movement. It would be nice to track the moving object and place a mask that moves around it. Then derive the vectors of that movement for blur in compositor (or OSL?)

    Another scenario for Blender is it's lack of slow motion generation for fixed frame rate assets. That is external footage used that needs to be slowed down (frames added) but cannot be re-rendered at alternate frame rate. You can interpolate by mixing between additional frames or a bit better you could blur the moving parts between frames via derived motion vectors. But getting them from the tracker I guess is the hard part :S

    End Off Topic.
    Cheers, David ___________"awesome in space and other places".
    ________Follow me on twitter @3pointedit
    _____________ Check the Youtube Channel for tutorials. Or my Sketchbook



  16. #16
    Hi David, Thanks for the comments.

    You have a great set of VSE tutorials!
    Can you recommend a good Render Output can Encoding Setting for uploads from Blender VSE to You Tube? I just use 'plain' old QuickTime to capture the screen (15FPS) - and then Blender VSE to edit.

    I notice you're in Bris - if you'd be keen to catch up sometime then please PM me.

    :-)

    Dylan



  17. #17
    Member 3pointEdit's Avatar
    Join Date
    Sep 2005
    Location
    Brisbane, Australia
    Posts
    8,597
    I was wondering about this tool, what would be the best way to get multiple source flares onto the material screen? Would I use multiple screens/planes?
    Cheers, David ___________"awesome in space and other places".
    ________Follow me on twitter @3pointedit
    _____________ Check the Youtube Channel for tutorials. Or my Sketchbook



  18. #18
    Member
    Join Date
    Aug 2010
    Location
    Adelaide, South Australia
    Posts
    2,667
    Maybe try using the add shader node, and have two individual lensflare setups?



  19. #19
    There are a couple of ways to add multiple flares. You can have as many as you want (if you really want to go all JJ Abrams!)
    As doublebishop says:

    - You can use two flare scripts and an Add Shader node - as in the image below.

    or

    - You can add multiple lens-flare planes -each one with its own shader.

    This can give you a lot of control in post compositing - when you really want to tweak features to subtly suit the scene (that's one reason why there are so many colour outputs -- to allow each element that makes up the flare to be colour/value tweaked/distorted for the desired effect.

    I plan to make shader tweaks and usage the subject of video tutorial 4/4.
    Video 3/4 is on automated lens-flare masking and is rendering now :-)

    dualFlare.png



  20. #20
    Hello all,

    I have just uploaded a tutorial on how to set up the compositor to automatically mask the lens flare when its 'light source' passes behind a solid object (like the Earth for example).

    Here is an example scene showing the effect:


    Here is the tutorial:
    It's pretty long -- but there are 'quick jump' links in the "About" section.
    This tutorial has enough information to set up a scene from scratch (hence the length -- the compositing bit is only around 15 mins!)

    - LensFlare Tutorial Part 3 of 4: Automatically Masking the lens flare using the compositor

    There's an entry on the BlendBits blog site that describes the general workings of the compositor set up which I'll reproduce part of here. (The OSL shader is also available from this site - or from the BlendSwap link in the introductory post).

    The actual node set up is reasonably simple - as can be seen from the noodle below.
    The general idea works as follows:

    1. Solid 3D objects in the scene that should block a lens flare are given a Pass Index.
      The IndexOB render-pass is enabled in the RenderLayer(s) for these objects.
    2. A small emission source (e.g an icosphere) is placed on it's own RenderLayer.
      The emission source is parented to the empty that defines the position of the lens flare bloom.
    3. The emission source output image, from its RenderLayer is Multiplied by the output of an IDMask. The IDMask index is set to match the Pass Index from above.

      a) Flare Blocked: When the emission source is behind a 'solid' 3D objects (white) mask -- then its bright white image passes through the Multiply node. (i.e. 1 x 1 = 1 = small white dot)

      b) Flare Not Blocked: If he emission source is not behind a white mask -- then it does not appear at the out put of the Multiply node. (i.e. 1 x 0 = 0 = totally black image)
    4. The output of the Multiply node is fed into a Dilate node. This will turn the small white dot from 3a into a fully white image that is the size of the render image.

      a) Flare Blocked: Output = fully white image.
      b) Flare not Blocked: Output = fully black image.

      (In earlier version of this noodle - various blur functions were used to spread the dot 'gating signal' to cover the whole image.
    5. The output of the Dilate node is inverted.

      a) Flare Blocked: Output = fully black image.
      b) Flare not Blocked: Output = fully white image.

      Hence this signal can be fed directly to the Fac input off the ADD color mixer that mixes the output from the lens flare render layer with the output from the general 3D scene render layer.




    automated lensflare masking.png
    Last edited by iReboot; 13-Jun-13 at 10:30.



Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •