Zh/SteamVR/Environments/Introduction: Difference between revisions

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


== Textures, Materials, Models, Maps – oh my! ==
== 贴图,材质,模型,地图 ---G胖也疯狂 ==


Here’s a quick breakdown of what all these files are.
以下是所有文件的简要说明。


* '''Textures''' – pixels, basically, and generally from image files. An image of some bricks on a wall, or a normal map (a description of precise surface direction, for imitating extra detail), or one of numerous other possibilities. To be rendered, the engine needs a bit more information about what the pixels actually mean, however. Textures are usually made in software like Adobe Photoshop, The GIMP or similar. Automatically recompiled whenever content updates.
* '''Textures 贴图(相当于Source1中的vtf文件)''' –像素,并且通常来自图像文件。 墙上的一些砖块图像或法线贴图(精确的层面方向描述,用于模仿额外的细节?),或者其他多种可能性中的一种。 但是,要渲染,引擎需要更多有关像素实际含义的信息。 纹理通常是使用Adobe Photoshop,GIMP或类似软件制作的。 内容更新时自动重新编译。
 
* '''Materials 材质(相当于Source1中的vmt文件)''' – 所有这些贴图如何一起使用的描述,以便着色器知道所有内容的用途。 因此,对于砖墙,材料可能指向颜色图,法线图,光泽图(描述表面光滑度/粗糙度)等,并且您可能还有另一种版本的砖墙,该图具有不同的颜色图 但法线和光泽贴图相同。


* '''Materials''' – a description of how all those textures go together, so the shaders know what everything is for. So for the brick wall, the material might point at the colour map, a normal map, a gloss map (describing surface smoothness / roughness) and so on – and you might have an alternative version of the brick wall which has a different colour map but the same normal and gloss maps. The material untangles all of these, and allows simple configuration of all the shader’s inputs.
** Materials are set up in the aptly named [[Dota_2_Workshop_Tools/Materials/Material_Editor|Material Editor]].
** Materials are set up in the aptly named [[Dota_2_Workshop_Tools/Materials/Material_Editor|Material Editor]].
** Makes a temporary new version whenever you change material settings, and does a proper recompilation when you save.
** 每当您更改材质设置时,都会生成一个临时的新版本,并在保存时进行正确的重新编译。


* '''Models''' – generally produced in a 3D modelling program (such as Maya, Modo, Blender etc.), these are 3D shapes made out of triangles. Examples would include furniture, trees, sections of buildings, even animated characters and creatures – a good deal of what you’ll see in VR is based around these 3D models. The surfaces these models are made out of are assigned to particular materials, which in turn point at the appropriate textures to use. While the underlying model files will usually be built using external software, their use in the engine will be set up in the imaginatively titled [[SteamVR/Environments/Importing_Tutorial|Model Editor]].
* '''Models 模型(相当于Source1中的mdl文件)''' – 通常是由3D建模程序(例如Maya,Modo,Blender等)制作的,它们是由三角形制成的3D形状。 示例包括家具,树木,建筑物部分,甚至动画人物和生物-您在VR中看到的很多东西都基于这些3D模型。 这些模型制成的表面被分配给特定的材质,这些材质又指向要使用的适当贴图。 虽然通常使用外部软件来构建基础模型文件,但其在引擎中通常使用[[SteamVR/Environments/Importing_Tutorial|Model Editor]]工具来进行处理
** Automatically recompiled when you change source content – aspects of the resulting compiled model can be defined by the materials it uses. For instance, a model with a simple, unlit material can be automatically compiled to be without vertex normals to save space – but you’ll need to force a model recompile if you subsequently change the material to use proper lighting. Similarly, you change your material to start using secondary UVs for something, you may need to recompile the model for it to render properly.
** 更改源工程内容时会自动重新编译-生成的已编译模型的各个方面可以通过其使用的材质来定义。 例如,具有简单,无光照材质的模型可以自动编译为不具有顶点法线以节省空间,但是如果随后更改材质以使用适当的照明,则需要强制重新编译模型。 同样,您更改材质以开始将辅助UV用于某些东西,可能需要重新编译模型以使其正确渲染。


* '''Maps''' – more of a three-dimensional description of the world you are creating and everything in it – from lighting to prop placement via which sounds are placed where, and even the basic scripting linking object behaviours together. Everything you see in VR in SteamVR Home is ultimately hosted in a map – it’s the film set or theatrical stage in which everything happens.
* '''Maps''' – more of a three-dimensional description of the world you are creating and everything in it – from lighting to prop placement via which sounds are placed where, and even the basic scripting linking object behaviours together. Everything you see in VR in SteamVR Home is ultimately hosted in a map – it’s the film set or theatrical stage in which everything happens.

