Sunday 5 February 2017

The CutAway Shader - A free Blender add on for architectural visualisation, model cutaways and more.







After 3 years in the making - I'm excited to announce the alpha release of the CutAway Shader - a free addon for Blender for artists, architects, scientists and engineers.

If you've ever wanted to cut away a cross section of a model, perform an architectural reveal or carry out some tricky special effects then this is the tool for you! 


It works for still images and for animations.

The CutAway Shader can be used for:
  • Model cut aways.
  • Architectural reveals.
  • Scientific and engineering images.
  • Filming through walls (without damaging or re-dressing the set).
  • Special effects (e.g. turning a winter scene into a summer scene).
  • Wire frame to solid model transitions.
  • ... plus much more!





What does it do?

Checkout the CutAway Shader demo reel video on YouTube

Downloading the Addon

  • Download Adddon(.zip)  
    (node_cutaway_shader.zip  v1.2 alpha)
    (This is an alpha release - so remember to save your work!)

Installation

Install the addon in Blender in the usual way. 

or just do the following:
  • File  -> Preferences -> Addons Tab -> Install from file -> node_cutaway_shader.zip
  • File  -> Preferences ->  File Tab -> Check "Auto Run Python Scripts"

Video Tutorials

  1. Installation Instructions and Very Quick Overview Video
    How to download and install the addon - and a very quick intro on how to use the shader.
      
  2. Architectural Reveal with the CutAway Shader: (YouTube link)
    Learn how to reveal the walls and furniture in a house - as seen in T.V design shows and documentaries.

    This tutorial jumps right into it with a practical example - and assumes no knowledge of how to use the shader.
     
  3. CutAway Shader Controls: Overview Tutorial
    All the CutAway Shader controls are covered  - showing what situations they're useful for and how to use them. It is assumed that the shader has already been installed.

    This tutorial is really a compilation of 11 short videos (2 min to 10 min each) covering:
  • A quick overview of the controls.
  • Setting up the CutAway Shader in your scene.
  • Adding cutaway planes.
  • Solidify and Rim Fill options.
  • Cutaway Shape: Rectangular and Circular.
  • Cutaway Shape: From Gray Scale Image.
  • Cutaway Shape: By editing the shape of the cutaway plane mesh.
  • Origin Control Buttons: To help with plane scaling and positioning.
  • Parenting Controls: Easily duplicate parent shaders to selected objects.
  • Auto and Manual Refresh: Viewport speedups.
  • Remove All CutAway Shaders button.

    Each 'mini' tutorial has a heading -- so scroll though the video to get to the desired section, or click on the quick links on the YouTube page.
 ... More tutorials to follow

How does it work? Executive summary

  1. The Cutaway Shader is added as a material node to an existing Cycles material (or materials)
     
  2. Objects in front of the 'green' side of the cutaway plane (that use the assigned materials) will be made fully or partially transparent.
     
  3. A number of helpful controls are available to:
    - Add the Cutaway Shader to multiple materials at once (parenting).
    - Draw a rim at the cutaway cross section.
    - Fadeout the cutaway edge
    - Cutaway arbitrary shapes based on gray scale images, or the shape of the cutaway plane.
      ... plus many more features. (Checkout this tutorial)

Some background info

History: 

After finishing the Open Shader language (OSL) Cycles Lens Flare shader a few years ago, I began experimenting with a few more OSL shader designs. The CutAway shader looked like it would be the quickest to finish (!!!) - so I continued with it.

I noticed with the previous Lens Flare shader release that many people did not know how to add the Blender drivers - these are needed to let the Lens Flare shader know the position of the sun (an 'Empty')  in the scene. A custom 'py-node' in front of the Lens Flare OSL shader could have automated this task. (A Blender py-node is a node that runs Python custom code)

For the CutAway shader release I decided to include a custom py-node to help automate many useful tasks (see figure to the right)

For example, the py-node adds all required drivers automatically. These let the CutAway shader know:

  • The position of the cutaway plane.
     
  • The rotation of the cutaway plane.
