Zh/SteamVR/Environments/Introduction: Difference between revisions

From Valve Developer Community
< Zh‎ | SteamVR‎ | Environments
Jump to navigation Jump to search
Line 102: Line 102:
有时,教程会要求您输入控制台命令。 好吧,这就是解决方法。
有时,教程会要求您输入控制台命令。 好吧,这就是解决方法。


== Multiplayer ==
== 多人游戏 ==


SteamVR Home gives you multiplayer for free – there’s no additional setup needed to let multiple users explore the same environment together. In technical parlance, the engine uses a client-server architecture, with the server running on the computer hosting that particular multiplayer room – other clients communicate with that server to find out what is happening, and to update the server with their own changes. This all happens behind the scenes, and should be mostly seamless in action.
SteamVR Home免费提供多人游戏-无需其他设置即可让多个用户一起探索同一个环境。 从技术上讲,引擎使用客户端-服务器(C/S)体系结构,该服务器在托管该特定多人游戏机房的计算机上运行-其他客户端与该服务器通信以查明发生了什么,并使用自己的更改来更新服务器。 所有这一切都在幕后发生,并且在操作中应该几乎是无缝的。


Be aware, however, that real-world communications links are in the way – with latency and bandwidth limitations and all that those entail. Don’t build a hugely complex physically simulated masterpiece and expect it to run efficiently in multiplayer – and understand that lag can be an issue for more distant players...
但是,请注意,现实世界中的通信链路存在问题-延迟和带宽限制以及所有这些限制。 不要建立一个非常复杂的物理模拟杰作,并期望它能在多人游戏中高效运行-并且要知道,延迟对于较远的玩家来说可能是个问题...


== Performance ==
== Performance ==

Revision as of 23:53, 6 August 2020

开篇简介

也许您是一个完全的初学者,刚刚开始研究Source 2引擎。 或者您是经验丰富的Source 1 mod开发人员,或者您是其他引擎的专家,无论是Unity,虚幻引擎还是您自己创建引擎-你所掌握的知识仍适用于起源2。 本文将为大家提供帮助-解释起源2引擎和开发工具背后的基本概念。

我希望您至少对计算机上的游戏渲染有所了解,也就是说,在3D模型上使用纹理,这些纹理具有模拟的光照和效果,并通过一些神奇的渲染过程施加了效果,从而生成了最终的2D图像。 起源2没什么不同–在底层,它是一个高性能的游戏引擎,并且其用于渲染3D场景的方法几乎是行业标准的-最终都是三角形,纹理和着色器。 演示和性能有所不同。

启动SteamHome创意工坊工具

默认情况下,无论何时启动SteamVR本身,SteamVR Home都将运行。 但是,这将是一种特殊的,简化的“游戏”模式-所有与开发相关的部分都是“工具”模式的一部分。 为此,请单击小SteamVR状态窗口左上方的SteamVR菜单,然后单击创意工坊:创建/修改环境。

这将带您到Adddon(我喜欢叫:“项目”因为Addon本身就有插件的意思,插件在中文里指的是代码编译成的文件之类,而这里的Addon更像是Unreal 4里的“工程”)选择窗口。 如果您想直接创建一些东西,环境教程系列 就是为你准备的

Addons(工程)以及游戏文件夹

Addon是放置在基础游戏上的文件的集合-概念上类似于Source 1的mod(例如hl2文件夹css文件夹),但更适合在运行时之间进行切换。 您的文件将分为两种类型-源工程内容,其内容如下:

  • Steam\steamapps\common\SteamVR\tools\steamvr_environments\content\steamtours_addons\your_addon_name

.. 以及编译后的游戏内容,这些内容非常相似,例如:

  • Steam\steamapps\common\SteamVR\tools\steamvr_environments\game\steamtours_addons\your_addon_name

内容文件夹保存在您的计算机本地,不会被重新分配-当您将插件上传到创意工坊时,游戏文件夹中的内容将打包到名为.VPK的特殊文件中。

依赖环境与资源包

你只能使用自己制作的素材资源和SteamVR自带的少量资源开发,这太鸡儿可怕了,幸运的是,加载项可以加载他人分享在创意工坊中的资源内容。

你有没有想过你第一次进入SteamVR Home的美妙场景里面所用的资源都没有出现在素材浏览器当中? 因为他被打包成一个 资源包 储存到从插件选择窗口中去了! 当用户订阅您的地图时,Steam甚至会自动下载任何需要的依赖项。 请注意,依赖的内容不会复制到您自己的插件上,因此用户将无法使用任何本地资产包(Summit Pavilion除外)。

但是,为什么无论如何都需要对内容进行“编译”?

