Unity3D灯光详解

发表于2017-10-23
评论0 5.6k浏览

Lights will bring personality and flavor to your game. You use lights to illuminate the scenes and objects to create the perfect visual mood. Lights can be used to simulate the sun, burning match light, flashlights, gun-fire, or explosions, just to name a few。

译:灯光将给你游戏带来个性和味道。你用灯光来照亮场景和对象 以至创造了完美视觉的气氛。灯光可以用来模拟太阳,燃烧的火柴,手电筒,枪火光,或爆炸,等等等等,在此就不一一列举。

 The Light Inspector 灯光检视面板

There are three types of lightsin Unity  译:在Unity中有三种类型的灯:

  • Point lights shine from a location equally in all directions, like a light bulb。译:点光源从一个位置向四面八方发出光线,就像一盏灯。
  • Directional lights are placed infinitely far away and affect everything in the scene, like the sun。 译:方向光源(平行光) 被放置在无穷远的地方,影响场景的所有物体,就像太阳
  • Spot lights shine from a point in a direction and only illuminate objects within a cone - like the headlights of a car。  译:聚光灯 灯光从一点发出,只在一个方向按照一个锥形物体的范围照射,就像一辆汽车的车头灯。

Lights can also cast Shadows. Shadows are a Pro-only feature. Shadow properties can be adjusted on a per-light basis。

译:灯光也可以投射阴影。阴影是专业版的功能。阴影属性可以在每一个灯光的基础上进行调整。

Properties 属性


There are three basic light types in Unity. Each type can be customized to fit your needs。

译:在Unity中光有三种基本类型。各类型可以定制,以满足您的需要。


You can create a texture that contains an alpha channel and assign it to the Cookie variable of the light. The Cookie will be projected from the light. The Cookie's alpha mask modulates the light amount, creating light and dark spots on surfaces. They are a great way af adding lots of complexity or atmosphere to a scene。

译:你可以创建一个包含alpha通道的纹理,并将其赋予光线的Cookie变量。Cookie会被光线投影。cookie的Alpha遮罩调节光量,可以在表面产生亮点和黑点。他们是往场景加入大量复杂的东西或气氛的一种很好的方法。


All built-in shaders in Unity seamlessly work with any type of light. VertexLit shaders cannot display Cookies or Shadows, however。

译:Unity里所有的内置的着色器(built-in shaders)全都可用于任何类型的灯光。然而,VertexLit 着色器不能显示Cookies或者阴影。


In Unity Pro with a build target of webplayer or standalone, all Lights can optionally cast Shadows. This is done by selecting either Hard Shadows or Soft Shadows for the Shadow Type property of each individual Light. For more information about shadows, please read the Shadows page.

译:在Unity专业版,编译目标为网页版或单机版,所有的灯光可以选择性地投射阴影(Shadows)。这是通过选择每个灯光阴影类型( Shadow Type)属性为"硬阴影或软阴影来完成的。更多关于阴影的信息,请阅读阴影(Shadows )页。

Point Lights 点光源

Point lights shine out from a point in all directions. They are the most common lights in computer games - typically used for explosions, light bulbs, etc. They have an average cost on the graphics processor (though point light shadows are the most expensive).

译:点光源光线在某一点从各个方向发射。它们是电脑游戏中最常用的灯光——通常用于爆炸、灯泡、等。他们有一个图形处理器的平均成本(虽然点光源阴影是最昂贵的---最耗费资源的)。

 Point Light 点光源

Point lights can have cookies - Cubemap texture with alpha channel. This Cubemap gets projected out in all directions。

译:点光源可以有cookies – 带有 alpha通道的立方图(Cubemap )纹理。立方图 (Cubemap)可在各个方向得出投影。

 Point Light with a Cookie 带有Cookie的点光源

Spot Lights 聚光灯

Spot lights only shine in one direction, in a cone. They are perfect for flashlights, car headlights or lamp posts. They are the most expensive on the graphics processor.

译:聚光灯只在一个方向上,在一个圆锥体范围发射光线。它们用作手电筒真是完美,汽车的车头灯或者灯柱。它们在图形处理器上是最耗费资源的。

 Spot Light 聚光灯

Spot lights can also have cookies - a texture projected down the cone of the light. This is good for creating an effect of light shining through the window. It is very important that the texture is black at the edges, has Border Mipmaps option on and its wrapping mode is set to Clamp. For more info on this, see Textures.

译:聚光灯同样也可以带有cookies - 这可以很好地创建光芒透过窗户的效果。纹理的边缘是黑色的,打开边框多层纹理(Border Mipmaps )选项和它的循环模式(wrapping mode)设置为强制拉伸(Clamp),这是非常重要的。想要得到更多关于这方面的信息,参见纹理(Textures.)

 Spot Light with a Cookie 带有Cookie的聚光灯

Directional Lights 方向光源

Directional lights are used mainly in outdoor scenes for sun & moonlight. The light affect all surfaces of objects in your scene. They are the least expensive on the graphics processor. Shadows from directional lights (for platforms that support shadows) are explained in depth on this page.