The custom py-node also:

  • Colours the cutaway plane in the view port (red on one side and green on the other)
     
  • Provides parenting and duplication functions.
... and a lot of other things too.

This all took quite a lot of time!

Even so, the bulk of the code was finished over two years ago - however, this was followed by the production of 12 demonstration video scenes and several tutorials.

As I am kept very busy during the day project managing this (and like most people have a very busy home life too) this project has taken  approximately 3 years to get to the alpha release stage.


Special Effects Use

Initially I imagined the CutAway shader performing the obvious tasks - Model cross section cutaways, geological cutaways and architectural reveals. But I soon became excited about other uses the shader could be put to.

Special effect Revels: The a shader can easily hide materials on one side of the 'cutaway plane' and (optionally) reveal materials on the other.

This type of effect can be seen in the demonstration video in the following scenes:
  • Winter Forest -> Summer Forrest scene.
  • Ivy growing on statue scene. 
  • Magic stairway reveal scene.
  • Island forest -> Island city scene.
  • Filming through set walls (see full video)
     
These 'special effect'  examples can easily be extended to many additional scenarios:

  • Revealing car tire tracks in the snow, or in the desert, or on a road.
  • Casting shadows in laser lights shining on a mist.
  • Animated characters 'morphing' from one costume set to another (super hero style)
  • Cat scan style cutaway sections.
  • Easily Cutting holes to let the light into a scene (without affecting the mesh or U.V wrappings)
  • ... etc

Another interesting use for the CutAway Shader is related to the 3D  pipeline work flow. The shader makes it easy to 'punch' any arbitrary shaped hole through scene elements without affecting the base mesh or U.V mapping. If a client wants to move or add an window to a scene at the last minute - none of the existing mesh or U.V work has to be re-worked. The shader will create the new hole with the desired shape and additional geometry (or existing windows etc) can be moved into place.

If the pipeline involves mesh assets the are frozen (or scene dressings that are locked) then the shader offers a new  method of  hiding (cutting away) assets that are blocking the camera view. This can be achieved without actually moving assets or redressing the scene.

This concept extends to 'filming' through set walls - without affecting a set's internal lighting setup, as the shader can be configured to only cutaway 'camera rays'. (i.e. we can look through 'solid' walls without light leaking into or out of the set!)

Filming through sets can be useful for when the desired framing and depth of field results in a lens size that forces the camera to be placed outside the walls of a small set (e.g. a small bedroom, or small space capsule).

So, the possibilities for the Cutaway Shader are surprisingly large for such a simple concept!

Give it a try!

Let me know what you think in the comments below - or e.mail:  iReboot42 at gmail dot com.

Please note:

  • This is an alpha release - so please save your work first. 
  • There are a few 'non-standard' features related to the parenting controls of the shader, These allow the CutAway Shader node to be automatically replicated among selected objects in the scene. Child copies of the parent node are added to the material nodes of selected objects (i.e this feature will alter material nodes in your scene).

Future Work

There are many features that could be added to the shader - along with some optimisations. I would like to look at micro displacement of shaded points in the drawn 'rim' to improve this effect.

Cheers

Dylan

Thursday 13 June 2013

LensFlare Tutorial Part 3 of 4: Blender Lens Flare: Automatic Masking 


I have just posted a new tutorial on how to achieve automated masking of the lens flare using Blenders compositor.

Automated masking of lens flares can be very useful for complex scenes -- such as in a forrest - where many randomly placed branches may block a lens flare.



Here is an introduction animation showing the automated masking in action:



Here is the tutorial.

It's a little long - weighing in at just over 60mins -- but it has been put together to allow a non-expert to create a scene using the lens flare shader from scratch. Links in the info section below the video allow advanced users to skip ahead.



Here's the Automated Masking Node Setup

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 Lens Flare Masking Node Setup (click to enlarge)

The main reason that the video is so long is that it takes a while to go through the steps (for newer users) that allow all the render layers to be setup and the  drivers to be added to the shaders.