编译及其必要性

原工程文件内容的格式通常不适合重新分发或快速加载和呈现。 以纹理为例

纹理可能是一个巨大的Photoshop文档,其中包含数十个图层-然后将其编译成特定于引擎的格式,以优化其尽快渲染。 它会丢弃不需要的所有数据(在这种情况下为所有这些层),将其压缩为渲染系统的着色器所要求的形式(在显卡上运行的小程序,负责处理屏幕上看到的所有像素) ),并且通常使其适合于尽快高效地加载和显示。

因此,内容中的所有文件都是您在其中放置或在SteamVR Home工具中制作的“友好”格式,而游戏中的文件通常是由内容中的文件生成的,并且全部由引擎直接使用。

通常,当磁盘上的内容发生更改时,引擎会自动重新编译(因此您可以将文件保存在Photoshop中,并像魔术一样更新所有内容)–还可以强制重新编译(当事情有些混乱时,比如说我偷图不小心偷过来一个Source1的纹理)。

贴图,材质,模型,地图 ---G胖也疯狂

以下是所有文件的简要说明。

  • Textures 贴图(相当于Source1中的vtf文件) –像素,并且通常来自图像文件。 墙上的一些砖块图像或法线贴图(精确的层面方向描述,用于模仿额外的细节?),或者其他多种可能性中的一种。 但是,要渲染,引擎需要更多有关像素实际含义的信息。 纹理通常是使用Adobe Photoshop,GIMP或类似软件制作的。 内容更新时自动重新编译。
  • Materials 材质(相当于Source1中的vmt文件) – 所有这些贴图如何一起使用的描述,以便着色器知道所有内容的用途。 因此,对于砖墙,材料可能指向颜色图,法线图,光泽图(描述表面光滑度/粗糙度)等,并且您可能还有另一种版本的砖墙,该图具有不同的颜色图 但法线和光泽贴图相同。
    • Materials are set up in the aptly named Material Editor.
    • 每当您更改材质设置时,都会生成一个临时的新版本,并在保存时进行正确的重新编译。
  • Models 模型(相当于Source1中的mdl文件) – 通常是由3D建模程序(例如Maya,Modo,Blender等)制作的,它们是由三角形制成的3D形状。 示例包括家具,树木,建筑物部分,甚至动画人物和生物-您在VR中看到的很多东西都基于这些3D模型。 这些模型制成的表面被分配给特定的材质,这些材质又指向要使用的适当贴图。 虽然通常使用外部软件来构建基础模型文件,但其在引擎中通常使用Model Editor工具来进行处理
    • 更改源工程内容时会自动重新编译-生成的已编译模型的各个方面可以通过其使用的材质来定义。 例如,具有简单,无光照材质的模型可以自动编译为不具有顶点法线以节省空间,但是如果随后更改材质以使用适当的照明,则需要强制重新编译模型。 同样,您更改材质以开始将辅助UV用于某些东西,可能需要重新编译模型以使其正确渲染。
  • Maps 地图(相当于Source1中的Bsp文件) –从更多的角度对正在创建的世界及其所有内容进行三维描述,从照明到道具放置,甚至是将对象行为连接在一起的基本脚本。 您在SteamVR Home中在VR中看到的所有内容最终都托管在地图中-这是电影场景或舞台上发生的一切。
    • SteamVR Home tools 使用 Hammer2地图编辑器 作为地图编辑器-它本身也是一个功能强大的3D建模程序。 地图可以包含在Hammer中创建的形状-例如,SteamVR Home,Summit Pavilion的默认地图,其架构主要由Hammer内部制作的几何图形构成。
    • 地图不会自动重新编译-您始终必须先手动编译它们,然后再运行它们。 编译地图之前,您可能需要完成多个阶段(例如,建筑照明)–这些步骤都是单独完成的,因为它们可能需要花费相当长的时间,并且结果可以在许多情况下重复使用。

其他文件包括声音,粒子系统等-这些文件在您的Addon的内容文件夹中都有源版本,并且(自动或不自动)在您的插件的游戏文件夹中被编译为精简高效的版本。

除此之外

文件和游戏之间的这种“完美”分离确实会在某些地方分解–主要是由引擎直接使用的各种脚本文件。 这些文本文件放置在游戏文件夹中的某个位置–其中包括Lua脚本文件和Soundscape定义。 但是,除了这些例外,游戏中的几乎所有内容都可以从内容文件中重建。

实体,几何,实体逻辑等

