คำอธิบายโครงสร้างพื้นฐาน
// ชื่อ Shader ที่แสดงผลใน Material ในที่นี้คือ "Custom/Basic"
// Block Shader ใช้คำนวณค่าในการแสดงผลให้กับ Material
Shader "Custom/Basic" {
// Block Properties ที่แสดงบน Material และใช้อ้างอิงในการคำนวณ
Properties {
// ชือ Properties ที่ใช้อ้างอิง (ควรขึ้นต้นด้วย _ เสมอ) ในที่นี้คือ _MainTex
// ชื่อ Properties ที่แสดงบน Material ในที่นี้คือ "Base (RGB)"
// ชนิดของ Properties ในที่นี้คือ 2D
// ตัวอย่างในที่นี่ จะแสดง Properties ให้ใส่ Texture ใน Material
_MainTex ("Base (RGB)", 2D) = "white" {}
}
// ตัวแปรที่ใช้อ้างอิง, struct, surf() และอื่นๆ
SubShader {
// RenderType
Tags { "RenderType"="Opaque" }
// Shader Level of Detail
LOD 200
// Block CG Script
CGPROGRAM
// กำหนดชนิดของแสงที่ใช้ ในที่นี้ใช้ Lambert (Unity Default Lighting)
// ซึ่ง Unity จะทำการคำนวณแสงให้เป็นชนิด Lambert
#pragma surface surf Lambert
// ตัวแปรอ้างอิงใน Block Properties (ถ้ามีตัวแปรใน Block Properties ควรที่จะมีตัวแปรอ้างอิง)
sampler2D _MainTex;
// Block Struct Input ใช้ในการอ้างอิงถึง UV หรือ ตัวแปร Built-in ใน Unity
struct Input {
float2 uv_MainTex;
};
// Function ที่ใช้ในการคำนวณค่า และ แสดงผลให้กับ Material
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}