- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
 
- 纳金币
- -1
- 精华
- 11
|
Light beams are only visible if part of the light is scattered by objects: tiny particles like dust, water droplets (mist, fog, rain)… In games this implementation used for tense or dusty environment. Here an example from Need for Speed Hot Pursuit 2010;
Click to image for bigger size
I’m going to show to you how can create light beams for your game. You can improve your game graphics with simple 2d sprite and a script.
First of all, you need some ptoho editing tool. I’ll use photoshop for this tutorial.
Beam Texture Creation
1.First, create a empty Photoshop document with transparent background sized 400×500. Then paint current layer with some dark color. I used dark gray.
2.Then create three guides for your lightbeam start point. I’ll use this for spot light so i make start point very narrow.
3.And create a triangle with lasso tool. This will be our beam.
4.Selected gradient tool and select “Foreground to Transparent” preset from presets window.
5.Be sure your foreground color is white. Draw graident from top to bottom of selection.
6.And now drop opacity value from layer window to 15
7.Remove the black layer and save as transparent png to unity folder.
And we’ve a beam texture. Now its time to create asset and materials.
Asset Creation in Unity
1.Create a game object this will our Beam Container and name it “LightBeam”.
2.Create a plane name it “BeamPlane” Rotate this plane at x to 90 degrees. This will be our beam object. You can scale this plane as suitable for your beam area.
3.Remove the mesh collider, we don’t want stuck object to beam. Also remove checks from Cast Shadows and Receive Shadows properties under Mesh Renderer
4.Drag the “BeamPlane” plane to “LightBeam” object. This make plane child of LightBeam object.
5.Import that png file unity.
6.Create a material with Particles/Addictive shader. Drag this imported texture to “Particle Texture” channel. If you want more transparency with beam you can darken the Tint Color.
7.Assign this texture to previously created plane.
8.Align the “LightBeam” object to your light source.
There you go, your light have beam.
Its not finished yet. If you move the camera you’ll see this beam will stand still. For realistic view, we’ve to face it to camera always.
To achieve that;
Create a new c# file named LookAtCameraYonly.cs and copy this codes in to ;
using UnityEngine;
using System.Collections;
public class LookAtCameraYonly : MonoBehaviour
{
public Camera cameraToLookAt;
void Update()
{
Vector3 v = cameraToLookAt.transform.position - transform.position;
v.x = v.z = 0.0f;
transform.LookAt(cameraToLookAt.transform.position - v);
}
}
Drag and drop new created script to “LightBeam” gameobject.
We need to assign main camera to “Camera To Look At” propery of this script. So drag main camera and drop it to propertybox.
Now when you walk around, beam object turn to camera and it will look better.
Check out the result. I used Urban Props from asset store. (http://u3d.as/content/bi-ski-t/urban-props/1Rf)
You can move around using with arrow keys.
I hope you find the article useful.
|
|