2.3 自定义镜头光晕(镜头眩光)效果 Unity
Unity技术Thepoly 15467 0
实名

通过了实名认证的内容创造者

发布于 2022-3-24 17:59:58

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 Thepoly 于 2022-3-24 20:05 编辑

src=http___xqimg.imedao.com_17b70f518351426d3fd73b36.png!800.jpgrefer=http___xqimg.imedao.webp.jpg
174551k9r66ex7z719e99h.jpg
Hello,大家好。
周一到了Kinglary分享
游戏引擎相关内容
2.3 自定义镜头光晕(镜头眩光)效果
2.3 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.
为了进行本节的内容,强烈推荐你使用Photoshop或是GIMP软件。在本章节中,创建的眩光(光晕)贴图资源在0423_02_03文件夹中。(本书的下载内容,可以忽略,不影响学习)。
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.
1.通过点击 Assets | Import Package | Character Controller(角色控制器),将Character Controller package导入进来。

2.Do the same for the Light Flares package.Using Cameras 36.
2.进行同样的操作,将Light Flares package导入进来,使用Cameras 36。

3.In the Hierarchy view, use the Create button to add a Directional Light effect to your scene.
3.在Hierarchy面板中,使用创建按钮,添加一个Directional Light(平行光源)效果在你的场景中。

4.Select your camera and add a Mouse Look component by accessing the Component | Camera Control | Mouse Look menu option.
4.选中你的摄像机,通过点击Component | Camera Control | Mouse Look添加一个Mouse Look。

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:
5.在Project面板里,找到Sun光晕(在Standard Assets | Light Flares文件夹下),将其复制并重命名为“MySun”,如截屏所示:
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.
6.在Inspector面板中,点击 Flare Texture,就会在Project面板区域展示出基本贴图的位置,有一张贴图应该叫做 50mmflare。

7.Duplicate the texture and rename it My50mmflare.
7.复制该贴图,并将其重命名为My50mmflare,流程如下图所示:
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:
8.右键点击 My50mmflare并选择打开,在你的图像编辑器中应该是打开了一个PSD文件。如果你用的是Photoshop,你应该看到了图片上的辅助线,如下图所示:
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.
9.为了创建一个光圈(light rings),你可以在PS中创建一圆环形状,之后叠加图层特效,比如说渐变叠加(Gradient Overlay)、描边(Stroke)、内发光(Inner Glow)和外发光(Outer Glow)。

10.Recreate the star-shaped flares by editing the originals or by drawing lines and blurring them.
10.利用本地软件(就是PS),通过画线或模糊,重新创建一个星形光晕(如下图):
11.Save the file and go back to the Unity Editor.
11.保存文件,返回到unity编辑器中。

12.In the Inspector view, select MySun, and set Flare Texture to My50mmflare:
12.在Inspector面板里,选择MySun,设置Flare Texture(光晕贴图)为My50mmflare(如下图):
13.Select Directional Light and, in the Inspector view, set Flare to MySun.
13.在Inspector面板中,选择平行光源,然后设置Flare参数为“MySun”。如下图所示:
14.Play the scene and move your mouse around. You will be able to see the lens flare as the camera faces the light.
14.运行场景、四周移动你的鼠标。你应该能看到精油眩光,就像用摄像机正对光源一般。
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.
我们已经运用自己的贴图蓝本在unity中制作了一个镜头眩光。制作完成时,镜头眩光贴图会在玩家看起来大约在光源方向时展现出来。
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/Document ... lass-LensFlare.html
镜头眩光可以针对每一个元素应用不同设计和参数,如果你想学习更多镜头眩光的效果,请打开unity官方文档,网址如上。

节后
根据译者的制作demo经验,其实镜头眩光是一种摄像机视觉特效,往往在一些光影变化极强的打斗场面或是一些具有一定指向意义的游戏动画中应用。尤其是后者,可以赋予更深的镜头艺术语言。在Cryengine中,镜头眩光直接利用模拟物理光源的形式,给予开发者直接调节光学参数就可以添加镜头眩光的效果;尤其是在unity5和unity2017中,大大强化了light和camera组件的功能。当然,镜头眩光对于整个游戏画面而言是一个点缀,莫要在实际操作中添加过多、喧宾夺主。

本帖被以下画板推荐:

还没有设置签名!您可以在此展示你的链接,或者个人主页!
使用道具 <
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表