There are many more way's to achieve this automated masking effect I'm sure - so it will be interesting to see what people come up with.

This latest invocation is fair;y simple -- and very fast. It does appear to be very 'binary' however. It mostly seems to block - or not block.

Some of the earlers methods that used blur nodes etc were very good at quickly 'fading out' the lens flare as it passed behind objects (such as tree branches or plane wings).

Some tuning can be made with the masking sensitivity however by changing the emission brightness of the source (as seen in the video).

Draw Backs

The compositing method as described above has a key drawback in that once the lens flare bloom moves off the screen (along with its special masking emission source), the compositor can no longer be used to manage the masking -- as it cannot process off screen images.

There are work around for this - such as adding another special emission light source on the 'Masking' Render layer that can be 'keyed' by hand to get the flare into the desired visible state. The lens flare shader's Intensity input itself may also be 'keyed'  in this case.

The Future

I would like to investigate the use of the OSL 'trace' function to determine if any 3D scene objects are occluding the ray from the camera to the 'light source'. I did try this when porting/developing the shader - but without initial success.  It should be possible though - so hopefilly in the future -- extra compositing nodes and render layers will not be required.

Until then however -- this nifty trick seems to work well.

Also in the future - it would be good to see if a Python add on, or a Pynode, could be used to automate the set up of the lens flare render layers  camera plane creation and parenting. Again -- this should be quite do-able - but will have to wait for some development time  ;-)

Monday 20 May 2013


Lens-flare Shader for Blender Cycles with real time preview

I have been using Blender for several years and have recently started to learn OSL - Open Shader Language.

As a first project I embarked upon creating a lens-flare shader for Blender. In the process I came across a lens-flare shader, written for the Renderman language by Larry Gritz & Tony Apodaca.

I decided to try and port this to OSL - and to my surprise after a day of tinkering it worked! Along the way I added a few features, such as user definable images for lens-flare elements and have got to a point where the shader can now be released. Details about how to download and use this shader are given below - along with video tutorial links.


Before proceeding, a big thanks to the original authors of the shader, Larry Gritz for his work in making the Open Shader Language available to the world and the Blender developers for creating such a great tool.

In the process of learning OSL (an on-going process) I found the following blogs / links extremely helpful.

Screenshot showing the lens- flare shader node set up, real time 3D preview, and positioning control.
Drivers are used to link the position control Empty to the shaders "LightPosition" input.

Lens-flare Shader Features:

  • 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.

Shader Set up:

The lens-flare is created by applying the shader to a plane
 parented in front of the camera. An "Empty" is used to define the
position of the flare's light source.
The image above shows the simple shader node set up
for the lens-flare plane material. The "Light Source Empty" position is fed to the
shader using Drivers to set the x,y and z inputs of Value nodes.

Video Tutorials

Two of the planned four tutorial videos have been completed. Follow the links to see an overview of the lens-flare shader features - anda tutorial on how to set up a scene with this shader.
Part's 2 and 4 are yet to be completed - but will go over additional composition features - such as automated masking of the flare as it passes behind objects. (Download the .blend file or look at the node 'noodle' below if you want to try this before the videos are completed).

Download an Example Blend file and LensFlare Shader File (lensflare1v1.osl) 

An example .blend file with an:
  • Example scene
  • lensflare1v1.osl shader 
  • Sample user defined shader textures
  • Masking composite node setup
is available from Blendswap here.

Get a copy of the Shader here!

  • Download a copy of the code below as lensflare1v1.osl - and save into the same directory as your .blend file.
  • Load the file as a script in the materials node editor - and connect directly to the Material output node of a plane parented to the front of a camera. Follow the video tutorials for more information.




Automated masking of the flare 

This is the subject of an upcoming video - however if you want the Node
Noodle - either download the .blend file from Blendswap (see above) or copy the node setting below.



Note: An additional lensflare plane with its own shader is needed in front of the camera for this to work)

Finally

I hope to see your example scenes and tutorials on the web  :-)