unity 旋转角度5 平行光角度可以广大吗

努力加载中,稍等...
暂无新消息
努力加载中,稍等...
已无更多消息...
这些人最近关注了你
努力加载中,稍等...
已无更多消息
努力加载中,稍等...
已无更多消息
& Unity 5:光照系统
Lighting in Unity 5
征集热心朋友翻译文章,奖励规则:每100汉字奖励10QB,30天内互动奖励0 - 50QB.
翻译请求:介绍在unity 5中使用lighting功能以及注意事项
该文章来自用户转载
What You'll Be CreatingUnity has become more and more popular among aspiring game programmers. This is due to the fact that Unity directly supports a multitude of platforms such as mobile, desktop, and console environments. Moreover, it is free to use for lower revenue developers or studios.Unity supports several technologies and components. Some of the key components are the lighting and illumination techniques. In Unity you can illuminate a scene by simulating the complex behaviour of lights or by applying a simple lighting model.This tutorial will focus on explaining how lighting works in Unity 5, the lighting types and properties, and how to use them to create rich illumination effects.PrerequisitesFirst, ensure you have the . In this tutorial we're using version 5.5.0f3. Make sure that you are using the latest U otherwise you may have problems following the tutorial and using the physics joints.Next, download the LightingInUnity5-Starter file. Unzip and open the project in Unity. The Demo scene should open automatically, but if not, you can open it from the Assets folder.Direct and Indirect LightingIn a real-world scenario, you have two types of lighting effects: direct and indirect lighting. Direct lighting, as the name suggests, is light that comes directly from a light source (a lamp, the sun, or other). On the other hand, indirect lighting is light that comes from another object.Let us test and implement both of them.Direct lighting can already be seen in action in your Scene. As you probably noticed, you have a directional light in the scene called Directional Light.Directional lights are mostly used in outdoor scenes for sun and moonlight. They affect all the surfaces of the objects in the scene. They are also the least expensive to the graphics processor.You can select the Directional Light and view its properties in the Inspector pane. You will notice several interesting properties such as Type, Color, and Intensity. You can play with the Color and the Rotationproperties and see the result in real time. By changing those values, you are directly playing with directional light.At this moment, your 3D scene does not have any indirect light. You can check that by moving the Spherecloser to the green or red wall. The Sphere color will not change.One way to use indirect lighting is to use static GameObjects. Keep in mind that the use of static game objects can improve the performance of your game rendering, but will also reduce the quality, so you must find the right balance for your game.Add a box mesh box into your scene (GameObject & 3D Object & Cube), and place it next to the sphere. Name it Cube.Select the Cube, and inside the Inspector enable the Static property.When you enable the Static property, Unity automatically creates a light map for that object and applies the correct illumination model. You can now move the camera towards the Cube and see the indirect lighting working. The green (in the image) or the red color is now spreading into the Cube.If you change the direction of the Directional Light, you will notice that Unity automatically updates the light maps as well.The indirect lighting that is being applied to the Cube is not applied to the Sphere because the Sphere is not static. You can solve this by making the Sphere static (Inspector & Static).At this moment, you can add and configure direct and indirect lighting to static objects. However, 3D scenes are composed of dynamic objects. Therefore, how can we apply such effects to those objects? That question leads us to the next section.Light ProbesWhen your scene contains non-static objects, you need to use specific lighting techniques to correctly illuminate them so that they don't look disconnected from the scene.Through the use of light probes and their positions, you can sample strategic points in the scene. Each light probe can sample a specific region and then calculate the lighting in that specific region. These calculations are fast enough to be used during gameplay. The use of light probes avoids any disconnect between the lighting of moving objects and static light-mapped objects in the scene.The Sphere is a dynamic object, therefore, and contrary to what it may seem, it is not correctly illuminated. If you turn the Directional Light off, you will notice that the only lighting affecting the Sphere is the ambient light. To correctly illuminate the Sphere, you need to use light probes.To add light probes to an area of your scene, you go to Component & Rendering & Light Probe Group. This will create a light probe group in your scene.The next step is to put the probes of the group in the correct position. You now want to place them near each corner of the Box.The best way to do this is to change to an orthographic view (by clicking on the cube on the upper right corner of the scene). Then, select each light probe node and drag it into each Box corner (similar to the next image).Repeat the process until you have positioned all nodes.There are scenes that require additional probes to correctly illuminate objects. In order to add more probes, you can select one probe and then under the Inspector, click on the Duplicate Selected button.After the duplication, you need to place the new node in the right place (the duplicated one will spawn in the same position as the selected one).If you take a closer look at the interface in the Inspector, you will notice that you can also add individual probes (Add Probe), delete probes (Delete Selected), or select all the probes from the group (Select All).To see the light probes in action, select the Sphere and add a Rigidbody to it (Add Component & Rigidbody). Then, assign a material to the collider. You can use the rubber material.Now, place the Sphere near the top of the Box and press Play. You can now see the proper illumination of the Sphere. To see the differences, disable the light probes and Play the scene again.Point LightPoint lights are the most common light in games. They're usually used for explosions and light bulbs. Since they emit light in all directions, they have an average cost on the graphics processor. However, calculating shadows when using point lights is more expensive.Add a point light by selecting GameObject & Light & Point Light. Next, position the Point light inside the Boxnear the top.Select the Point light and take a look at the parameters in the Inspector.The first parameter is Type. Here you can set the type of light you want to use. You can either select Spot,Directional, Point, or Area. Each provides a specific light effect. You can select any of the options and see the results in real time. However, for this tutorial you will use the Point option. This will create a light bulb effect (light shines in all directions equally).The second parameter is Baking. You can set it to Realtime, Baked, or Mixed. Leave the value as default. The Range parameter defines how far the light is emitted from the center of the Point light. The Colorparameter defines the emitted light color.Intensity defines the brightness of the light, and Bounce Intensity defines the indirect light intensity multiplier. The Shadow Type defines the shadow properties and shadow types. You can either set it to No Shadows, Hard Shadows, or Soft Shadows. Remember that point light shadows are the most expensive for the engine, so be careful when selecting this option.If you select Hard Shadows or Soft Shadows, you will see the shadow produced by the Sphere and thePoint light. When you change the Strength value, the shadow will also attenuate or accentuate. TheResolution lets you define the detail level of the shadows. Finally, Bias and Normal Bias let you configure the offset used when comparing the pixel position in light space with the value from the shadow map.The Cookie is an optional parameter that represents an alpha channel of a texture used as a mask that determines how bright the light is in different positions. Since this is a point light, the texture used must be a Cubemap.The Draw Halo option only renders a halo around the light source. Flare defines a reference to a flare to be rendered at the light's position. Flare and Draw Halo can be useful when debugging the 3D scene and possible bottlenecks.Render Mode defines how important lighting is when the renderer is rendering the scene. The more important, the more intensive the rendering will be. The Render Mode can be set to Auto, Important, or Non-Important. Finally, Culling Mask is used to select or exclude groups of objects that are affected by the point light.Now that you've seen all the point light properties, let's talk about direct and indirect lighting when using point lights. When you create a game, one of the main characteristics is the use of lighting and illumination effects. However, a heavy lighting scenario will lead to heavier loading times, FPS bottlenecks, and more work for the CPU. Therefore, you are advised to play with Shadows Type and Baking properties to balance your scene performance.For example, if you set the Baking to Realtime and the Shadow Type to Hard Shadows or Soft Shadows, you will have a very nice, realistic shadow effect between the Sphere and the Box. However, this setup can be heavy for the CPU if your scene is composed of many lights.How to solve that issue? You can initially set the Baking parameter to Bake. Once you do this, Unity will automatically create lightmaps for this light, giving you a performance boost. However, this performance boost has its cost: now you don’t have shadows being cast by the point light into dynamic objects, like theSphere.The best practice is to analyze each light individually, and then proceed accordingly. For example, in this scene it would make more sense to have Realtime Baking and Hard Shadows, because only one light source is present inside the box. However, if your light source is a torch in a wall, it would be better to set Baking to Bake and let Unity produce the lightmaps.Recall that it is up to the developer to manage the quality and performance of the game. Therefore, keep in mind that you have to be careful in keeping that balance, especially if you are developing for mobile devices.Spot LightSpot lights emit light from a light source targeting a specific region. They only illuminate objects within a specific region, a region delimited by a 3D cone. Basically, they work like the headlights of a car. As you may imagine, they are perfect for flashlights, car headlights, or lamp posts. They are also the most expensive light type for the graphics processor.Let us now change the Point light into a spot light. Select the Point light you created earlier and change itsType to Spot. Next, Rotate the light so that it can illuminate the floor of the Box. Rename it to Spot light.As you may have noticed, inside the Inspector, the Spot parameters are similar to the Point ones. However, you have a new one called Spot Angle.The Spot Angle determines the angle of the light cone in degrees.Regarding direct and indirect lighting, spot lights work exactly like point lights. You have the same limitations and advantages. Therefore, you have to be careful when setting up the balance of lights in your game.Note that you can always play with shadows and baking in order to balance looks and performance.Area LightAn area light is light is emitted in all directions on one side of a rectangular area of a plane. This rectangle is defined in both Width and Height properties. The area lights are only available during light map baking, which means that they have no effect on objects at runtime.Select the Spot light and change its Type to Area and its name to Area light. Next, position the light inside your box, and in the Inspector, change the Width and the Height, in order to cover the whole area inside theBox.By looking at the Area light parameters, you'll notice that most of the parameters are similar to the previous ones, for example Type, Draw Halo, Flare, Render Mode, and Culling Mask. The real new parameters are the Width and Height. Both are used to set the size of the rectangular light area.If you press Play, you will see that the area light is casting its light on all objects within its range. The size of the rectangle is determined by the Width and Height properties. The side on which light is being cast is the plane’s normal, which is the same as the light’s positive Z direction. The light is emitted from the whole surface of the rectangle. Because of this, shading and shadows from the affected object tend to be much softer than with point or directional light sources.The lighting calculations for an area light are quite processor-intensive, so they are not available at runtime and can only be Baked into light maps.ConclusionsThis concludes the tutorial about lighting in Unity 5. You learned about several lighting effects and configurations. With this knowledge, you can now apply several lighting effects to your game or application.Unity has an active economy. There are many other products that help you build out your project. The nature of the platform also makes it a great option from which you can better your skills. Whatever the case, you can see everything we have available .If you have further questions or comments, as always, feel free to drop a line in the comments section.
Unity 5:光照系统
版权所有,禁止匿名转载;禁止商业使用;禁止个人使用。
翻译:龚斌涛(建筑学概论)审核:龚斌涛(建筑学概论)Unity在一些有理想的游戏开发者当中变得越来越流行。这应该归功于Unity对多平台(像手机、台式机以及主机环境等)的直接支持。此外,对于低收入开发者和工作室来说,它还可以免费使用。Unity支持多种技术及组件,其中一些关键组件就是光照和照明技术。在Unity中,你可以通过模拟灯光的复杂行为或者使用一个简单的光照模型来照亮一个场景。这篇教程将会着重解释Unity 5中光照系统的工作原理,光照类型和特性,以及如何使用它们来创造丰富的光照效果。预备工作首先,确保你使用的是最新一版的Unity。在这篇教程中,我们使用的Unity版本号是5.5.0f3。请确保你正在用的是最新版本的Unity,否则在接下来的教程中以及在物理连接的使用上有可能会遇到问题。下一步,请下载LightingInUnity5-Starter文件。解压并在Unity中打开该项目。示例场景应该能够自动打开,如果还是不行的话,你可以从Assets文件夹中打开它。直接光源和间接光源在真实场景中,一般存在两种类型的光照效果:直接光源和间接光源。直接光源,顾名思义,就是光直接来自于一个光源(灯、太阳或其他)。而间接光源是指光来自于另一个物体。现在就让我们来测试并且实现这两种效果。在你的Scene中,已经可以看到直接光源在工作了。也许你有注意到,在这场景中已经存在一个方向光,我们称之为Directional Light(方向光源)。方向光源大部分在有太阳光或者月光的室外场景中使用。它们会影响到场景中所有物体的表面。与此同时,它们对于图形处理器来说,消耗最低。选择Directional Light项,在Inspector面板中查看它的属性。你会注意到几个有意思的属性(例如Type、Color和Intensity)。你可以尝试修改一下Color和Rotation属性的内容,实时观察修改之后的效果。通过修改那些属性数值,就可以直观地调整方向光。此时,你的3D场景还没有任何的间接光源。你可以通过移动Sphere球体,使其不断靠近绿色墙或者红色墙,来进行查看。你会发现Sphere的颜色将不会发生变化。间接光源的使用范围之一是将其应用在静态游戏物体中。请记住,静态游戏物体的使用能够提升你的游戏渲染的性能,但同时也会降低其表现品质,所以你必须为你的游戏找到一个合适的平衡点。添加一个盒状物体,并设置Mesh参数为box(GameObject& 3D Object & Cube),并将它放置在球体旁边,命名为Cube。选中该Cube,并在Inspector面板中勾选中Static属性。当你勾选了Static属性后,Unity会自动为这个物体创建一个光照贴图,并且使用合适的光照模型。现在你可以朝这个Cube去移动摄像机,观察间接光源是怎么工作的。你会看到,绿色(下图中)或红色正在不断地扩散到这个Cube上。如果你改变Directional Light的方向,就会看到Unity也在自动地更新光照贴图。在Cube上使用的间接光源并不会作用到Sphere上,因为Sphere不是静态的。你可以通过设置该Sphere为静态来实现同样的效果(Inspector & Static)。现在,你就可以对静态物体进行添加和配置直接光源和间接光源了。然而,3D场景是由许多动态物体所构成的。那么,我们如何对这些动态物体使用这些效果?在下一章节中,就会来解决这个问题。灯光探测器当你的场景中包含非静态物体时,你就需要使用特殊的光照技术来正确地照亮它们,以便让它们看上去没有脱离整个场景。通过对灯光探测器的使用以及它们位置的摆放,你可以对场景中一些有意义的点上进行采样。每个灯光探测器可以对所在的特定区域进行采样,然后计算那一特定区域的光照信息。这部分运算速度很快,因而可以在游戏运行期间进行使用。灯光探测器的使用避免了场景中动态物体的光照与静态光照贴图物体之间的断连。Sphere是一个动态物体,因此,和它预想可能看到的情况相反,它没有被正确地照亮。假如你关掉Directional Light——你将会注意到影响该Sphere的唯一光照是环境光。为了正确地照亮Sphere,你就需要使用灯光探测器。要实现在你场景中的一个区域中添加灯光探测器,执行以下操作Component & Rendering & Light Probe Group。这样就在场景中创建了一个灯光探测器群组。下一步就是将这个群组中的灯光探测器放置到正确的位置上。你现在可以将它们摆放到靠近Box每个角的位置上。做这件事情最好的方式就是将视角切换到orthographic正交视角(点击该Cube下场景右上角处)。然后,选中每个灯光探测器节点,并将它拖拽到每个Box拐角处(类似于下面这幅图)。重复这个过程,直到你将所有的探头节点都摆放到正确位置。有些场景需要额外的探测器来正确地照亮物体。为了添加更多的探测器,你可以选中一个探测器,然后在Inspector面板下,点击Duplicate Selected(复制选中)按钮。复制以后,你需要将新的节点放置在正确的位置(复制出来的节点将会生成在被选中探头节点的同一位置)。如果你更加仔细地观察Inspector面板中的界面,你就会注意到你还可以添加独立的探测器(Add Probe),删除探测器(Delete Selected),或者选中群组中的所有探测器(Select All)。为了观察灯光探测器的运作情况,选中Sphere,在上面添加一个Rigidbody组件(Add Component & Rigidbody)。然后,给它的碰撞检测器分配一种材质。你可以使用橡胶材质。现在,将此Sphere放置在靠近Box顶部的位置,然后按下Play按钮。现在你就可以看到Sphere合适的光照了。为了观察不同之处,禁用掉灯光探测器,再一次按下Play按钮,进行观察。点光源点光源是在游戏中的常见光,他们常被用作爆炸源和电灯泡。由于它们向各个方向发射光线,因而在图形处理器上的消耗较为平均。但是,在使用点光源的时候进行阴影计算,消耗代价更高。选择GameObject & Light & Point Light,添加一个点光源。然后,将Point Light点光源放置在Box内部靠近顶端的位置。选中该Point light点光源,观察其Inspector面板中的属性参数。第一个参数是Type(类型)。这里你可以设置你想使用的光照类型。你可以选择Spot(聚光灯)、Directional(方向光)、Point(点光源)或者Area(区域光)。每种类型提供一个特定的光照效果。你可以选择其中任何一个选项,然后实时观察光照效果。然而,在这部分教程中只使用Point点光源选项。这样就会创建出一个电灯泡效果(光线向所有方向进行均匀照射)。第二个参数是Baking(烘焙)。你可以设置它为Realtime、Baked或者Mixed(实时、烘焙或混合)。保留该值为默认值。Range参数规定光线从Point light光源中心向外发射的最远距离。Color参数规定发射的光的颜色。Intensity参数规定光线的亮度值,Bounce Intensity是间接光强度倍增值。Shadow Type确定阴影属性和阴影类型。你可以将它设置为No Shadows(无阴影)、Hard Shadows(硬阴影)和Soft Shadows(软阴影)中的一个。请记住点光源阴影对引擎来说是最耗的,所以当选择该选项时请多加思考。如果你选择了Hard Shadows(硬阴影)或者Soft Shadows(软阴影),你就会看到由Sphere和Point light点光源产生的阴影效果。当你尝试调整Strength强度值,阴影也会随之减弱或者加强。Resolution分辨率参数设定阴影的精细程度。最后是—Bias和Normal Bias参数,他们用于设置光照空间的像素位置与阴影贴图值进行对比时的偏移量。Cookie是一个可选参数,用于表示被用作掩码的alpha通道纹理,决定光线在不同的位置的不同亮度。由于这是一个点光源,被使用的纹理贴图一定会是立方体贴图。DrawHalo选项只用于在光源周围渲染出光晕效果。Flare选项规定了在光源位置处对要渲染的光晕的引用。当你在调试3D场景以及可能遇到的瓶颈时,Flare和Draw Halo选项会很有用。RenderMode渲染模式选项定义了渲染器在渲染场景时光照的重要程度。程度越重,渲染将会越加强烈。Render Mode模式可设置为Auto(自动)、Important(重要)或者Non-Important(不重要)这三种。最后,Culling Mask用来选中或者剔除受点光源影响的物体群组。现在你已经理解了有关点光源的所有属性,那么让我们来讨论一下在使用点光源时的直接光照和间接光照。当你开发一个主要特点就是光源和光照效果使用的游戏时,复杂的光照场景会带来更长的加载时间和FPS帧率瓶颈方面,同时还会消耗更多的CPU。因此,建议你使用Shadows Type和Baking属性来平衡你的场景性能。举个例子,如果你将Baking(烘焙)属性设置为Realtime(实时),将Shadow Type(阴影类型)属性设置为Hard Shadows(硬阴影)或者Soft Shadows(软阴影),那么在Sphere和Box这两者之间将会得到一个非常好并且真实的阴影效果。然而,如果你的场景中存在很多光源,那这样的设置则会消耗过多的CPU资源。怎么解决这个问题?你可以先将Baking参数设置为Bake。一旦你这么做了,Unity就会自动为这个光源创建光照贴图,会给你一个性能上的提升。但是,这个性能提升也会有其自己的代价:现在你就无法得到透过点光源投射到类似Sphere这样动态对象中所形成的阴影效果。最好的做法是单独对每个光源进行分析,然后进行相应地处理。例如,在这个场景中,选择Realtime Baking(实时烘焙)和Hard Shadows(硬阴影)将会显得更合理,因为在盒子内部只放置了一个光源。但是,如果你的光源是墙上的一个火把,那么将Baking选项设置成Bake,让Unity来生成光照贴图会更好一点。总结一下,不管使用哪种做法,都取决于开发者对游戏质量和性能的管理。所以,请记住在维持平衡方面要多加注意,尤其当你在手机设备上进行开发的时候。聚光灯聚光灯是指从一个光源处朝着一个特定区域发射光线。它们只会照亮这个特定区域内的物体,这个区域被限定为一个三维锥形的区域。基本上,它们的工作原理类似于汽车的前照灯。正如你所想象的,它们非常适用于手电筒、汽车前照灯或者灯柱。对于图形处理器来说,它们也是资源消耗最大的光源类型。现在让我们把Point light参数调整为聚光灯。选中更早之前创建的Point light,调整它的Type类型参数为Spot(聚光灯)。下一步,旋转该光源,使它能够照亮Box的地板。并重命名为Spot light。你可能已经注意到,在Inspector面板内,Spot聚光灯的参数与Point点光源参数非常相似。但是,这里出现了一个新的参数Spot Angle。SpotAngle参数决定光锥的聚光角度。关于直接光照和间接光照,聚光灯的工作原理跟点光源非常相像。它们拥有相同的局限性和优势。因此,在你的游戏项目中设置光的平衡时,请务必小心谨慎。注意,为了在表现上和性能上取得平衡,你总是可以通过调整阴影和烘焙来做到。区域光区域光是在矩形区域平面的一面向所有方向发射的一种光。这个矩形通过Width和Height两个属性参数来进行限定。区域光只能用于光照贴图烘焙,这也就意味着在运行期间它们不会对物体产生影响。选中Spot light,调整它的Type参数为Area,并命名为Area light。然后,将此光源放置到盒子里,同时在Inspector面板中,修改Width和Height参数以确保它能够覆盖Box箱子内部的整个区域。查看Area light相关参数,你会注意到绝大部分参数跟之前的那些光源参数类似,例如Type、Draw Halo、Flare、RenderMode和Culling Mask。实际上新增的参数就是Width和Height。这两个参数都用于设置区域光的矩形尺寸大小。如果你按下Play按钮,你就会看到区域光向它范围内的所有物体投射光线。区域光矩形的尺寸是由Width和Height属性来共同决定的。投射光的面向方向为平面的法线方向,与光的正Z轴方向是一致的。光线是从整个矩形表面发射出去的。所以,与点光源或者平行光源相比,受区域光影响的物体阴影则显得更加柔和。区域光的光线计算非常消耗处理器资源,所以它们不能在运行期间使用,而只能用于光照贴图烘焙。总结总结一下以上关于光照系统在Unity 5中的教学指导。主要学习了几种光照效果和相关配置信息。有了这些知识,你现在就能够在你的游戏项目或者应用中灵活运用多个光照效果。Unity拥有活跃的生态环境,有许多其他的产品可以用来帮助你构建你的项目。同时该平台的特点有助于更好地提升你的技能,这也让它成为了一个非常不错的选择。不管怎样,你都可以看到我们在中留下的任何东西。如果你有更进一步的疑问或是意见,那么跟以往一样,在评论区中随意留言。【版权声明】原文作者未做权利声明,视为共享知识产权进入公共领域,自动获得授权。
分类:程序新手圈
请勿发表无意义的内容请勿发表重复内容请勿发表交易类内容禁止发表广告宣传贴请使用文明用语其它
淫秽色情政治倾向人身攻击抄袭剽窃广告刷屏恶意挖坟冒充他人其它
登录后参与讨论。点击}

我要回帖

更多关于 unity 两点之间的角度 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信