Unity 5: Making the Most of Updating (Lighting and Shaders)
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.
(x-posted from ifdogthen)
Psydra Games recently released a video of our Unity 5 upgrade for our current game, code-named (read: probably-forever-named) MikeDies. We found the difference to be staggering. Between Unity 5's Personal Edition removing all of the limitations of previous free versions and the new Standard shader and lighting, our visuals have been boosted by several orders of magnitude.
And although the upgrade was really fast, and went quite smoothly, it wasn't automatic. Because Unity 5 kept support for legacy shaders and light settings, booting up into Unity 5 for the first time had the game looking just as it did before (though with a much-welcomed performance improvement). That might be an underwhelming moment for some indie developers, but fear not, it only takes a few moments to see an incredible difference, and here's how we did it.
Using the Standard Shader
Unity's new Standard Shader is meant to handle most of the materials you'll need, and it certainly lives up to that for us. Just setting everything to this shader will be a significant upgrade in your visuals - assuming you are going for something remotely realistic, rendering-wise. But setting all of those shaders can quickly get tedious. That's where editor scripting comes to save the day. Just add this script to your Editor folder (create it if you don't already have one).
You can also use a batch processing script like this for any other properties you want your objects to have, and we will use this technique again later.
If you want an object to have its own glow without the use of a light, crank up the Emission property inside of the Standard shader options. You can assign a color to it as well. Here is the before and after of our Unstable Energy beams, with simply adding a red emission property to it.
Along with obvious improvements to the background visuals (just by using the Standard shader), the emission property can really make elements stand out without having to add special lighting for that object. Aside from our crazy laser-beam-like energy here, it can also be great for simple things like light bulbs.
A lot of our lights were Point Lights, which can work well for lighting an area from an unseen source, but when you have a physical object representing a light, you want some realistic shadowing from that light. And you probably want it to be somewhat directional. I changed several lights from Point Lights to Spot Lights, as seen below. The Emission property is also present on the light tube itself.
This made the next part all the more necessary.
If you were using the free version of Unity 4, none of your objects were able to cast shadows. Now that they are, you have another big job ahead of your for setting your objects to cast and receive shadows. But once again, we can script that.
Like before, you may want to add some logic to your script if you don't want all of your objects to have the exact same settings, but this works as a template, and you can select only particular objects or everything in your scene. However, the objects themselves are only part of the equation: you also need to make sure the lights themselves cast shadows. You can script this in the same way by grabbing the Light component, or use Unity's handy Lighting panel.
The Lighting panel can change the properties on one light or all of your lights simultaneously. You can also change your ambient light and GI settings, and build your lightmaps. Your hierarchy will automatically be filtered based on the "Scene Filter" in this panel, making it easy to change the settings on multiple lights at once. You can also change lightmap settings on your meshes here.
This is just a peek at the updates we're bringing to our game, and we've only scratched the surface of what we can do with the new power available in Unity 5. I'll be updating with any new discoveries, but in the meantime, you can find me on Twitter @ifdogthen, or the same username on GMail for more personal/thorough questions/feedback. You can find more updates on the game from the rest of the team @PsydraGames.