Enhancing sunrays using lens flares

A lens flare is a distraction in an image caused by stray light in the camera lens. There are two kinds of lens flares. One is directional, based on a cone (much the same as is used by a spotlight) and the other is radial (standard). Flares are a modified version of a particle, and have an editor much like Cascade, and their elements are made through the Material Editor. If you have been thorough with the chapters so far, you'll be kind of familiar with a lot of the steps required. The order of ceremonies is outlined in the UDN page: http://udn.epicgames.com/Three/LensFlareEditorUserGuide.html. In this recipe we are going to construct a lens flare from scratch to place in an existing lit scene.

Getting ready

From the provided content, open Packt_08_LensFlare_Start.UDK and note the big sun sphere hanging under the Skydome. Our lens flare effect will serve to complement it.

How to do it...

  1. In the Content Browser, in your folder, right-click and choose New LensFlare. Name the asset Yourfolder.LensFlare.Test_LensFlare. The Unreal LensFlare Editor will open. The key idea to grasp is that each element the user adds to the lens flare has a distance value based on an offset from a Source element. A lens flare can include different 'shapes' spread at varying apparent distances.
    How to do it...
  2. Search in the Content Browser for PacktFX.Texture.Packt_FlareShape_A. Highlight it, right-click, and choose Find Package. You'll find five flare shape textures (plus a few others used for DOF that would also work fine). They have a black backdrop and a radial pattern. These were generated quickly in Photoshop using Gradients and the Shape tool and some blurring filters.
    How to do it...
  3. Highlight these, right-click and choose Properties. In the properties dialog, expand Texture2D and choose Clamp instead of the default Wrap. This will allow us to rotate the texture without the corners suffering any overlap problems.
  4. Create Materials for the textures. You can select them all, then right-click and choose Create New Material and UDK will generate the Texture Samples for you. Hook the Texture Sample to the Emissive and Opacity channels. Then set the Material Blend Type to BLEND_Translucent, set it to be Two sided and use the Lighting Model | MLM_Unlit.
  5. If you want to, add a Coordinate | Rotator node to the UV inputs for each Material's Texture Sample. Set a rotation speed to 0.05. This gives the lens flares a spin. This is not a realistic feature of a lens flare, but does look interesting.
  6. For the Materials that will be used with a lens flare, in the PreviewMaterial properties the Usage | Used With Lens Flare property should be ticked on.
  7. Double-click your LensFlare asset, and in the Source element set the LFMaterials entry to PacktFX.Material.Demo_FlareShape_F_mat. Right-click on the element and choose Add Element After. Here, set the Element Name to A, and set the LFMaterials entry to use the Material you made driven by the texture Packt_FlareShape_A, and continue to repeat the pattern to add more elements, as shown next. The order is unimportant in this example.
    How to do it...
  8. The distance given to each element determines the spreading out of the shapes. It should increment automatically if you use the Normalize Radial Distance in each element's properties.
  9. Excluding the Source Element, newly added elements are all created with a Size | XYZ of 0.2 by 0.2. Change this so no two elements are the same, within a range of 0.1 to 1. The Source Element default size is 75x75x75. It can be used as a sun. You can also effect the size using a Scaling | Distribution | Constant, and, if you want the LensFlare to be, for instance, a stretched oval rather than round, you can use the Axis Scale parameter. A very important thing to note is that if bNormalizeRadialDistance is enabled, 1.0 will represent the camera distance from the source to the edge of the screen. Using this, you want to use small numbers indeed, such as: A= 0.01, D=0.1, C=0.2, F=0.66, E=0.75, B=0.95.
  10. Further down, you'll see an Alpha | Distribution | Constant that will allow you to fade the Material for each element. The Color | Distribution | Constant | XYZ lets you tint each shape in the regular XYZ = RGB style.
  11. For now, let's go with the way things are, having set the distances and some size variation. We need to set the LensFlare asset in the scene to further tweak it. Press the Save Thumbnail Image icon [ How to do it... ], close the LensFlare Editor, and save your package, or use the prepared asset PacktFX.LensFlare.Sun_LF instead.
  12. With the asset highlighted in the Content Browser, right-click in the scene and choose Add LensFlare: Sun_LF (or use yours).
  13. You may notice that light shafts affect the lens flare actor, but this is only the icon being affected. If you observe this, press G to toggle game mode and check out the difference. The LensFlare actor displays as a particle Emitter.
  14. Place the LensFlare actor right up by the sun sphere that we added earlier, just beneath it. You can see the lens flare affect the editor by pressing the toggle for Real Time playback [ How to do it... ] Ctrl + R. Now you will be able to adjust the relative distances, sizes, and opacity of the lens flare elements back in the LensFlare editor.
  15. The values of the Emissive component in the flare Materials can also be altered to taste.
    How to do it...

    Here we set B_OPACITY as a parameter. Next, we drive B_OPACITY in the lens flare.

    How to do it...
  16. As shown here, some features of the element can be driven by animatable vector parameters. Supposing you add vectors to the flare Materials, within the bottom properties of each LF Element you can see parameters that are prefixed "Dist Map". These are Dist Map Scale, DistMap Color, and Dist Map Alpha. These can map to values in the Material depending on their distance and the camera distance from the LF Source.
  17. As a demonstration, open the Lens Flare Editor Property Wrapper for LF ElementB, expand the Dist Map Alpha property, and right-click on the Distribution channel's blue triangle [ How to do it... ] which sets the type of distribution it will use. Choose from the list, DistributionFloatParticleParameter. This has a parameter name field where you can type B_Opacity, which is also assigned in the parent Material of the Material Instance Constant: PacktFX.Material.Demo_FlareShape_B_Mat_INST, which you can assign to this element (under Element | LFMaterials | [0]). Open the Parent Material and inspect the Opacity channel, which is set to Multiply the Texture Sample with a Constant converted to a Parameter.
    How to do it...

See also

If you are not sure how Named Parameters work in UDK, look up the Material Instance Constants recipe in Chapter 9, The Devil Is In the Details!

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

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