1. 程式人生 > >Unity3D_指令碼和材質系統的結合使用

Unity3D_指令碼和材質系統的結合使用

Material類

建立一個材質球就是貼圖和一些渲染的引數的組合可以理解成一個預製體,裡面儲存了各種各樣的渲染資訊。 
整個CG領域中這三個概念都是長不多的,在一般的實踐中,大致上層級關係是:材質Material包含貼圖Map,貼圖包含紋理Texture。 
紋理是最基本的資料輸入單位,遊戲領域基本上都用的是點陣圖。此外還有程式化生成的紋理Procedural Texture。 
貼圖的英語Map其實包含了另一層含義就是“對映”.其功能就是把紋理通過UV座標對映到3D物體表面。貼圖包含了除了紋理以外其他很多資訊,比方說UV座標、貼圖輸入輸出控制等等 
材質是一個數據集主要功能就是給渲染器提供資料和光照演算法,貼圖就是其中資料的一部分,根據用途不同,貼圖也會被分成不同的型別

,比方說Diffuse Map、Specular Map,Normal Map和Gloss Map等等。另外一個重要部分就是光照模型Shader,用以實現不同的渲染效果。

指令碼修改材質

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestMaterial : MonoBehaviour {

    Material m_material;
    public Texture newTex;
    // Use this for initialization
void Start () { //Materials是MeshRenderer的一個屬性 m_material = gameObject.GetComponent<MeshRenderer>().material; Debug.Log(m_material.name); //修改材質的顏色 m_material.color = Color.red; //設定主貼圖 m_material.mainTexture = newTex; //設定遊戲 m_material.SetColor("_Color"
,Color.green); } }