字幕列表 影片播放 列印所有字幕 列印翻譯字幕 列印英文字幕 Materials in Unity are the assets that control Unity裡的材質控制物件的外觀 the visual appearance of game objects. 在著色元件裡,材質是一個 包含著色器(Shader)和著色腳本的資源 Applied to a renderer component, 屬性有顏色和貼圖等等 the material is essentially an asset 材質可從專案介面點選Create鈕產生 that brings together a shader, a script 可以從下拉選單選著色器(Shader) 一旦建立好的材質就可以指定給著色元件 that controls the appearance of a rendered surface 材質可以從3D模型裡面擷取出來 稍後我們會介紹這個部分 and it's required properties, such as 來個簡單的測試 colours and textures. 我們準備一個方體 Materials can be made by using the 也準備了一個範例材質 我們來指定材質給網格著色器 Create button on the project panel. 網格著色器是一個用來 對3D網格著色的元件 And once you've created this asset 我們將它指定到著色器的材質槽 it can be assigned to a renderer component 在預設情況下會有一個Default-Diffuse材質 and a shader can be chosen from the drop down list. 我們將它換成我們的材質 Materials can also be generated from 除了拖曳到材質槽來指定之外 也可以將材質拖到模型或場景物件上 models brought in from 3D packages 馬上可以看到材質貼在模型的樣子 but we will discuss this later. 指定好之後來看檢視其他的設定 As a basic example 要注意的是,這個檢視裡的材質設定 是一個指向資源材質屬性的捷徑 if we have a primitive cube in Unity 這非常重要,因為修改這裡的材質 等於直接修改材質資源 and an example material ready to use on it 舉例來說,我將這個材質改為紅色 那材質資源也會變成紅色 we can assign this to the mesh renderer. 或是我建立了一個圓球並指定同樣的材質 它也會變成紅色的 The mesh renderer is the component used 當我調整其中一個物件的材質 相當於調整材質資源的設定 to render any 3D mesh. 因此所有指定這個材質的物件都會改變 We'll assign this to the materials slot. 當匯入3D模型時Unity會在 Models目錄底下建立Materials子目錄 By default a primitive mesh has 除此之外也幫你指定好貼圖 Unity's default-diffuse material assigned to it. 舉例來說,我們匯入這個防爆門到Unity裡 貼圖將存入名為Textures的目錄 We will replace this with our example material. Unity會自動搜尋這些貼圖 並指定到對應材質裡 Whilst I have assigned this material 防爆門有兩個部,分別是門和框 by dragging it directly to the material's property 它們共用同一個材質 並使用不同部位的貼圖來著色 I could also assign it by dragging it to the model 材質名為Prop_blastDoor or dropping it in to the scene. 當我點選了它 會在專案介面被標記出來 And you can see that Unity previews what that 基本上匯入時會帶有Diffuse的著色器 著色成果基本就像這樣 material would look like on the mesh 我們準備了模型的法線貼圖 that we're dropping on to. 所以我們可以用凹凸著色器 像是Bumped Diffuse來運用這個貼圖 Once assigned we see settings for this material 法線貼圖是一個 存放高度和方向資訊的貼圖 below other components in the inspector. 用來投射凹凸紋理到網格表面 It's important to know that this part of the inspector's 可以不增加模型面數 又可以呈現表面凹凸細節的方法 settings are simply a shortcut to editing 你可以從場景或遊戲視窗看到兩者差異 the material asset. 所以門上的凹痕、溝槽和傷痕 可以用法線貼圖來表現 This is important because when changing the 同理我們可以選擇Bumped Specular 來表現表面光澤 properties of a material on the object 現在除了貼圖和法線貼圖 我們也可以設定光澤了 you are actually changing the material asset itself. 因此我們從平坦外觀到閃亮有刮痕的門 都只要調整著色器就可以達成 For example if I make this material red. 我們甚至還沒在模型上加工 這就是材質的厲害 The asset has been made red. Unity收納了許多開發遊戲會用到的著色器 當然你也可以編寫並使用自己的著色器 So for example 你可以從專案面板來新增並使用著色器 if I have a sphere and assign the same material it too will be red. And when adjusting that material on either of those two objects we're simply adjusting the asset so any object using that material will be changed too. When introducing 3D assets from a modelling application Unity will create the materials in a materials subfolder in the location of the asset as well as assigning textures for you. For example this blast door asset has been brought in to Unity and we have saved it's textures in to folder called Textures which Unity automatically searches in order to reassign it to the material that it creates. The two parts of the asset are the door and the frame. Both of these assets share the same material and simply use different parts of the texture to render them. The material that's being created is Prop_Blastdoor and I can see that if I click on it it's highlighted in the project panel. As standard when introducing this we would be shown a diffuse shader. This is a flat standard look for rendering 3D meshes. We have a normal map for this asset so we can instead choose a bumped shader such as Bump Diffuse to make use of this texture. The normal map is a way of storing height and directional information that is projected onto the surface of a flat mesh in order to give it the appearance of surface detail without adding vertices to the geometry itself. And if you look at the mesh in the scene or game view you can see the difference that this makes. So the dents, grooves and scratches on our blast door are accentuated in the normal map texture. We could also extend this to give it a shiny surface by choosing Bumped Specular. Here, in addition to the texture and the normal map we are also able to set the shininess. So we've gone from our default flat look to our nice shiny looking dented door simply by adjusting the shader. We haven't had to add any more detail to the original model, and that's the true power of using materials. Unity ships with many shaders that will cover all manner of game development needs and you can also write your own shaders and assign them. You can create these also from using the create button on the project panel.
B2 中高級 中文 英國腔 材質 貼圖 網格 物件 設定 資源 材料 - Unity官方教程 (Materials - Unity Official Tutorials) 378 8 朱瑛 發佈於 2021 年 01 月 14 日 更多分享 分享 收藏 回報 影片單字