Hammer中的一个空白地图是VR的空白空间–几乎所有东西都放置在这里。 并且,除非您将内容添加到地图中,否则世界将完全空白。 但是可以放什么呢?

  • Entities 实体 – 这些是引擎中的“事物”。 本质上,实体是计算机程序的特定实例,通常在世界上具有可见(和/或听觉)表示,并且将以特定方式对事物做出反应。 一个实体的例子可能是物理道具–它告诉引擎使用特定模型进行渲染,并且知道它应该如何应对玩家将其扔掉的情况。 另一个示例是鸽子,信息面板,光源或不可见的触发体积,它们告诉另一个实体在特定实体进入时执行某项操作。 甚至玩家也是一个实体。
  • Geometry 几何map geometry built in Hammer 可能完全是静态的且没有响应-尽管从技术上讲,它仍然是幕后某个实体,但它更像是固定的架构,所有事情都在此之上发生。 您还可以将地图几何的特定部分绑定到特定实体-这告诉实体(例如,滑动门或旋转平台)使用该地图几何作为其可见的表示形式。 对于不可见的触发体积,地图几何块将定义其包围的空间。
  • Entity Logic 逻辑实体 – 这是将地图中实体的行为粘合在一起的基本粘合剂。 简单的地图可能几乎没有实体逻辑,而复杂的游戏可能将各种事物连接在一起。 由输入和输出组成(与Source 1系统几乎完全相同,是改装爱好者),一个实体可能会遇到一件特定的事情(例如玩家将一只手放在指定的体积内),从而触发OnTrigger输出, 它连接到另一个实体上的输入,该实体告诉它执行其他操作。 例如,一扇门通过其“打开”输入被告知要打开,一盏灯通过其“ TurnOn”输入被打开,一声音通过其“ PlaySound”输入播放,或者被其FlyPath输入称为飞翔的鸽子。 每个实体可以具有一个输出列表,并且可以建立一个从其他实体调用的输入列表。. 这些功能依赖于 输入输出(国内开发者喜欢称为实体I/O) 请通读以获取更多信息-但请注意,这是Source 1教程,因此链接和详细信息通常会跳入不适用于SteamVR Home的主题。

Source2让你远离泄露和密封空间(奥利给干啦兄弟们)

如果你是起源1开发者,不管你是建图师,模型师还是音效师,或者你只是工作室里打杂的,你可能都遭受过地图leak泄露错误或者必须密封地图造成vvis不堪负重。但是现在,Source2让你远离这些灾难,你不用在Source2里密封你的地图了!这意味着你可以自由创作并不用考虑泄露事故

感谢奇迹?继续往下看

光照

许多人提到这种神秘的“照明”系统。 简而言之,引擎使用模拟来模拟现实生活中光线的外观以渲染对象-允许曲面对光源,环境照明等做出真实响应。 对象可以在自身和其他对象上投射阴影-正确设置后,光照可以成为地图的巨大视觉效果。 适当地照亮世界本身就是一门艺术。

脚本

对于简单的行为和映射逻辑,您可能仅会使用基本的实体I/O;但是对于更复杂的事情(例如,将自己创建新实体的行为),则需要使用Lua脚本系统。 可以与实体和世界互动的成熟编程语言。 There's a tutorial on building a player-interactable item if you want to know more, while there's also a wider overview on the script system.

控制台

不是游戏机,而是用于控制大型老式大型计算机的终端的概念后代。 控制台是一个命令行界面,可将日志和消息中继回用户,并接受许多基于文本的命令来控制引擎内部深奥的功能。 起源采用单独窗口的形式–在运行工具的情况下,您可以通过按下键盘左上角转义键下方的波浪号(〜)或从右上角的“工具”启动控制台

起源2取消了内置控制台,采用外部EXE控制台程序 (为什么内部控制台没了,带着VR头显敲键盘,想想就cyberpunk----某位起源大佬的话)

默认情况下,它可能会尝试连接到错误的端口(这些大型机的另一概念遗留物)–因此,请单击“本地主机”选项卡左侧的“ +”按钮,然后在“端口”中输入29009,然后按“接受”。 窗口应该神奇地充满了彩色文本。 您现在几乎可以将其全部忽略。

要在游戏中打开外部控制台,请打开相应游戏的EXE程序

  • Steam\steamapps\common\SteamVR\tools\steamvr_environments\game\bin\win64\vconsole2.exe

有时,教程会要求您输入控制台命令。 好吧,这就是解决方法。

多人游戏

SteamVR Home免费提供多人游戏-无需其他设置即可让多个用户一起探索同一个环境。 从技术上讲,引擎使用客户端-服务器(C/S)体系结构,该服务器在托管该特定多人游戏机房的计算机上运行-其他客户端与该服务器通信以查明发生了什么,并使用自己的更改来更新服务器。 所有这一切都在幕后发生,并且在操作中应该几乎是无缝的。

