Blender Tutorial #4
'Baking Stars for VR'
For this tutorial, I assume you will be familiar with the Blender layout of its menus and functionalities. If not, please have a look at the other tutorials on this Wiki. In this tutorial, we will simulate a bunch of stars and bake a 360 degree video that you can look at on your phone using a simple HMD such as Google Cardboard. To begin, start a new project, delete the standard Cube object and the Lamp object. Then, switch to the Cycles Render environment before doing anything else. When you've switched, click on the Scene tab in the inspector and uncheck Gravity. Switch to the World tab and under Surface press Use Nodes and set Strength to 0. This will effectively reduce any light in the scene, with exception of our stars, to absolute black; no gravity and all black: starts to sound like deep space already!
Make a star
For our stars we will model a Sphere object, but we do not want this one object to be visible throughout the video. Therefore we will place this Sphere object on a different layer and reference the object, but not do anything else with that layer; these layers are effectively not connected. Click on a new layer in the panel below and add a new Ico Sphere (SHIFT + M + I). With your new Sphere selected, go into its Material properties tab in the inspector and make a new material for your Sphere. Name this new material Star and under Surface click Use Nodes; this will expand with a new surface, set standard to Diffuse BSDF. Change this to Emission and then click on the color-picker; pull the slider on the right all the way up to white. We're done with this part, so switch back to your initial layer.
While you're down here, see the Start: 1 and End: 250 on the Animation toolbar? Change Start to 500 and End to 1000; also, see the empty box on the right? Change that to 500; you'll see in a minute why we're changing these values.
Make many stars
We have made one star and now we can use that star in conjunction with a Particle system to make it simulate many stars. Make a new Plane object (SHIFT + A > M > P). With your 3D cursor at the center, the Plane should be at 0, 0, 0. Put the Plane object upright by 90 degrees on the X-axis (R > X > 90); scale the Plane object by 800% (S > 8) and place it towards the furthest side on the Y-axis (G > Y > 8).
Select your Plane object and look for the Particles tab in the inspector. Add a new Particles system to your Plane object by clicking New. Under the Emission dropdown change Lifetime and End both to 1000. Scroll down and expand the Cache dropdown menu and press the Bake button; just above, it should now say '1000 frames in memory (xx.x Mb)'. This is good because it has now pre-baked the particle system. If you press ALT + A, the pre-baked animation will play back and you can see your first stars moving. However, we are not yet done modifying the Particle system. Scroll down further on the Particles tab until your reach the Render dropdown; it is currently set to Halo, which you will need to set to Object; notice how underneath a new field appeared, marked Dupli Object? Click on that and select your Isosphere object. The Particle system will now use the Isosphere to model the particles accordingly; next, change the Size to 0.02 and we don't want our stars to make too much light and reveal our setup, so uncheck the Emitter box.
From mono to stereo
Now that we have our stars and space set up, select the Camera object and reset its Location to 0, -3, 0 and its Rotation to 90, 0, 0; since we won't be exporting the Object itself, there is no need to apply the changes. You can now preview the scene through the Camera object by pressing 0/insert and pressing ALT+A; presto! Stars in heaven! Last thing to do is to set up our camera to export in the right format. For this tutorial, since iPhone is a pain to upload videos to, I used YouTube instead. You can export the animation in a 360 degree video format that YouTube understands, and then use your YouTube app on your iPhone to experience the stars in VR on your Phone!
Select your Camera object and under the Render Layers tab find the Views dropdown menu and check it; make sure Stereo 3D is now active and you should see a little rectangle in front of your Camera object. Then, switch to the Data tab (shaped like a little movie camera), under the Lens dropdown, select Panoramic and change its Type to Equirectangular. Further down there should be Stereoscopy dropdown; change the Convergence Plane Distance to about 5 and check the Spherical Stereo button. Then, click on the Render tab (shaped like a little photo camera), and under Render make sure the Device is set to GPU Compute; if this is not an option on your computer, the actual baking (see below) might take quite a bit longer.
Finally, scroll down to the Output tab and set the output folder and file; click the little folder icon, which will open a separate window where you can save your file; path name goes in the top field, filename (without extension) in the bottom field. Once done, Accept and click on PNG; change it to FFmpeg video from the popup menu; also change Views Format from Individual to Stereo 3D; change Stereo Mode from Anaglyph to Top-Bottom and expand the Encoding dropdown. Change the Container to Quicktime and everything should be set!
Baking, and baking, and baking, and...
Ok, technically, Blender will not bake this scene; instead, it will model the object movements and raytrace the entire scene frame by frame and combine all these frames into a little animated movie. Remember that we changed the Start and End positions of our animation? This was to make sure that the animation would start mid-way; otherwise you would see the beginning of the animation, i.e. stars approaching; now the animation will start with the user being submerged in them.
One final consideration before you can go on a holiday and leave your computer to think for a while is the quality of animation you would like. Under the Dimensions tab the Resolution setting will allow you to control that. It is set to 50% by default, but this is not particularly high quality overall. Changing that to 200% will effectively render a 4K movie for you. However, the tradeoff is that it might take you a good day to render a 500 frame animation @ 24fps, which equals to slightly more than 20 seconds; a whole day for 20 seconds though mindblowing quality?
Up to you what settings to use for resolution and this will fully depend on your system specs. In any case, when you've decided on the output resolution, go over to the Render dropdown and press the big Animation button; Blender will now start its raytracing.
Bringing the Stars to YouTube
Last stretch: getting that animation up to YouTube! You will need a small third-party tool known as the Spatial Media Metadata Injector to prepare your video for YouTube. You can download the tool here, for either Mac or Windows. Once you've unpacked the tool and started it up, you'll need to press the Open button and select your video. It should detect and mark your video as spherical; make sure you check 'My video has stereoscopic 3D (top/bottom layout)' and then press Inject metadata. The program will ask you to save the file, and make sure you save the file with the extension .mov. Once done, you're good to go! Send that puppy up to YouTube and amaze the world with your stars!