Zh/Materials for models: Difference between revisions

From Valve Developer Community
< Zh
Jump to navigation Jump to search
(创建了Material for models的中文页面(W.I.P.))
 
No edit summary
Line 1: Line 1:
[[Category:Modeling]] {{otherlang2|
[[Category:Modeling]] {{otherlang2|
en=:Materials for models
title=模型材质 |
en=:Materials for models |
ru=:Materials for models:ru|
ru=:Materials for models:ru|
jp=:Materials for models:jp|
jp=:Materials for models:jp|

Revision as of 00:26, 24 May 2018

Template:Otherlang2

介绍

为起源引擎游戏制作模型——不论是实体模型、角色模型或是动作模型(viewmodel)等等——都需要至少3个基本构件:.MDL文件,.VMT文件以及VTF文件。

然而,单纯地认为MDL文件是“网格”,VTF文件是“皮肤”,VMT文件是“物理”并不够准确。在制作的每个阶段,你的模型都包含了至少两个独立的文件,但它们之间是有交叉引用的。编译的各个阶段都需要来自其它文件的数据。因此整个流程必须严格按照顺序进行,文件名和路径也是有严格要求的。

这些文件的创建过程大致可以分为两步:

  1. 第一步,创建基础纹理并映射到模型网格上,生成出两个“临时”文件:.SMD文件与.TGA文件。
  2. 第二步,使用.SMD文件与.TGA文件,编译MDL、VMT、VTF文件到起源游戏根目录各自的路径下。

使用XSI将纹理映射到.SMD模型中

  1. 选中建模完成的网格
  2. 切换到XSI的渲染模式(位于左边栏的顶部)
  3. 在 Render->Get-Material 选择 Blinn
  4. 在 Render->Get-Texture 选择 Image 以打开图片纹理窗口:
  5. 在 Image-Texture tab->Image 点击 "New" 以查找并导入你的TGA纹理文件
  6. 在 Image-Texture tab->Texture Projection 点击 "New" 并选择 Unique UVs (polymesh)(关闭图片窗口)
  7. 按下“Alt+7”打开XSI Texture Editor窗口
  • 如果你的纹理映射搞砸了想从头开始:
1. 按下 "8" 打开 Scene Explorer,接着按如下方法进入到 Texture Projection:
-> Cube (或是你的基础物体)
--> Polygon Mesh
---> Clusters
----> Texture_Coordinates_Auto
-----> Texture Projection (Explicit UVWs) 
2. 现在左键点击 "Texture Projection (Explicit UVWs)" 进行选中,然后按下 "Delete" 键来删除。
3. 检查 3D 视图(在 'textured' 模式下)以确保没有选错。否则,按下“Ctrl+Z”撤销操作并重来一遍。

适时地预览

  • 带纹理模型的效果应该直接在起源引擎中进行评估,在你开始进一步完善材质、导出vtf、创建vmt、创建mdl并从引擎中观察效果之前。只有先在引擎中看到了你的模型,才能开始完善你的纹理、阴影参数。

棋盘模板纹理

  • 使用棋盘纹理(checkerboard texture)非常适合最开始的UV制作;它能让你快速发现哪里有畸变、条纹,或是其它需要修复的地方。另外,使用棋盘纹理让你得以衡量模型不同的位置应该用多大的图片像素密度(Texel Density, TD),当你在定义UV时,部分区域例如脸部可能需要更高的密度,但总的来说还是要尽量让模型上的图片像素密度更加均匀和一致。XSI中缺省的 noicon.pic 文件是个不错的选择,或者可以使用SDK中的这个文件, Checkerboard Starter Texture (右键另存为...)。

纹理的尺寸?

  • 尽早地导出.VTF文件并在引擎中进行预览。在控制台输 mat_showmiplevels 命令,在游戏中查看模型的贴图细化级别。尽管直觉上来说越大越好,但事实上并不一定,贴图细化会强制缩小你的纹理尺寸,导致出现模糊化的问题。

多个纹理

  • 尽可能只使用一种基础纹理,除非有材质上的其它需要。模型上有多个纹理会极大增加渲染时间。如果有在一个模型上创建多个纹理的需要,你必须先先选中一组多边形,创建一个簇(cluster),再将材质与图片应用到簇上。确保首选项设置成了 "reload externally modified images on focus"。这样当你按下Alt+Tab从其它程序——例如Photoshop——切换回XSI时,它将会自动重新加载纹理。

编译.VTF文件

任何纹理文件在映射到模型之前(当你从3D软件导出.SMD文件之前),都必须从TGA转换为VTF文件才能在起源引擎中使用。VTF文件名必须与应用到.SMD模型上的TGA文件名一致(例如:“我的纹理.TGA” 到 “我的纹理.CTF”),并且VTF文件必须放置在 $游戏根目录$/materials/models 路径下

  • SourceSDK/bin 包含了 Vtex.exe,一个用于编译VTF文件的程序。最简单的使用方式是在桌面上创建 vtex.exe 的快捷方式,然后拖动TGA文件到快捷方式上。它将在materials文件夹中创建一个与你的TGA文件名相同的VTF文件。 When you drag open a tga file with Vtex, a .TXT file is also created in the same directory as your .TGA, in this file you can issue commands to Vtex to alter your compression.
Note.png注意:For quick material creation, try adding "-shader VertexLitGeneric" to your target field in the Vtex shortcut properties. this works with any shadertype. Dragging a texture on to this modified shortcut will then create a .VTF file as usual, and create a .VMT file with the shader and basetexture defined for you.
  • Cannonfodder's StudioCompiler provides a more user-friendly GUI to Vtex (and Studiomdl). It is able to compile/decompile VTF, VMT and MDL files from/to TGA and SMD files.

Compiling your.VMT : Valve Material Type

Each Material for the Source engine is defined by a .VMT file. It specifies the lighting model, the basetexture (VTF), and any other additional channels you may have like: specularity, self-illumination, normalmap, transparency, translucency, and proxy shaders.

For models, your.VMT must be written by hand (using notepad, etc) and placed in the game_directory/materials/models folder so that your.MDL can find it. The $basetexture (your.VTF) referenced in your.VMT must also be in the same game_directory/materials/models folder so that your.VMT can find it.

Tip.png提示:The QC command $cdmaterials can be used to specify further subfolders.
Warning.png警告:All materials for models must use the VertexLitGeneric shader. Model Materials will not work properly with LightmappedGeneric or UnlitGeneric.

Here’s an example VMT file from HL2:

"VertexLitGeneric"
{
     "$basetexture" "Models/Combine_soldier/Combine_elite"
     "$bumpmap" "models/combine_soldier/combine_elite_normal"
     "$envmap" "env_cubemap"
     "$normalmapalphaenvmapmask" 1
     "$envmapcontrast" 1
     "$model" 1
     "$selfillum" 1
}

This example is a material used on a polygonal model, using the VertexLitGeneric shader. The $basetexture or diffusemap is specified as "Models/Combine_soldier/Combine_elite" The $bumpmap or normalmap is imported from "models/combine_soldier/combine_elite_normal". The $envmap or environmentmap is set to "env_cubemap", which refers to cubemap entities placed in the level; the specular reflections of this character will always reflect the world around it - assuming you have cubemap entities placed appropriately in you level. You can use a custom cubemap instead, if you choose. The next line, "$normalmapalphaenvmapmask" 1 tells the renderer that this material has a mask for the specularity, so only some areas of the model will reflect the env_cubemap information, as defined in this case by the alpha channel of the normal map, the specular mask can be here, in the alpha of the basetexture "$basealphaenvmapmask 1" or in a separate mask file "$envmapmask" "models/modelname/mymask". The "$envmapcontrast" 1 command means the brightness of the envmap reflections is multiplied by itself one time; to create brighter highlights and deeper shadows. All models need to contain the command, "$model" 1 which tells the renderer that this material is being used on a polygonal model compiled by Studiomdl.exe. The last line "$selfillum" 1 tells the renderer that the alpha channel of the $basetexture contains self illuminated areas, these areas of the alpha channel show up as glowing areas of the model.

Alpha-channel

To get materials with alpha-channel to work, you have to insert the command "$translucent" 1 to your VMT file. Sometimes this leads to rendering errors in the model (e.g. theres convex 1 in the back of convex 2, but convex 2 gets hidden by convex 1 => Rendering error). If this happens, using the command "$alphatest" 1 instead of "$translucent" 1 should fix it.

Proxy shaders

A powerful component of the source engine material system is the Proxy shader system. Examples of what proxy shaders are capable of are shown in the shaderzoo map contained in the sdk, and further documentation on their creation can be found in the materials documents.