Customizing the lens flare effect

As anyone who has played a game set in an outdoor environment in the last 15 years can tell you, the lens flare effect is used to simulate the incidence of bright lights over the player's field of view. Although it has become a bit overused, it is still very much present in all kinds of games. In this recipe, we will create and test our own lens flare texture.

Getting ready

In order to continue with this recipe, it's strongly recommended that you have access to image editor software such as Adobe Photoshop or GIMP. The source for lens texture created in this recipe can be found in the 0423_02_03 folder.

How to do it...

To create a new lens flare texture and apply it to the scene, follow these steps:

  1. Import Unity's Character Controller package by navigating to Assets | Import Package | Character Controller.
  2. Do the same for the Light Flares package.
  3. In the Hierarchy view, use the Create button to add a Directional Light effect to your scene.
  4. Select your camera and add a Mouse Look component by accessing the Component | Camera Control | Mouse Look menu option.
  5. In the Project view, locate the Sun flare (inside Standard Assets | Light Flares), duplicate it and rename it to MySun, as shown in the following screenshot:
    How to do it...
  6. In the Inspector view, click Flare Texture to reveal the base texture's location in the Project view. It should be a texture named 50mmflare.
  7. Duplicate the texture and rename it My50mmflare.
    How to do it...
  8. Right-click My50mmflare and choose Open. This should open the file (actually a .psd) in your image editor. If you're using Adobe Photoshop, you might see the guidelines for the texture, as shown here:
    How to do it...
  9. To create the light rings, create new Circle shapes and add different Layer Effects such as Gradient Overlay, Stroke, Inner Glow, and Outer Glow.
  10. Recreate the star-shaped flares by editing the originals or by drawing lines and blurring them.
    How to do it...
  11. Save the file and go back to the Unity Editor.
  12. In the Inspector view, select MySun, and set Flare Texture to My50mmflare:
    How to do it...
  13. Select Directional Light and, in the Inspector view, set Flare to MySun.
    How to do it...
  14. Play the scene and move your mouse around. You will be able to see the lens flare as the camera faces the light.

How it works...

We have used Unity's built-in lens flare texture as a blueprint for our own. Once applied, the lens flare texture will be displayed when the player looks into the approximate direction of the light.

There's more...

Flare textures can use different layouts and parameters for each element. In case you want to learn more about the Lens Flare effect, check out Unity's documentation at http://docs.unity3d.com/Documentation/Components/class-LensFlare.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.244.250