译:方向光主要用于模拟在室外场景的阳光与月光。方向光影响你的场景中的对象的所有表面。 他们在图形处理器中是最不耗费资源的。方向光产生的阴影(因为平台支持阴影)标识着在此页(this page)上的深度。

 Directional Light 方向光源

When directional light has a cookie, it is projected down the center of the light's Z axis. The size of the cookie is controlled with Cookie Size property. Set the cookie texture's wrapping mode to Repeat in the Inspector.

译:当平行光有一个cookie,它是预测光的Z轴的中心。cookie大小由cookie的大小(Cookie Size)属性控制。在检视面板设置cookie贴图的循环模式(wrapping mode)为重复(Repeat)

 Directional Light projecting a cloud-like cookie texture 方向光投影一个云状的cookie纹理

A cookie is a great way to add some quick detail to large outdoor scenes. You can even slide the light slowly over the scene to give the impression of moving clouds.

译:Cookie是在大型户外场景中快速添加细节的好方法。你甚至可以将的灯光在场景中慢慢移动,给人的感觉就像云在动。


Performance considerations 性能考虑

Lights can be rendered in one of two methods: vertex lighting and pixel lighting. Vertex lighting only calculates the lighting at the vertices of the game models and interpolates the lighting over the surfaces of the models. Pixel lights are calculated at every screen pixel, and hence are much more expensive. Some older graphics cards only support vertex lighting.

译:灯光有两种渲染方式:顶点(vertex )光照和像素(pixel )光照。顶点光照只计算游戏模型的顶点照明和通过插值计算得出模型表面所有光线。灯光在屏幕每一个像素计算,因此很奢侈(耗费资源)。一些旧的显卡只支持顶点光照。


While pixel lighting is slower to render, it does allow some effects that are not possible with vertex lighting. Normal-mapping, light cookies and realtime shadows are only rendered for pixel lights. Spotlight shapes and Point light highlights are much better when rendered in pixel mode as well. The three light types above would look like this when rendered in vertex light mode:

译:像素光照渲染得慢,但它能够实现一些顶点光照不能实现的效果。正规映射(Normal-mapping),灯光cookies(light cookies) 和实时阴影(realtime shadows)只能由像素光照渲染。在像素光照模式下,聚光灯的形状和点光源亮点效果更好。当在顶点光照模式下渲染,以上三种光照类型的效果就像这样:

 Point light in Vertex lighting mode. 在顶点光照模式下的点光源

 Spot light in Vertex lighting mode. 在顶点光照模式下的聚光灯

 Directional light in Vertex lighting mode. 在顶点光照模式下的方向光

Lights have a big impact on rendering speed - therefore a tradeoff has to be made betwen lighting quality and game speed. Since pixel lights are much more expensive than vertex lights, Unity will only render the brightest lights at per-pixel quality. The actual number of pixel lights can be set in the Quality Settings for webplayer and standalone build targets.

译:灯光有对渲染速度有非常大的影响——因此必须权衡前后照明质量和游戏速度。由于像素光照比顶点光照奢侈得多(更耗费资源),Unity将只在最亮的光逐个像素渲染。网页版(webplayer)和单机版(standalone)编译目标中,像素灯的实际数量可以质量设置( Quality Settings )进行设置。


You can explicitly control if a light should be rendered as a vertex or pixel light using the Render Mode property. By default Unity will classify the light automatically based on how much the object is affected by the light.

译:光线以顶点光照或像素光照模式渲染。你可以通过渲染模式属性(Render Mode property)显式控制。默认情况下,Unity根据对象受到光影响的多少自动对光进行归类。


The actual lights that are rendered as pixel lights are determined on an object-by-object case. This means:

译:实际灯光被渲染在object-by-object的情况下确定作为像素光渲染。这句话的意思是:

  • Huge objects with bright lights could use all the pixel lights (depending on the quality settings). If the player is far from these, nearby lights will be rendered as vertex lights. Therefore, it is better to split huge objects up in a couple of small ones.  带有明亮灯光的巨大物体,可以全用像素光照(根据质量设置)。如果玩家非常远,附近的灯光可以用顶点光照模式渲染。因此,巨大的物体应分割成几个小的物体这样更好。

See Optimizing Graphics performance on Desktop, iOS or Android page for more information.

译:在 台式机(Desktop),iOS 或Android 页面参见优化图形性能(Optimizing Graphics performance),获取更多信息。


Creating Cookies


For more information on creating cookies, please see the tutorial on how to create a Spot light cookie.

译:创建的Cookie的更多信息,请参阅关于如何创建一个射灯cookie的教程( tutorial on how to create a Spot light cookie)


Hints 提示

  • Spot lights with cookies can be extremely effective for making light coming in from windows.  带cookies的聚光灯可以很有效的制作出光线从窗户射进来的效果。
  • Low-intensity point lights are good for providing depth to a scene.  低强度点光源带来场景深度。
  • For maximum performance, use a VertexLit shader. This shader only does per-vertex lighting, giving a much higher throughput on low-end cards.  为了获得最佳性能,使用VertexLit 着色。这个着色器(shader)只进行顶点光照,在低端卡提供高得多的吞吐量。

http://blog.csdn.net/wjlsxl_whb/article/details/53019031

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引