Zh/Source 2/Docs/Level Design/Lighting: Difference between revisions

From Valve Developer Community
< Zh‎ | Source 2‎ | Docs‎ | Level Design
Jump to navigation Jump to search
No edit summary
No edit summary
Line 120: Line 120:
{{提示|使用r_light_probe_volume_debug_colors和r_cubemap_debug_colors的控制台值来调试光探测容器}}
{{提示|使用r_light_probe_volume_debug_colors和r_cubemap_debug_colors的控制台值来调试光探测容器}}


== Lightmap Density ==
== 光照贴图密度 ==


Lightmap density describes how dense the lightmap texture is on a particular face. This is necessary to control because giving all faces a uniform density would be inefficient to calculate.
光照贴图密度描述光照贴图纹理在特定表面上的密度。这是必须控制的,因为给所有面一个均匀的密度是没有效率的。


You can preview lightmap density in-game with the command <code>mat_luxels 1</code>.
你可以使用命令mat_luxels 1预览游戏中的光照贴图密度。


=== Lightmap Player Spaces ===
=== 光照贴图玩家空间 ===


Lightmaps are textures containing precalculated lighting information for static surfaces. You want these to be as high resolution as possible for the best visual fidelity. You can ensure the compilation process automatically prioritizes player-accessible stuff by placing lightmap player space volumes - quite simply, these are Hammer meshes with materials/tools/toolslightmapres.vmat on them. The closer a surface is to one of these meshes, the more lightmap texels are assigned to it.
光照贴图是包含静态表面预先计算的光照信息的纹理。为了达到最好的视觉保真度,你需要尽可能高的分辨率。你可以通过放置光照贴图玩家空间容器来确保编译过程自动优先考虑玩家可访问的东西——很简单,这些是带有materials/tools/toolslightmapres.vmat的Hammer网格。一个表面越接近这些网格,就有越多的光照贴图纹理元素被分配给它。


The general gist of it is - place these lightmap player space volumes within areas the player can get to. Inaccessible areas - things behind fences, high up on walls, distant buildings - will thus be assigned fewer and fewer lightmap texels depending on how far away they are.
它的一般要点是-放置这些光照地图玩家空间容器在玩家可以到达的区域。不可到达的区域——栅栏后面的东西,高墙上的东西,远处的建筑物——将因此分配越来越少的光照贴图纹理元素,这取决于他们离得有多远。


The net result is apparently seamless lightmap detail!
最终的结果显然是无缝的光照贴图细节!


=== Lightmap Resolution Bias ===
=== 光照贴图分辨率偏差 ===


When editing a face, you can control the Lightmap Resolution Bias. This is a value that will influence how large the lightmap texture space is for that face relative to the rest of the map.
当编辑一个表面,你可以控制光照贴图分辨率偏差。这个值将影响该面相对于地图其余部分的光照贴图纹理空间的大小。


Bias scales by powers of 2. A lightmap bias of +1 will make the texture resolution 2x what it would be normally, +2 is 4x resolution, etc. Negative bias will lower the lightmap resolution.
偏差以2的幂来缩放。光照贴图的偏差为+1将使纹理分辨率变为正常的2倍,+2则为4倍等等。负偏差将降低光照贴图分辨率。


Be wary of adjusting this option by accident, as a single face with a very large lightmap bias can effectively destroy the lightmap density for the rest of your map! If you have bad shadows and your console is reporting 'Mesh with material <x> is extremely large in lightmap (x.x%)' with a large value, this may be why. You can go to the coordinates listed in console to get an idea of where these faces may be, and use <code>mat_luxels 1</code> in game to find suspiciously dense faces.
小心无意中调整这个选项,因为一个带有非常大光照贴图偏差的单一表面会有效地破坏你其余贴图的光照贴图密度!如果你有糟糕的阴影,你的控制台报告“Mesh with material <x> is extremely large in lightmap (x.x%)”有一个大的值,这可能就是其原因。你可以转到控制台中列出的坐标来了解这些面可能在哪里,并在游戏中使用mat_luxels 1来找到可疑的密集面。


== Basic summary of lighting: ==
== 照明基本总结: ==


