A Note about Scenes and Layers
Before we begin, however, we need to discuss “Scenes” and “Render Layers.”
A scene is a group of elements combined into a single picture. They are developed separately from each other, usually for the purpose of their name; different environments for different scenes. However, they do have the ability to be combined using the node editor.
This is important; the ability to combine scenes in the node editor will allow us to apply different effects to the sky. Unlike the wireframe which should glow, a good starfield should not; the brightest stars should do some sparkling, but most of the stars should be pinpoint dots that glow. By making a separate scene that’s composited into the final render, we can combine the glowing landscape with the clear and sparkly nighttime sky.
About Render Layers
A render layer is a set of graphics that gets mixed into a final image. In programs like Photoshop, layers are literal, acting like transparent film with drawing that gets layered over one another, covering up parts of what’s under them with their drawings. In Blender, the term is less literal, in that there is no “stacking” order; all objects are rendered based on the layers selected, and in which categories they’re selected.
For example, consider the following picture:
The light source, reflective sphere, and the solid plane under everything is on the first layer, which is enabled in both the “scene” (affects light paths) and layer (actually visible) layers. This means that these objects are both visible, and they interact with lights.
The cube, on the other hand, is only set in the scene layer, so while it is completely invisible, it still interacts with lights, meaning that shadows and reflections can still happen, as you can see here. It’s not directly visible, but it is in the scene.
The cone is set in both scene and mask layers. As with the cube, reflections and shadows could still register, except that it is glowing. As such, it is emitting light that other objects can pick up. How this layer differs from the cube, however, is that you can see a solid block area where the cone should be. If I had “transparency” on in the film settings (under “Render”), it would have been transparent instead.
For the purposes of this article, however, all we need to know is that the render layers exist, and that we can use them to make some things visible, and other things hidden. The main use for “hidden” layers is to hold the shapes that will be generated in other layers, such as our stars, once the starfield is ready for them.
So, without further ado, let’s save to a new file (to preserve the original wireframe file) and begin.
Creating a New Scene
Now, the wireframe itself is one single scene. In order to keep things organized, we want to make sure it is appropriately named in the “scenes” list (right next to the list of screen configurations at the top of the window). So, let’s change “Scene” to “Wireframe.”
While using “Link Objects” could be more convenient, let’s take the more complete road, and select “New” for now. Once the new scene is created, let’s call it “Starry Sky” (or, you could choose a better name).
Now, we want to have our camera in the starry sky scene as well as the wireframe scene. Additionally, we will want the camera’s motion to be the same in both scenes. That way, if we decide to do animations, the sky and landscape will be consistent with the movements of the camera.
So, we want to link the camera we already have in the wireframe scene with the starry sky scene. To do this, go to the wireframe scene, select the camera, and then link it using “Object” -> “Make Links” -> “Objects to Scene” -> “Starry Sky”.
Now, the camera is in both “Wireframe” and “Starry Sky,” and moving the camera in one scene will move it in the other as well. And this will be important once it comes down to compositing them together.
The Vertex Sphere
The vertex Sphere is the name I give to a sphere of vertices used to position stars in a sky. The vertices are hand-manipulated (with some automated help) to give a random, organic “night sky” patten, which is pretty much what we want.
Making the “Vertex Sphere”
To make the starry sky, we need to have the points where stars will render. This process needs to be random, but artistic, and it needs to be consistent in a complete sphere for this to be believable.
Now, unselect the cube, and we can begin the fun stuff.
First of all, we now want to select random vertices on the cube. You can either select them yourself at random, or, if you want to save some time, there is an option (“Select” -> “Random”) that will do all the random selections for you.
Once you have random vertices selected, use the scale and rotate tools to move them around randomly, while keeping the center of the object centered. Keep doing this for some time, periodically subdividing the cube more and more until you have a pretty messy… thing.
It is important to specify “Only” edges and faces, because normally, if a vertex is between two edges that are being deleted, the vertex will be deleted as well. We want all the vertices to remain, just the edges and faces to go away.
In the end, we should now have a huge collection of dots.
You might have something different, but if you end up with a cloud like this, we can safely a good portion of the dots by using the “random” selection again, and just deleting the vertices that are selected. Once you’re down below 15,000 vertices, it should be safe to continue.
Next, we want to align all these vertices into a perfect sphere. To do this, simply select all the vertices, and then select “Mesh” -> “Transform” -> “To Sphere”.Move the mouse right until all the vertices are in a sphere shape.
Finally, you need to make sure the origin point is in the center of the vertex sphere. To do this, simply select the sphere in object mod, and use “object” -> “transform” -> “origin to geometry”.
Your vertex sphere is now ready for positioning.
Positioning the Vertex Sphere
Space is big. Very big. And a side effect of that bigness is the fact that stars seem to stay fixed in the sky when you walk/drive/fly around. Of course, they obviously move at pretty relativistic speeds through the cosmos, and they spin around the sky as an optical illusion of the planet itself making an awful lot of movement.
But from the perpective of our camera, if the camera moves, the sky follows along with it. However, if the camera turns, the sky should not turn with the camera. This means that the vertex sphere, the scaffolding that will make our nighttime sky, should always follow the physical position of the camera, without actually turning with it.
To do this, we need to add a constraint to the sphere.
To do that, we need to leave edit mode, and select the vertex sphere. On the constraints properties panel (the chain-looking tab), select “Add Object Constraint” -> “Copy Location”.
From this point forward, the vertex sphere is now always around the camera. If the camera moves, the vertex sphere will move with it. However, since we used “Copy Location” and not “Copy Rotation,” the sphere will not rotate with the camera. This means that the stars will seem to behave like real stars.
One more thing we need to do, and the vertex sphere will be complete.
Sizing the Vertex Sphere
The vertex sphere is pretty small as it is right now. We want it to encompass everything the camera can see, so that it is always behind whatever’s in the “foreground.” To fix this, we simply need to (using the “camera view”) select and scale the vertex sphere (moving the mouse rightwards) until it hits the “clipping point,” the point at which the renderer will ignore everything beyond.
You can tell when you reach the clipping point, as the points will start vanishing at the center in the shape of a circle:
The Star Patten
We could get away with just using dots, but for best results, it helps to actually create objects with special materials for the stars. This way, when they spawn in the nighttime sky, they can actually look like stars, complete with the variations of color and size one would expect.
Designing the Pattern
By itself, the vertex sphere might fit the look of star positions, but if you opened the render view, you’d see nothing; vertices don’t glow. We need to design stars to be rendered at those positions. This is why layers were discussed; we need to design and texture our star in another layer, where it won’t be rendered.
To do this, let’s go to layer 2. At the bottom of the 3D View window, click the second layer box:
Now, we need to make a sphere (“Add” -> “Mesh” -> “UV Sphere”).
By itself, this would be fine for a star, but for something that’s going to be tiny, we can simplify this a bit. This way, we can ensure that the star sphere isn’t taking up immense amounts of memory for rendering.
To do this, once we add the sphere, on the left-bottom panel is an “Add UV Sphere” properties consisting of “Segments,” “Rings,” and “Size”. I would probably recommend reducing the number of segments and rings to 8 each. The object will still be round, and at the sizes and distances involved in the starfield, the angles will not be noticeable.
That’s all the work we need to do to make the star’s mesh. Make sure to name the object “Star,” because we’ll need to select it later.
Designing the Pattern Material
Now we need to create the material. This is done in the compositing view, so let’s switch to that view now.
You might have noticed that we jumped back into the wireframe scene when opening the compositor view. This can easily be corrected by simply selecting the Starry Sky scene from the drop-down. Once you’re there, make sure your sphere is still selected.
You might have also noticed that, when switching scenes, Blender’s renderer changed from “Cycles” to “Blender Render.” Make sure that Blender is using Cycles for this project.
Once we are in the compositor, we need to switch to “material” mode (at this point, our prior work left it in “compositing” mode) To do this, simply click the sphere button at the bottom of the node editor.
Now, for a little physics lesson. Stars are balls of plasma in space. They seem to be white, but they rarely are. They generally run the spectrum from red (coolest) to blue (hottest), passing through yellow on their way. Their distance can affect both the size and brightness of stars, but they’re usually bright enough that their color is a vague tint on what seems to us to be white.
We have a way of using the same material to make different object differently-colored. This means that with one star mesh (which we already created) and one starlight material, we can have a night sky full of uniquely-colored stars.
Before we do that, however, we need to click the “+” above the gradient to add a midpoint.
The reason for this is that we want to have a specific scale for the color: the black side will be a reddish white, the white side will be a bluish white, and the midpoint will be yellowish-white. To change the color of each, simply click on each slider (don’t drag), and select the color using the color box below.
Now, we can test this with the star, but before we get to testing, we need to replace the “Diffuse BSDF” material with “Emission” (Add -> Shader -> Emission). It IS a star, after all.
Once we place the emission node, connect the “ColorRamp” color connector to the “Emission” color connector, and then output “Emission” to the “Surface” connector of the “Material Output” node.
Once the shader has been set up, let’s look at our star. The render view should show the star as a white dot which hints of yellow.At the moment, all stars using this material will use this same shade, so we need to randomize things up a bit. The node editor includes a nifty node called “Object Info,” which includes some the location, and a couple of index values to use. However, the key here is the fourth connector: “Random.”
Every time the node is accessed, the random connector will output a different number. In a moment, you will see why this is important. For now, connect “Random” to both the “Fac” connector of “ColorRamp” and the “Strength” connector of “Emission”.
Creating the Starfield
Now, let’s begin by going back into the default view, switching to camera view, and returning back to layer 1, with the vertex sphere.
To begin, select the vertex sphere. Pay close attention to the line at the top of the 3D view; this will include a count of vertices:
Now, create a particle system for the object, by going to the “Particles” tab of the properties panel, and clicking “+ New”. Go ahead and name the particle system “Starfield” (or whatever you prefer; naming things is the important part).
Particle Emission Settings
Now, remember when I said to note the number of vertices in the vertex sphere? This is where it is important. Under “Emission,” there is a “Number” parameter. Enter the number of vertices in this box; it will create one star for each vertex in the sphere.
Since we don’t want to generate any more stars than there already are vertices, we will need to set “Start” and “End” values under Emissions to 1. This guarantees that, if we’re doing animation, the vertex sphere won’t keep generating new stars in every frame.
The lifetime of the particles should be beyond the last frame of the animation we’ll be doing. So, if you’re doing a 25-frame animation, then you should set the lifetime to 26. If it’s a 250-frame animation, 251. 2500-frame… you get the idea. One more than the maximum number of frames in your animation. If it’s a still image, 2 is just fine.
By default, particles tend to emit from the faces of objects; this is designed to allow particles to be used to generate things like rain, hair, or what-have-you. In this case, however, we want to generate one particle from each vertex, so we want to change “Emit From” from “Faces” to “Verts.”
In the end, the “Emission” section should look like this:
You might have also noticed now that the vertex sphere is showing points of different sizes:
Velocity and Physics Settings
Under Velocity Settings, we want to change normal to 0. This sets the opening velocity of particles; how quickly they move. We don’t want them moving at all; they are to stick with their vertices like glue. This means that once they spawn in the nighttime sky, they stay there, like stars should.
In the end, the velocity settings should look as such:
The same applies to the Physics settings. We don’t want outside forces affecting the stars; the only action they should be performing is moving with the camera. No wind, no gravity, no collissions. This is easy enough to achieve; simply change the “Physics” option to “No”.
To finish off the starfield, we need to make some changes to the render settings. First, and foremost; we didn’t go to all the trouble to make a star object so that halos can be rendered instead, right? So, we need to change the render from “Halo” to “Object”. The “Dupli Object” field should then be set to our “Star” object.
Next, we really want to randomize our stars’ sizes. To do this, we change the Random field (in the render settings) to 1 (full randomness).
Testing the Starfield
Now, render to determine if the starfield fits your intentions. If you don’t like what you see, try rotating the starfield itself around the camera, to see if another angle has a better view.
If everything worked according to plan your starfield should (more or less) look like this:
Adding Twinkles to the Stars
Now, it’s time to switch to the compositor. Once there, select the “Compositing” setting, so we can work on the image in total. Make sure that “Use Nodes” and “Auto Render” are enabled.Sparkles are nothing more than illusions caused by light being slightly refracted through a medium; not enough to separate color, but enough to cause what looks like lines moving away from the source. Sparkles are often used in still images to represent the twinkling of stars, a different illusion caused by the change in brightness in a star due to the movement of air.
For this tutorial, we’ll focus on a still image, so we’ll use sparkles for now.
To make a sparkle, you need two things: a horizontal blur, and a vertical blur. They need to be mixed together without blurring each other.
For now, our compositor should look like this:
First, We need to add a blur node to the project (Add-> Filter -> Blur).
Connect the “Render Layers” node to both blurs, and one of the add nodes. Connect both of the blurs to the same add node. Then connect that add node and the original image to the second add node. Connect the final add node to the Composite node, and it should look something like this:
You might have noticed that each add node can only take in two images. And yet, we have three things to mix: the main picture, and the X and Y blur nodes. The way around this is to use two add nodes and connect one to the other. One add node handles both blurred images, while the second add node handles the original image and the first add node.
So, what does the end result look like?
This is where the node editor comes into its own. What we can do is change the image the blurs are receiving, in order to only get the brightest stars.
To do this, we add a new node to our lineup: The Brightness/Contrast node. To add it, select Add -> Color -> Bright/Contrast.
We’ve got a wireframe, and we’ve got a starfield. The wireframe glows, while the starfield is bright and sparkly. Now, what about combining them? That is the reason we made two scenes in the same file, right?
This is where we introduce the concept of the composite image; an image made from multiple images. Unfortunately, neither Cycles nor Blender Renderer supports using compositor output as input for a new scene. Because of this, we will have to recreate the compositor nodes in the new scene to bring them together. We can, however, import the scenes themselves, and even copy and paste the compositing nodes and connections directly!
Creating a Composite Scene
To make the process easier, we can create a scene solely for the purpose of compositing multiple scenes into one project. We’ll just call this “Composite Scene.” Once we have this new scene, go directly to the compositor.
The process of importing composites across the same file is trivial by comparison to everything else.
Go to the Wireframe scene.
Before we do anything else, we need to make a change to the properties. In the “Film” settings of the “Render” properties, make sure “transparent” is checked. This will guarantee that the wireframe landscape, which is in the foreground, overlays the starfield, while allowing it to show through where there is no geometry. This removes the need for inexact composition tools, by ensuring that the wireframe is the only thing that gets rendered; only the starry sky will provide the background.Now, Enter the node editor. The other thing we need to change is that final “Add” node. We want to combine the core wireframe and the blur over an alpha (transparent) background. As such, we want to replace “Add” with “Alpha Over.” This way, the transparency will still preserve the glow; the add node would cause it to be translucent, washing out the wireframe entirely.
The new Wireframe settings should look like so:
Importing Starry Sky
Do the exact same thing for the Starry Sky; copy and paste the composite nodes with the exception of the Composite Node.
Combining Imported Compositions
Now, if the copying and pasting worked correctly, we should have two sets of nodes in the editor, looking something like this (after some cleanup):
Now, we simply need to remove the default Render Layers node (connected to the Composite Node), and replace it with an “Alpha Over” node. Then, connect the output of the two composite chains to each of the Add node’s inputs. Make sure, while adding the wireframe nodes, that the “Add” node has the alpha button (the strange button next to the “Add” dropdown) pressed. The wireframe scene should be placed in the lower slot, while the scene making up the background should go in the upper slot.
It should look something like this. Note that there was some tweaking to improve the starlight: