原文地址http://blog.sina.com.cn/s/blog_471132920101d5of.html
Shader第二講
:Fixed Function Shader
Fixed function shader簡介: 屬于固定渲染管線 Shader, 基本用于高級Shader在老顯卡無法顯示時的情況。使用的是ShaderLab語言,語法與微軟的FX files 或者NVIDIA的 CgFX類似。例一:
顯示單一顏色下面我們來看第一個例子,顯示單一顏色,注釋寫得挺詳細了,照著格式寫即可。Function Shader" title="【風宇沖】Unity3D教程寶典之Shader篇:第二講Fixed Function Shader" style="margin: 0px; padding: 0px; border: 0px; list-style: none;">//根Shader
Shader "Custom/1_1color" {
// 屬性
Properties {
//定義一個顏色
_Color ("Main Color", Color) = (1,.5,.5,1)
}
// 子shader
SubShader {
Pass {
Material {
//顯示該顏色
Diffuse [_Color]
}
//打開光照開關,即接受光照
Lighting On
}
}
}
例二:顯示一張貼圖Function Shader" title="【風宇沖】Unity3D教程寶典之Shader篇:第二講Fixed Function Shader" action-data="http%3A%2F%2Fs15.sinaimg.cn%2Fmw690%2F47113292td0e101ae8f0e%26690" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;">Function Shader" title="【風宇沖】Unity3D教程寶典之Shader篇:第二講Fixed Function Shader" style="margin: 0px; padding: 0px; border: 0px; list-style: none; width: 135px; height: 180px;">Shader "Custom/1_2show1texture" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color("Main color",Color) = (1,1,1,1)
}
SubShader {
Pass
{
Material
{
Diffuse[_Color]
}
Lighting on
SetTexture[_MainTex]
{
//combine color部分,alpha部分
// 材質 * 頂點顏色
Combine texture * primary,texture * constant
}
}
}
}
例三:兩張貼圖疊加****Function Shader" action-data="http%3A%2F%2Fs9.sinaimg.cn%2Fbmiddle%2F47113292td0e150c65108%26690" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none; width: 330px; height: 297px;">Function Shader" style="margin: 0px; padding: 0px; border: 0px; list-style: none;">Shader "Custom/1_3merge2texture" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_MainTex2 ("Tex2 (RGB)", 2D) = "white" {}
_Color("Main color",Color) = (1,1,1,1)
}
SubShader {
Pass
{
Material
{
Diffuse[_Color]
}
Lighting on
SetTexture[_MainTex]
{
// 第一張材質 * 頂點顏色
Combine texture * primary
}
SetTexture[_MainTex2]
{
// 第二張材質 * 之前累積(這里即第一張材質)
Combine texture * previous
}
}
}
}