* Use indexed lights for the key lights in your scene - sunlight, major light sources etc. that you want specular from, switchable / flickering lights etc.
* 在你的场景中使用索引灯作为主光源——阳光,主要光源等你想要从可切换/闪烁的灯等反射的光源
** The 'Baked Lighting Complexity' visualization mode will show you how things are looking in terms of rendering cost
** ''烘焙照明复杂性''的可视化模式将向你展示事物在渲染成本方面的样子
** Ideally, you want things black, red and a bit of orange and yellow
** 理想情况下,你需要黑色、红色和一些橙色和黄色
* Use fully baked lights for visually less important things - fill lights, things in background, dimmer light sources
* 在视觉上不太重要的东西上使用完全烘焙的灯——填充灯,背景物件,调暗的光源
* Use per-pixel lights only for very particular reasons - if in doubt, ''don't''.
* 只有在非常特殊的情况下才使用逐像素光源——如果有疑问,就'''不要'''使用。


== Volumetric Fog ==
== Volumetric Fog ==

Revision as of 00:22, 12 May 2021

Template:Otherlang2

在3D中渲染对象时,《半衰期:爱莉克斯》背后的引擎会模拟现实生活中灯光的显示方式—允许表面对光源、环境光等做出逼真的响应,静态和动态对象都会从这些光源投射阴影。为了确保高视觉逼真度和高性能,创意工坊工具需要预先计算大量信息—以各种形式存储照明数据,如光照贴图纹理、光探头体积和立方体贴图。

但这些到底什么?

照明系统的输入可分为以下几部分:

  • 静态几何体上的光照贴图纹理(Hammer网格、静态道具)
  • 光探头体积和立方体贴图(动态对象上的环境光、反射)
  • 光源(环境、点光源、正交光源和聚光灯)
  • 体积雾

要预览Hammer中的效果,可以使用顶部的“预览烘焙照明(Preview Baked Lighting)”菜单。这将做一个相对低质量的预览来呈现在虚拟现实中的最终照明效果——极大地帮助艺术指导、游戏设计和其他类似的。它使用顶点照明和许多单像素动态光源,而不是光照贴图——需要更少的预计算,但导致较低的质量和更昂贵的运行时渲染。

你需要为完整的发布版照明创建光照贴图,但你可以在VR中使用这个预览版本的照明进行低性能测试。除了非常简单的地图外,任何地图在这种照明下的帧率都可能非常糟糕,所以不要以这种方式发布地图!

光源类型

光源有几种不同的类型,光的消散方式也不同。你可以在左侧工具栏中使用Hammer中的实体工具将光源放置到地图中——很方便,它有一个样式化的灯泡图标。

放置后,在3D视图中选择实体,并在右下角的'对象属性'中设置颜色、亮度、最大距离等。

  • 环境光——light_environment
    • 来自天空的虚拟阳光——无限远的光源
    • 不随距离衰减
    • 通常在地图上只有一个
    • 在workshop_examples/prefabs/environment_settings文件夹里提供超级有用的预制件
  • 点光源——light_omni
    • 单一的全方位光源
    • 有点像灯泡!
  • 聚光灯——light_spot
    • 来自特定点的定向光源
    • 就像一个真实世界的聚光灯,令人惊讶!
  • 正交光 - light_ortho
    • 需要在实体类弹出菜单中选择'light_ortho'来放置
    • 介于环境光和聚光灯之间
    • 光是平行的,但只存在于特定的长方体内
    • 与环境光一样,不会随距离衰减
    • 适用于有限的天窗和其他特殊用途等

直接和间接照明

光源实际上由两个部分组成:

  • 直接照明——基于光源视线的主要组件
  • 间接照明——光线从一个表面反射到另一个表面的次要组成部分——可能相当微妙,但极大地增加了视觉真实感

如何渲染直接照明是这里的主要选择。

默认为烘焙灯光索引

  • 选择时将“直接照明(Direct Lighting)”设置为“烘焙(Baked)”,并选中“烘焙光照索引(Baked Light Indexing)”(默认设置)
  • 默认情况下,间接照明烘焙到光照贴图(对于静态曲面)和光探测体积(对于动态对象)
  • 优点:
    • 直接照明具有镜面反射(闪亮)组件
    • 可以从动态对象(角色、物理道具等)投射阴影
    • 静态几何体阴影上的真实接触强化【使用光源半径(Light Source Radius)/太阳散射角(SunSpreadAngle)】
    • 直接照明可以闪烁、频闪、打开和关闭(给灯光实体一个目标名称,并通过实体I/O告诉它该怎么做)
    • 渲染成本相对低!
  • 缺点:
    • 一次最多可以有4个索引光照射在一个表面上,否则会发生奇怪的事情(最好保持为一个或两个,以使渲染成本更低)
      • 在Hammer的3D视图右上方预览菜单里——将“工具可视化模式(Tools Visualization Mode)”设置为“烘焙照明复杂性(Baked Lighting Complexity)”
      • 黑色是在那个表面上的零索引光,红色1,橙色2,黄色3,白色4,青色是“不要那样做”
    • 光源不能移动
    • 一次只能有一个索引光源从动态对象上投射阴影
    • 如果你想要一个完全可开关的灯,间接组件不能被打开或关闭——将它设置为“None”
    • 地图中索引灯光的总数是有限制的,尽管它相当高,而且在正常使用中不太可能达到

