Creating a Material:zh-cn

From Valve Developer Community
Revision as of 06:57, 8 January 2019 by GlrWere (talk | contribs)

Jump to: navigation, search
English Français Русский 日本語 한국어

本简体中文页面【正在】由 Gloria 汉化。

本篇教程将一步步教你如何创建全新的材质(Material),包括材质纹理(Texture)的创建。

创建纹理

只要满足以下条件,任何图片文件都能作为纹理使用:它的尺寸(高度和宽度)必须是2的乘方,2、4、8、16、32、64、128、256、512、1024、2048...以此类推。如果不清楚该用哪一种尺寸,可以参考现有的同类型纹理。高分辨图片会降低性能,但在近距离下更清晰。

不同类型的物体有不同标准的分辨率(例如人物模型的纹理分辨率非常高)。如果感到困惑,可以使用GCFScapesource materials.gcf 中提取纹理,看看Valve是怎么做的。

注意:
纹理源文件应当使用无损格式保存,例如TGA,以避免图片质量的损失。

转换纹理

为了给起源引擎使用,纹理必须先转换为 Valve Texture Format 格式。Valve提供的工具是VTEX。它是个命令行工具,使用起来相当不便,因此推荐使用第三方工具VTFEdit:它提供了图形用户界面,能让你无需重新编译就能修改纹理属性,支持大多数图片格式,也不需要每个纹理都创建一遍脚本文件。当然有些情况下还是不得不用回VTEX工具...但也仅限于那部分情况。此外,在使用带透明通道的纹理时,它会建议你先转为TIFF格式保存,因为PNG的透明度容易导致问题。

(部分图片软件如PhotoshopGIMPPaint.NET在安装了VTF插件后,能直接保存为VTF格式文件。但本篇教程不做讲解,因为并非每个人都使用上述工具。)

如何将自定义图片导入VTFEdit:菜单 File > Import 或者快捷键 Ctrl+I,选择图片后将会弹出“导入”对话框:

VTFEdit的“导入”对话框

通用设置

设置是最关键的。以下是其中三个:

Normal format/普通模式
不透明纹理使用的色彩/压缩格式。
Alpha format/透明通道模式
带透明通道的纹理使用的色彩/压缩格式。
Texture type/纹理类型
在导入了多张图片时使用,具体类型取决于它是(animation frames(动画帧)/cubemap faces(立方体贴图表面)/depth slices(深度切片))。

如果你制作的是普通、简单的纹理,上面的选项无需修改。但如果制作的是高清的细节图片,则需要选择无损的压缩模式.

Mipmap设置

Mipmaps是当纹理距离镜头相当远时,自动切换成的低清版纹理。它的使用减少的不必要的图片缩放,增加了性能与图片显示质量。纹理细节层次需要Mipmap才能正常使用。

小技巧:在3D世界中使用的纹理才需要mipmap。为了节约内存,只是用在2D界面的图片不应有mipmap。

下列图片展示了VTFEdit中各类不同的mipmap过滤器:

Normal map settings

These (mis-labelled) settings allow you to automatically generate a bump map from your input image. You'll want to do this properly with an image editor for the material you ship, but the automated option is there if you want quick results or a base to work from.

Configuring and saving

When you hit OK the input file is converted (there may be quite a lengthy pause for large images) and the output VTF appears. Now all that is left is configuring the texture with the options in the checkbox list on the left-hand side of the screen. See Valve Texture Format#Image_flags for descriptions of each.

Finally, save the file somewhere under your game or mod's \materials folder.

Creating a material

Source doesn't access textures directly. Everything goes through a material.

Materials are script files that can be created in any text editor, but it's recommended that you use Notepad++ in conjunction with the community-made syntax highlighting rules. For your material to be detected, you must save it under your game or mod's \materials folder with the extension .vmt.

Note:If you are creating materials and textures exclusively for a map for an existing mod, consider using BSPZIP\Packbsp\Pakrat\Compile Pal to package the material and texture files within the map file itself. This will avoid them ever becoming lost.

Syntax

A material file looks like this:

<shader>
{
	<parameter> <value>
	...
}
LightmappedGeneric
{
	$basetexture coast\shingle_01
	$surfaceprop gravel
}

There are many shaders to choose from, but most materials will use either LightmappedGeneric (brushes) or VertexLitGeneric (models). The third most common shader is UnlitGeneric, which is used for UI materials and the occasional tool texture.

Parameters

For a list of all documented shader parameters, see Category:List of Shader Parameters.

With a shader chosen you're onto parameters (also called commands). There are hundreds of options for what to put in a material so this article will only cover the most common, which are accepted by more or less all shaders. They are:

Tip:If you ever need to use a space or tab character in a parameter value, you must wrap the whole value with "quote marks". You'll often see absolutely everything wrapped like this - save yourself some typing, as that's unnecessary.

See also