Introduction to Compositing in Blender

Finance For The Future
12 followers
Oh yes, compositing. If you've never tried it, it may seem like a giant waste of time.
I mean, why render out something in layers, only to put everything back together later?
Especially since I can just render it all in one go, right?
Well, kinda. But in this video, I'm here to tell you why you might be better off using compositing.
Especially with heavy scenes, you might encounter your render failing a lot,
and rendering in layers helps with that. But of course, that's not all. In my experience,
from any larger production, compositing is a must. Because only in that stage,
one can really fine-tune colors, blend everything together nicely, add extra effects, and much,
much more. In other words, the real final image only comes about in the compositing stage.
Before we start, let me make a little note. I personally like to have my Blender UI a little
bit adjusted when it comes to these menus here. I like to right-click like this and flip them
to the bottom. So yeah, it may be a little bit different from what you're used to.
Also, be sure to have NodeWrangler activated before going into this tutorial. You do it in
preferences, add-ons, and NodeWrangler here, and then save your preferences. Otherwise,
some of the shortcuts I'll be mentioning won't work for you.
So as an example, I have here this desert environment. I'm sure you'll recognize it at
this point from my Master 3D Environments in Blender course, where you can learn how
to make it step by step. And the cool thing is, this scene, yes, it is made entirely out of planes
with this main desert plane as a basis for our terrain. Of course, when I switch to rendered
view, it gets displaced because it's using this adaptive sub-D modifier with a combination of
textures in Shader Editor. Then to extend the scene without adding too much of a performance
strain, we have these 2D planes placed so far behind that we do not even realize they're 2D.
In the mid-ground, it's the desert plane rendered and put on a flat card.
And in the background, it's some hazy mountains. And the sky, yep, it's 2D too.
In the course, you'll learn how to make all this and also add a particle setup with dust elements,
some HDRI lighting, and atmospheric layers, plants, and more.
Alas, that's not what this video is about. As I said, it is about compositing this scene together
to achieve even better results than we see here. And rendering is a first step to being able to
composite your layers. By the way, this workflow applies to all the other scenes of the Environment
course. Only in the rest of them, we go more in-depth, using more advanced compositing networks.
Still, the techniques remain the same all throughout. Before I explain what render layers are,
first, let's take care of organizing our collections here. Throughout the lessons,
we have diced up our elements into these groups to make the scene a bit more tidy.
And by the way, you can just download this blend file to follow along from the resources section
of CG Boost. Just have a look at the info of this video and click on a link there.
So we have this desert layer, the 2D desert plains, atmosphere, dust, mountains, sky, and more.
But we didn't create these collections just to make our outliner more organized.
These will actually help us with our goal, rendering and compositing in layers.
Now, thinking about how to dice up your scenes is a big part of this compositing process.
But let's make our composition fairly simple for the sake of this tutorial,
and let's base it on the actual distance from the camera.
So we have this whole foreground element, comprising of the desert dunes,
both the 3D ones and the 2D ones, also the dust and some grass particles.
So that will be our first foreground layer. Then we have this far background mountains,
so that will be our second layer, then the sky.
And finally, I have a very foreground element here, this FG dust,
which is just two dust particles placed in front of the camera to give the scene a bit more depth.
We will composite that one in front of the desert,
which gives us four layers, and we will now try to render them separately.
For that, let me check the collections here to make this all very simple.
It is always best to have the stuff you want to have on one render layer
to have it in a single collection.
So we have these mountains here, good,
then the sky collection and the FG dust collection, exactly as we need it.
And then we have all the rest of this mess.
So let's say we make a new collection by right-clicking here,
choosing new collection, and then double-clicking on it and rename it base.
And take all these and put it there.
Then we can even push the collection up here to have it after the FG dust,
which is the foreground layer, but above the mountains, which is the background layer.
So this way, we've ordered everything as it overlays each other.
You can see there is some extra stuff here, cameras and one sun lamp,
but that doesn't really need to be in any collection
because I want these to be active on all my render layers.
Cool, let's try this out, hide these three and leave just the FG dust.
Just the foreground dust is visible.
And if I unhide the desert and hide everything else,
just the base layer is visible and so on.
So far so good, but we don't want to always manually activate
and deactivate various collections to render various layers of the scene.
What we want is to save four different setups
where Blender would store the visibility of these collections
for all the four layers we want to render,
the FG dust, the desert, the mountains and the sky.
Well, and that is what render layers are for.
You find them up here where there is this render layer sign.
So now we have the base layer active.
Let's rename it to have the same name as the collection we want to render,
which is base.
Now control select these three collections
that we don't want to render on this render layer,
a right mouse button and find this view layer menu.
And in it, find disable from view layer.
Yep, you may be a little confused at this point
because the sign here stated render layer,
but now we read view layer menu.
Well, yeah, but that's not my fault.
These layers we are creating are called view layers,
basically storing sets of activated collections in your viewport,
but they also function as render layers,
storing which collections should be rendered on a specific view layer.
Yeah, thanks Blender.
Just bear with me, everyone.
It should be clear soon.
Okay, menu here.
So you can see a shortcut here,
which is E to disable the selected collections from this view layer.
Let's try it.
Go back to outliner, hit E and C.
These little checkers got deactivated
and the collections disappeared from the render.
Exactly what we wanted.
Next, let's just duplicate this view layer with copy settings.
This basically just takes all the info
of which collections are activated and which are deactivated
and copies it to a new render layer.
New would activate all your collections
and blank would deactivate them all.
Name it FG dust because that's the collection
we want active for this render layer.
And now we don't want the base layer this time.
So select it and hit E to deactivate it
and then select the FG dust collection
and hit Alt E to bring it back.
Done.
Now this view layer renders only the foreground dust.
Next, repeat the process for the mountains.
So copy settings, rename the view layer,
hit E on FG dust and Alt E on mountains.
And finally, the sky collection, copy settings,
name it sky and you know what?
You do not have to hit E and Alt E.
You can of course always use these checkers.
So just uncheck this and check the sky collection.
I just wanted you to know the keyboard shortcut.
Now, when you switch between these,
the layers we set get activated
and that is really a great way to separate your blend scenes
to render only separate collections
and store those settings for later.
A little note here,
there are also these render overrides hidden here
and among them super useful option
like this holdout mode,
basically punching a hole into your composition
wherever the objects on this specific collection are.
Or then there is this indirect mode
which will hide the objects
but make them visible in reflections, refractions,
glossy passes and well,
all the other indirect light effects.
We will use this a lot in the course,
especially for reflections on water.
We can give it a quick render now with F12
to only render one frame, you see.
I'm making this render faster
by only rendering 25% of the overall resolution
and also worth mentioning is
I have the various layers transparent
because I've checked this transparency checker here
under the film tab in render properties.
And it goes through all four of the view layers
or at this stage, render layers
and you can then see them stored here separately.
And if you were after just a single rendered image,
you can just hit save as on all of these four layers,
write them to your disc,
switch to another path,
save this one as well
and do it for all the four layers
and then just skip to compositing.
However, we are making a shot sequence.
For my shots, unless I want to go really professional
with EXR or DPX formats
with great data depth,
I just usually pick this PNG format
sometimes with 16 bits for colors
and I render out sequences of images.
But hey, Martin, why image sequences
and not a video, you ask?
Well, I'll tell you.
Two reasons actually.
One, most video formats include a form of compression to them
so they lose quality
in order to be able to play the video smoothly
which we do not want.
We want to retain the quality of each frame.
Second, most video formats do not have the option
to include alpha channel
which we actually need for compositing.
Fortunately, the PNG format will allow us
to store all these data
with only a limited loss of quality.
All right, now let's specify where to put the sequences.
Create a base folder and give it a name,
base underscore.
I use underscore here
because image sequences are rendered as separate images
with a number at the end
indicating the frame number
and I find it better to have this number separated by underscore.
Cool, so logically, we now want to render out
all our render layers at the same time onto our disk
just by hitting this render animation command
or control F12.
So let's see what happens if I render a few frames.
Okay, so I'm done rendering a few frames
and when I open the folder I specified in the output menu
I can only see the base layer rendered here.
Not the mountains, not the sky
and not the foreground fog.
So how to solve that?
Well, we'll use a compositor window for it.
If by any chance nothing appears in the window
just make sure you've checked the use nodes option
only then the node workflow will be activated.
You can now even maximize the window
by hitting control space bar to see it better.
What you see here is a rendered layer node
connected to the composite node
and if you don't see it
just shift A search for it
add it from this menu here
just like you would in shader editor.
Basically what is happening
the frame is rendered, stored here
this connection lines take the first rendered layer here
ordered alphabetically
and drive it into the composite image socket
which is then saved as our final frame.
But you can see here there is the rest of our layers
and those do not get saved.
What we can do though
is to duplicate the render layer node three times
and in each one set another pass here.
FG dust, mountains, sky
and now let's just set where should these layers
be stored on our disk.
So hit shift A, add three file output nodes
and connect them like this.
So now what this does
each of these image sockets will be driven
into file output command
which will then save this image
into a folder we specify here.
After that I like to go in here
and create those specific folders.
So one for FG dust
and you can delete anything from here
and hit accept.
Then one for mountains
delete this
and one for sky
and delete this again.
Accept and here we go.
Now hit render animation
and if we have a look in the folders afterwards
yes these are now rendered as well.
Very good.
The only issue I still have now
is that all these, the FG dust, the mountains, the sky
it is called image 001, image 002
and if all our extra rendered layers
are going to be called image
it may get real confusing real fast.
So let's have a look at the file output nodes here.
Hit N to bring out the sidebar
expand the properties of the node
and let's name this little fella right here
then mountains underscore for this one
and finally sky underscore for this.
And with that if we hit render animation
all our layers are rendered and saved at once
in separate folders.
Pretty useful I'd say.
Having finished the render layers
and setting up the render
so that it automatically stores the rendered images
onto our disk
we only have to set up a few values
in the render and output tabs.
First the output menu
where we can set the size of our rendered images.
Up here you can see that I've set this cinematic format
I like to use
which is 21 to 9
most commonly using this 2560 to 1080 resolution.
This gives you the super wide cinematic image.
The percentage here I cranked up to 100
you may even go to 150 to achieve 4k resolution.
Of course with all this you can go lower
to save some computing power
and sure you can even change the resolution format.
I specified frame rate to be 30 here
that's the rate I've chosen for all of the scenes in the course.
Other than that it's just in frame here
I need just 90 frames to have a three second shot
and the output with the location
where to save the base layer
and then the PNG format set here.
Good, so now let's move on to the rendering tab
because that is where we can really influence
the speed of the rendering.
First things first
I am using the Experimental Cycles render engine for this
I use it for the adaptive sub-d displacement
with which we've created a desert in the course
and I'm also using GPU computing here.
If you can't switch to GPU or if it's grayed out for you
you need to check it in preferences
and switch to CUDA
or if your graphic card allows it to optics.
If you happen to run out of memory when rendering
it doesn't automatically mean you have to switch to CPU.
First make sure you have switched to shaded view here
before hitting render
because render preview takes some memory too.
Also close any other GPU based applications
you may have running
like other 3D software, image editors or cyberpunk
especially cyberpunk.
Finally I sometimes restart my computer
before the final render
you know, to give it a fresh start
and make it rest for a bit after weeks of rendering.
No idea if it really works
but I do it anyway
only if all this fails
and you still run out of memory
switch to CPU rendering here
it is generally more reliable
but slower for this sort of job.
Next in here I use just 256 samples for the render.
I didn't really need more
because I have great experience with blender denoising
so I've chosen to rather denoise the render frames
then go overboard with all the overall sampling
which would slow down the render a lot.
I did not use any of the optics denoising
which is great
but I rather wanted to do some denoising
in the compositor later.
In the light paths
I found that the default values are way over the top
I didn't really need two extreme values here
just eight for total light bounces
two for diffuse
four for glossy
I probably could have gone even lower here
as well as with this transmission
and yeah zero for volume
we don't have volumes
anyway
the only thing I cranked up
were the transparency levels
I added 40
because we have a lot of transparent planes in the scene
creating the dust
and if we didn't have higher numbers
there would be a lot of dark fragments
where the transparent particles overlap
the rest I left mostly as it was
apart from this subdivision menu
I changed some values here
to make the computation of the subdivisions a bit faster
this off-screen scale ensures
that anything that is outside the range of the camera specified here
will not be subdivided as detailed
as anything that's in camera view
so that usually helps a lot
and I also activated motion blur
to have it baked into my rendered elements
I raised the shutter to have more of it
but default values of 0.5 would probably be okay as well
in film tab
do not forget to check this transparency here
to get your separate passes with transparent background
and then if you're using Blender version 2.9 and below
very important option here
definitely check the settings of your performance tiles
if you've set the render to GPU
it's better to set bigger tiles here
like 256 or 512
if CPU values of 64 to 64 pixels will be good
and if you're using the new Blender 3.0
you can safely disregard this option
because it is now calculated automatically
after that I just hit render animation
and finally went to sleep
well not really
let's render one frame here
let's speed up the video and see how it looks
nice but noisy
so it's time to go back to the compositing window
and see what we can do about it
first though we need to activate an option
that will allow us to denoise the final image
it is called denoising data
and you find it here in the passes menu
with that checked let's re-render the image
when you do you will notice that in the compositor
there is a few new output sockets in your render layer node
the denoise image, normal and albedo
without really going into this
how this thing works
not that I really know how it works
but all we need to do now is to use denoise node
shift a
search for it and add it here
now connect your resulting image here
then the denoise normal
and albedo here
with that done with F11
activate your render output window
and have a look at how the composited image looks
and to compare it
let's switch to the original base image
with the noise
without the noise
with the noise
without
the result is a tiny bit mushy
but quite okay for my final shot
because remember
even shots from your digital camera
are always a little bit blurry and imperfect
so having a perfectly crisp and sharp picture
isn't really the best solution
and while you're at it
you can also go through the various view layers
and activate the denoising data for the rest of them
and then plug it the same way we did before
so denoise node
in between the file output and the render layers
and then image
albedo and normal
into the denoise node
and with that I finally hit render animation
and waited until all my layers were rendered
and next up
we'll finally get to compositing
wonderful
when all this is rendered
we can take the image sequences
and put them together in a compositor
for example
Blender's compositor
as you can see
I have started a new blend project
and created a slightly different setup here
for this compositing stage
by dragging the corners of the windows
I reposition the windows
and I have this big window with my compositor here
and below that a timeline window
since we are going to be working with image sequence clips
so that I can scrub through them
and now let's put our shot together
if you're new to this compositor window
know one thing
it operates basically the same as shader editor
you can add stuff with shift A
and here you can search for your first node
called image
put it here and open it up
search for your desert base footage
and load it in
now if you have this option to detect sequences checked
and hit A
to select all your images in the folder
it should automatically set it up for you
so image sequences here
number of frames
and with an offset here
because we start the numbering at zero
also auto refresh is checked
and RGB values here are fine
this is good
but we don't see it
well for that
let's put the composite result directly into this compositor window
first plug it in here
and get rid of the render layers window
then create one more node called viewer
this one will allow us to preview the composited image
in the background of our window here
to do it
hit N to open up the shelf
and since we have our output view here
we can now activate the preview in this view menu
check backdrop
and voila
we have our layer in the window
you can now still move your nodes with middle mouse button
and zoom around
but the backdrop stays there
at this point it is too big though
so what I like to do is to go in
zoom out here
and push it up like this
all right
now let's get compositing
first things first
we will blend all our layers together
so if you want to overlay various rendered layers in the simplest way
just like you mix textures in shader editor for example
we can mix image sequences
the node that does it is called alpha over
so let's add it
move our desert base
oh and by the way
you can always rename your image sequences here
and name it desert base
now duplicate it
put it here
and let's choose for example
the mountains instead
it's all set up here automatically
so we can proceed to connecting the nodes
and then to the output image sockets
it's a real pain to always connect these two
so one thing to streamline this
is actually to shift right mouse
and drag to create a reroute node here
and drag the connection out of it
now we can always connect just one connection here
it saves some clicks
well now it's of course the wrong way around
we need to switch the inputs here
and actually move the nodes
so that they do not crisscross with their connection lines
and this doesn't look good
well Blender's viewport always had problems
with previewing transparency right off the bat
especially when you are compositing on a transparent background
which we currently are
what helps though is to use this convert pre-multiply checker here
again without going into details
because that would be a topic for a whole separate video
what it does is it takes our alpha channel of the image
and then multiplies the black color over the RGB channel
making the transparency work as expected
and yeah this is much better
now of course we want to see the backdrop better
so what you can do is to zoom in
and by the way super handy shortcut is alt middle mouse button
to be able to move it around with the mouse
without alt you're moving the nodes
with alt you're moving the backdrop
cool so shift D
load in the cloud image sequence
and rename it
then duplicate the alpha over
plug it here
and actually again switch the connections
and finally let's bring in our dust layer
so duplicate
replace the image sequence
and alpha over it
good however this dust you may not want to mix in hard like this
just covering the background elements
for this layer you actually may want to use mix node
add it in
mix these two
and replace the alpha over connection here
now something terrible is happening again
but that's just a problem with the transparency
so we need to use this checker this time
to actually use the transparency of the input
now in this node as it is now in mix mode
it functions basically the same as the alpha over
however in here you have all the other blending modes to choose from
so what I like for this dust
even though it's not actually correct
and any skilled compositor would kill me for that
is I sometimes like to set dust elements to screen or even add mode
now why is it wrong?
dust doesn't really brighten up your shots
instead it covers it
because it basically is a layer of solid particles over your shot
however I sometimes like to go with what's nice
rather than what's correct
I mean when it comes to compositing
not in real life of course
so when I compare the add value to the mix value
I like the add more
however we can definitely bring it down to about 0.5
if you now hit m
you can deactivate the node
and then hit m again to reactivate it
and since it's better than alpha over in this case
let's delete the node
cool
so this way we connected our node
basically we just reconnected the stuff we would get
if we rendered all as a single layer
so again that question
why render it in separate layers at all you ask
well now it's time to show you
because in compositing stage
you can do all sorts of extra 2D work
you wouldn't be able to do in 3D stage
or at least it would take time
and it would be too difficult
the simplest thing you can do
is to for example add a curves node
and very quickly play around with the lightness of the nodes
like this mountain node here
see
I can make it brighter
darker
even change the color tones
by just adding one more point on the green curve
and messing around with its position
and also on the blue curve
I was able to bring the colors of the mountains
closer to the colors of the sky and the desert
and now it all blends more believable
another great thing
even after a rendering stage
I can for example play with the positioning
so I add a transform node
and here
I can push my mountains up or down in the image
or scale it
even rotate it
that's especially good for some 2D elements
you want to add to your compositions
see why this stage might be useful
and seeing this
I think we can raise this curve
to make the mountains brighter after all
just like you would in shader editor
you can now select your nodes
and hit control J to frame them
you can then move the whole frame
and also if you don't like the looks of it
you can go to shelf and node here
and give this thing a label
so let's name it base for example
and you can also make the label bigger
and give the frame a color
at this point
you can of course scrub through your timeline down here
unfortunately Blender is not really fast at this
and definitely do not expect seamless play
it will be the slower
the more elements you add to your composition
speaking of 2D elements
let's add some over our image base
I have prepared some very simple elements
to add to our image here
so first I have this gradient image
from your folder
you can in fact directly drag it here
to the compositor window
and it pops right in
what I want to do is to overlap it on top of our image
to create a bit of sun glow
on the right side of the frame
so first duplicate this add node
shift T
and push it to the right
alt P will remove it from the frame
and now it got very bright
because it is adding white color
from the second socket to the composite result
so let's instead add the gradient
see
now it's adding this orange sun glow to the shot
however I want it to be on the right side of the shot
so let's add another node
meant for moving images
called translate
and push it on x-axis
about 1000 pixels will do
easy right
you can even push it up a little on the y
about 200 will do
next I want to scale it a bit
so before the translate node
add scale node
I want it to be taller
so y-axis and 1.2 is okay
finally what I feel it needs
is a bit more intense saturation
or maybe even a hue shift
well for that
there is of course the hue saturation node
which we can plug in here
to control the colors
put these nodes to the side
so that we have a slightly better view
crank up the saturation
to feel more like warm desert sun
about 1.7 will be good
and let's adjust the hue a tiny bit
to about 0.51
you need to be very careful with this value
but it helps to shift your colors overall
cool
one more thing we can do
here in the mix node
if you go to the shelf
item properties
you will see this factor value here
so we can adjust the intensity of the mixing
let's go with 0.4
or you know
you can always change the values here
I just wanted you to know
that in the shelf
in these properties
there are the same options
as are in the nodes
frame it
name it gradient
and we are done with this element
in the similar way
we can mix in another important effect
a vignette
I myself use two ways to do this
the first is
I have this transparent image here
of a black color
on the sides of our frame
which we can mix in
or we could of course
make our own in the compositor
I find it faster
to have some prepared elements
that I just use for all my shots
but the other way is more versatile
for various resolutions
though it is usually slower
all right
let's try the image method
bring it in
duplicate the add node
and connect these two
of course set to add
black color doesn't really do anything
however set to overlay
a different story right
you can go lower with the mixing factor
0.2 or 0.3
something like that
I'll go with 0.2
a slight but important effect I'd say
frame it as a vignette
and here we go
a nice cinematic darkening for our image
the second way to make the vignette
is manually
with several nodes
one little note here
for this to work
you need to copy the exact
same resolution settings
as your footage has
including this percentage here
so set 2560 and 100% here
next let's bring in this ellipse mask node
and plug it in here
it makes for us this hard-edged ellipse
which we can now adjust to our needs
so resize it here
until it almost touches the corner
but not really
this doesn't have to be precise
now bring in a blur node like this
and change it to fast gaussian
to make it faster
and with it blur it significantly on x and y
by the way you can also switch to this relative mode
and there you will be working with percentage
instead of blurring pixels
if it suits you more
and in the end I just duplicated this overlay node
and deactivated this one
and voila
that's how you make your own vignette effect
now we can focus a tiny bit on the coloring
let's add a curves modifier
and let's play with this curve
you can lower the green highlights
and raise the midpoint of the reds
just to give it a little bit of red tint
you can also increase the contrast of the image
by making a contrast curve like this
raising the high points
and lowering the low points
you can also raise the low point of the blue curve
because blue shadows make everything
a little bit more cinematic
as does more contrast by the way
next a node I really like
but one you also have to be careful with
the glare node
set it to fog glow
with low settings here
and then threshold of about 0.5
and size of 9
see you can give the dunes a bit of that glowy punch it needs
if you want to have more sense of motion blur
at the edges of the screen
right around here
you can also add a direction blur node
if we really crank up the values
like 8 iterations and zoom of 0.1
see what it's doing
but for my purposes
the zoom value needs to be raised only slightly
like 0.05 and one iteration
almost like a cheap motion blur
and finally to top it all off
a thing that you may have seen in the trailer for the course
and also an effect that in my opinion
is way overused these days
the chromatic aberration effect
you add it through this lens distortion node
add very low value in here
and then to remove these weird edges
check fit
just promise you'll not use it too much guys
it can get real artificial looking real fast
so if I now ctrl shift click on this first mix node
where we put all our layers together
and preview it
well it's a change right
with this composition
we have of course just scratched the surface
of what's possible in this compositing stage
but I think already the result is a bit more interesting
and now when you want to render the final sequence
you just bring in properties here
specify your output and the format
which is the same as the input
you do not want to deviate from the images
you put into the comp
and then hit render
so my friends
I hope this video was useful to you
introducing you to a topic
which at least in my opinion
does not get mentioned nearly as much as it should
in Blender tutorials
I for one know that compositing saves a lot of my 3D scenes
which would otherwise look uninteresting and boring
with a few well-placed 2D elements
some nice blending and color adjustments
you can do wonders for your CG images and shots
and if you want to know more about all these topics
as well as how I've made these 3D environments in Blender
I talk about it at length in my
Master 3D Environments in Blender course
which is finally in its complete form
polished and ready for you to level up your Blender knowledge
so I hope to see you there
or next time in one of these YouTube videos
until then
stay creative my friends
Martin out