完全烘焙直接照明

  • 在“直接照明(Direct Lighting)”设置为“烘焙(Baked)”且未选中“烘焙光照索引(Baked Light Indexing)”的情况下选择
  • 优点:
    • 基本上渲染0成本!
      • 直接组件存储在光照贴图和光探测容器中,与间接组件相同
    • 静态几何体阴影上的真实接触强化【使用光源半径(Light Source Radius)/太阳散射角(SunSpreadAngle)】
  • 缺点:
    • 直接照明没有镜面反射组件
      • 明亮的表面看起来干燥而粗糙
      • 不要从方向光照贴图中获得方向性
    • 不能从动态对象上投射阴影
    • 光源不能移动
    • 不能打开或关闭灯光,不能闪烁或频闪

每像素直接照明

  • 选择“直接光(Direct Light)”设置为“每像素(Per Pixel)”
  • 渲染成本可能非常高;通常只用于特殊场合(如玩家手电筒)或非常小的光源(弹药夹,树脂等)。
  • 只有在你知道自己在做什么的情况下才用这些
    • 查看附加的地图中的示例以了解更多细节
  • 优点:
    • 可以有高质量的高光组件(尽管在上面列出的小光源下高光会被关闭)
    • 可以有完全动态的阴影(同样,对于那些小光源会关闭)
    • 可以移动光源,例如用玩家手电筒!
    • 直接照明可以闪烁,频闪,打开和关闭
  • 缺点:
    • 渲染成本可能非常高!
    • 无接触硬化【光源半径(Light Source Radius)/太阳散射角(SunSpreadAngle)不起作用】
    • 如果启用,间接组件仍然被烘焙到光照贴图等(大多数情况下切换到“None”)
    • 外预览照明,我们只支持
      • 在视图中启用带阴影的单个light_spot或light_ortho
      • 最多8个禁用阴影和镜面反射和完全线性衰减的light_omnis

间接照明

为了对动态对象进行适当的间接照明,你需要放置Light Probe Volume and Cubemap实体——env_combined_light_probe_volume

  • 你想要每个中心都是一个典型的,在那个特定的空间里的平均视图,可以是一个房间,走廊,户外场景等等
    • 对于一个简单的长方体房间,你应该把它放在正中央,大约眼睛的高度
  • 扩展体积边界(红色、绿色和蓝色3D箭头)以完全包围该体积
    • 反射是通过盒子投影的立方体贴图完成的——想象一个盒子的每个面都有一个纹理
    • 在这个简单的长方体房间中,你希望体积边界与墙、地板和天花板相交
    • 因此,反射就是那个房间的简化版,具有正确的视深度和一切
  • 体积可以旋转和重叠——可以设置优先级,使一个覆盖另一个(例如,一个黑暗的玩家可进入的盒子,周围有阳光照射)
  • 必要时,应将hammer的几何体分解为单独的网格
    • 每个网格只能接收来自一个立方体贴图的反射
    • 不要担心在过程中有效地添加额外的几何体、顶点等——所有奇特的网格解剖东西都在后台以可见性和类似的方式进行。
  • 所有可到达的区域都应该用光探测容器包围起来——如果你有动态物体突然闪得很亮或者什么的,你可能漏掉了这一点
Tip.png提示:使用r_light_probe_volume_debug_colors和r_cubemap_debug_colors的控制台值来调试光探测容器

光照贴图密度

光照贴图密度描述光照贴图纹理在特定表面上的密度。这是必须控制的,因为给所有面一个均匀的密度是没有效率的。

你可以使用命令mat_luxels 1预览游戏中的光照贴图密度。

光照贴图玩家空间