Revision as of 23:32, 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 – more of a three-dimensional description of the world you are creating and everything in it – from lighting to prop placement via which sounds are placed where, and even the basic scripting linking object behaviours together. Everything you see in VR in SteamVR Home is ultimately hosted in a map – it’s the film set or theatrical stage in which everything happens.
    • The SteamVR Home tools include Hammer as the map editor – which, a little confusingly, is also a capable 3D modelling program by itself. Maps can contain shapes created in Hammer – an example would be the default map for SteamVR Home, the Summit Pavilion, the architecture for which was mainly built out of geometry made inside Hammer.
    • Maps are not automatically recompiled – you’ll always have to manually compile them before running them. There are various stages (such as building lighting) which you may need to do before compiling the map – these are all done separately since they may take a reasonable amount of time, and the results can be reused in many cases.

Other files include sounds, particle systems and more – these all have source versions in the content folder for your addon, and (automatically or not) get compiled into streamlined, efficient versions in the game folder for your addon.

Exceptions to the Rule

Of course, this perfect separation of content and game does break down in places – mainly with various script files which get consumed by the engine directly. These text files get placed somewhere inside the game folder – these include Lua script files and Soundscape definitions. But, beyond these exceptions, pretty much everything in game can be rebuilt from files in content.

Entities, Geometry, Entity Logic and More

An empty map in Hammer is the blank canvas for VR – this is where just about everything gets placed. And, until you add things to your map, the world will be entirely empty. But what can be put there?

  • Entities – these are ‘things’ in the engine. Essentially a particular instance of a computer program, an entity often has a visible (and/or audible) representation in the world, and will react to things in particular ways. An example of an entity could be a physics prop – it tells the engine to render it with a particular model, and knows how it should react to the player throwing it around. Another example would be a pigeon, an information panel, a light source, or an invisible trigger volume which tells another entity to do something when a particular entity enters it. Even the player is an entity.
  • Geometrymap geometry built in Hammer can be entirely static and unresponsive – while technically it’s still an entity somewhere behind the scenes, it is more like fixed architecture upon which everything happens. You can also tie particular sections of map geometry to specific entities – this tells the entity (such as a sliding door, or a rotating platform) to use that map geometry as its visible representation. In the case of that invisible trigger volume, a block of map geometry will define the space it encloses.
  • Entity Logic – this is the basic glue sticking the behaviours of entities in a map together. A simple map might have little, if any entity logic – a complex game might have all kinds of things connected together. Made from Inputs and Outputs (and pretty much identical to the Source 1 system, modding aficionados), an entity might experience a particular thing happening (such as a player putting a hand into a specified volume) which causes it to fire an OnTrigger output, which is connected to an Input on another entity which tells it to do something else. Examples would include a a door being told to open via its Open input, a light switching on through its TurnOn input, a sound playing via its PlaySound input, or a pigeon flying away being called by its FlyPath input. Each entity can have a list of outputs, and can build up a list of inputs being called from other entities. There's an in-depth article on Inputs and Outputs to read through for more information - but do note that this is a Source 1 tutorial, so links and specifics will often wander off into topics not applicable to SteamVR Home.

No More Leaks or Brushes (why am I even telling you about these anyway?)

If you’re a Source 1 modder, rejoice. Maps are now arbitrary polygon soup, and have no need to be sealed against the void – and brushes are no longer a thing, having been entirely replaced by the much friendlier map geometry constructed in Hammer.

If you have no idea what wonders you are missing out on here, just be thankful and move on.

Lighting

There are many mentions of this mysterious ‘lighting’ system. Put simply, the engine uses a simulation of how light appears in real life to render objects – allowing surfaces to respond realistically to light sources, ambient lighting and so on. Objects can cast shadows on to themselves and other objects – when set up correctly, lighting can be a huge visual aspect of a map. Properly lighting worlds is a bit of an art in itself. More information on the lighting system to come!

Scripts

For simple behaviours and map logic, you’ll likely use just basic entity logic – but for more complex things (such as behaviours approaching the creation of new entities in themselves) you’ll want to use the Lua script system, which is a full-fledged programming language which can interact with entities and the world. 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.

Console

Not a games console, but instead a conceptual descendant of the terminals used to control giant old mainframe computers. The console is a command line interface that relays logs and messages back to the user, and accepts many text-based commands for controlling esoteric features deep inside the engine. It takes the form of a separate program – with the tools running, you can bring it up by pressing the tilde key (~) just below the escape key to the top left of your keyboard, or from the Tools menu in the top right corner of most tool windows.

By default, it may attempt to connect to the wrong port (another conceptual legacy of those mainframes) – so click the ‘+’ button to the left of the ‘Localhost’ tab and, in Port, enter 29009 and press Accept. The window should magically fill with multicoloured text. You can pretty much ignore it all for now.

To launch the console when running in game mode, you can run the .EXE from here:

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

Occasionally tutorials will ask you to enter console commands. Well, this is how to get to it.

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.

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

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!