但是,请注意,现实世界中的通信链路存在问题-延迟和带宽限制以及所有这些限制。 不要建立一个非常复杂的物理模拟杰作,并期望它能在多人游戏中高效运行-并且要知道,延迟对于较远的玩家来说可能是个问题...

Performance

Gaming computers these days are ridiculously fast. But VR is extremely heavy on system requirements – so, like an irresistible force versus an immovable object, something has to give. One of the largest computational costs is in rendering the scene – so two binocular views in high definition at 90 frames per second. And, much more so than with games on a flat monitor, missed frames in VR are pretty obvious and unpleasant – causing juddering and shuddering at best. The rendering system and shaders in SteamVR Home are specifically engineered to be as efficient as possible, but it’s still possible to overload it.

The adaptive fidelity system used in SteamVR Home will dynamically enable and disable render size and features to get the best possible quality from your hardware, but to prevent excessive blurriness it won’t go below a certain level. When running in Tools mode, it will be disabled – it will be only enabled in game mode. (To best appreciate performance, test things in game mode – tools such as Hammer can expose their own cost on things currently running in VR.)

Here are a few potential rendering costs:

  • Too much geometry! The world can be too detailed. For a photogrammetry-based scene, which is pretty much a huge unlit mesh with some giant textures on it, around 2-3 million triangles is a practical limit. Going much beyond that can start causing the framerate to drop on lesser hardware.
  • Too much texture memory – again mainly a potential issue with photogrammetry-based scenes, having too many large textures can also cause precipitous performance issues on lesser hardware. Around 15 8k textures can be a sensible maximum – that’s something like 600MB of textures. Remember that things like normal maps, transparency maps and suchlike add up as well – and increase download size of whatever you make.
  • Expensive lighting – having too many dynamic light sources and shadows being cast all add to the rendering cost. While the lighting system in SteamVR Home is remarkably efficient (a graphics programmer kept urging me to add more shadowed spotlights to the Summit Pavilion environment), misunderstandings and over-expectations can cause significant issues. Some general rules are: restrict each light source to light only what it is needed for – bring the range in as far as you can – and don’t have too many of them. Dynamic lights are fairly expensive, so bake as many as you can – more information on the lighting system is coming in the near future!
  • Expensive shaders – the standard shader in SteamVR Home has many options, bells and whistles. Don’t turn all of them on and expect to render everything in framerate on basic hardware – a particularly expensive thing can be having many layers of transparent geometry (alpha-tested geometry is definitely not cheap, thanks to some super-fancy antialising features).
    • If you can, find someone with an entry-level GPU to test things with – an Nvidia GeForce GTX 970 or AMD Radeon RX 480 are a good baseline.

For an up-to-date view of current rendering cost, bring up the frame timing window in SteamVR : Settings : Perfomance : Display Frame Timing. At a very simplistic level, the GPU graph at bottom should stay below 11ms, without any non-zero red line popping up at the bottom – if running in game mode, the adaptive fidelity should try to maximise GPU usage, but it should rarely if ever go above 11ms.

Tip.png提示:Talking about ‘gaining 5fps’ or similar doesn’t really make sense – in games development, it’s all about milliseconds. It takes marginally over 11ms a frame to maintain 90fps, so saving 2ms is much more meaningful than ‘saving 5fps’, which gives no indication of absolute rendering cost saved. (Did you start at 10fps, or 1000?)

If your CPU graph is busy leaping above 11ms, then you’ve got different problems. Here are some potential CPU costs:

  • Too many entities – it’s much more likely to be some aspect of the specific entities you have in the map rather than an overall count of all entities, but if you have many more than usual of a certain thing, it may be worth investigating further.
  • Expensive scripts – scripts have to finish running for that frame before rendering can continue, so if you have complex loops and lots of logic, the scripts may be too expensive.
  • Complex rendering – counter-intuitively, you can have a high rendering cost even if the GPU isn’t maxed out, thanks to draw calls. If you have many separate models and/or materials, the CPU has to tell the GPU to render each one, which incurs a cost which goes up the more things you have.
  • Complex physics – having too many physically simulated objects in the scene at the same time can be a significant computational cost – and in particular having a complex collision hull colliding with another can be very expensive, causing severe frame drops. More information on simplifying physics systems to come!

Documentation

Finally, welcome to the Valve Developer Community wiki! This documentation is a never-ending work in progress, and is built in part by people like you - each page has a discussion section, and each page can be edited and extended as you see fit. If you have any questions, please do post them - and if you have any answers, post those too!