光照贴图是包含静态表面预先计算的光照信息的纹理。为了达到最好的视觉保真度,你需要尽可能高的分辨率。你可以通过放置光照贴图玩家空间容器来确保编译过程自动优先考虑玩家可访问的东西——很简单,这些是带有materials/tools/toolslightmapres.vmat的Hammer网格。一个表面越接近这些网格,就有越多的光照贴图纹理元素被分配给它。

它的一般要点是-放置这些光照地图玩家空间容器在玩家可以到达的区域。不可到达的区域——栅栏后面的东西,高墙上的东西,远处的建筑物——将因此分配越来越少的光照贴图纹理元素,这取决于他们离得有多远。

最终的结果显然是无缝的光照贴图细节!

光照贴图分辨率偏差

当编辑一个表面,你可以控制光照贴图分辨率偏差。这个值将影响该面相对于地图其余部分的光照贴图纹理空间的大小。

偏差以2的幂来缩放。光照贴图的偏差为+1将使纹理分辨率变为正常的2倍,+2则为4倍等等。负偏差将降低光照贴图分辨率。

小心无意中调整这个选项,因为一个带有非常大光照贴图偏差的单一表面会有效地破坏你其余贴图的光照贴图密度!如果你有糟糕的阴影,你的控制台报告“Mesh with material <x> is extremely large in lightmap (x.x%)”有一个大的值,这可能就是其原因。你可以转到控制台中列出的坐标来了解这些面可能在哪里,并在游戏中使用mat_luxels 1来找到可疑的密集面。

照明基本总结:

  • 在你的场景中使用索引灯作为主光源——阳光,主要光源等你想要从可切换/闪烁的灯等反射的光源
    • 烘焙照明复杂性的可视化模式将向你展示事物在渲染成本方面的样子
    • 理想情况下,你需要黑色、红色和一些橙色和黄色
  • 在视觉上不太重要的东西上使用完全烘焙的灯——填充灯,背景物件,调暗的光源
  • 只有在非常特殊的情况下才使用逐像素光源——如果有疑问,就不要使用。

Volumetric Fog

Half-Life: Alyx uses a voxel-based system for having the atmosphere react to light sources - hazy light flares, glare, mist, shafts of light coming through windows - all are possible using this unified volumetric fog system.

To enable it in your map, place a env_volumetric_fog_controller entity. The default settings are generally okay.

You can set volume-specific fog with env_volumetric_fog_volume entities - drag out the volume bounds in a similar way to light probe volumes. For harder edges to a fog volume, select the fog volume entity and set 'Falloff Exponent' to a low value such as zero.

Next, you need to set light sources to contribute to volumetric fog. Select a light entity, then set 'Volumetric Fogging' to 'Baked'. You can tweak the fog intensity with 'Fog contribution strength'

One drawback is that for outdoors areas, sunlit things will suddenly look darker. By default, atmosphere will absorb light. Normally we'd fix this by enabling volumetric fogging on the sunlight, but unfortunately environment lights (such as that sunlight) can't contribute to volumetric fog, for various technical reasons.

It's possible to locally fake stuff with a fog volume set to a low fog strength (to minimize atmospheric darkening), then a light_ortho with volumetric fog enabled, a low brightness, high fog contribution strength, and angles and color set to the same as the sunlight light_environment.

You can have many light sources with volumetric fogging enabled - additional rendering cost per light source is relatively minor. For light_omnis, set as many as you can to 'Baked: No shadows' or graphics programmers will be sad.

Look at shipping maps for more examples!

Building Lighting

Preview Baked Lighting

For an in-Hammer preview of how your map will look when fully compiled, make use of the Preview Baked Lighting : Bake All Lighting menu. This will perform some lower-quality calculations which will help you iterate on the overall look and visual feel of your map - it'll let you continue working on the map beyond this point, but remember to re-bake preview lighting whenever you make any significant changes so that you'll get an up-to-date representation of how everything will look.

Tip.png提示:Change to a no-lighting view by pressing F5 and a full lighting preview with F6.
Tip.png提示:When baking preview lighting, to save time you can select a limited number of Hammer meshes and then Bake Lighting On Selection.

Building Lightmaps

Once you're happy with how your map will look, you can now compile the thing. Press F9 to bring up the Map Builder dialogue box. The default settings for Full Compile will generate 1k lightmaps - this should be relatively fast for a simple map, just taking a few minutes. To build cubemaps for proper reflections on metallic surfaces, remember to check the Build cubemaps on load checkbox.

For a release version of your map, select the Final Compile option. This will generate higher-quality lightmaps at 2k resolution. This may take a little while on a typical home PC!