參考資料:
- ShaderLab syntax: Texture Combiners
http://docs.unity3d.com/Documentation/Components/SL-SetTexture.html - ShaderLab syntax: SubShader Tags
http://docs.unity3d.com/Documentation/Components/SL-SubshaderTags.html - Noobs Guide To Shaders #1
http://unitygems.com/noobshader1/ - Unity iOS ShaderLab @ Jessy Catterwaul
http://youtu.be/1C_-fQRKwG4
相關資料:
- Optimizing Graphics Performance
http://docs.unity3d.com/Documentation/Manual/OptimizingGraphicsPerformance.html
參考範例:
人生第一次的shader撰寫XD,超陽春Unlit受擊變色用shader,透過shaderLab簡單的功能只要少少幾行就能完成!呈現的效果為,不受光影響,單一貼圖表現,可以透過Color property的alpha來控制貼圖與color間的混合
● Opaque版本Shader "Custom/Unlit Opaque With Color" {
Properties {
_Color ("Color (RGB) Blending (A)", Color) = (1,0,0,0)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags {"RenderType"="Opaque" "IgnoreProjector"="True"}
Lighting Off
Cull back
ZWrite On
Pass {
SetTexture [_MainTex] {
ConstantColor [_Color]
combine constant lerp(constant) texture
}
}
}
FallBack "Unlit/Diffuse"
}
● Transparent Cutout版本
Shader "Custom/Unlit Transparent Cutout With Color" {
Properties {
_Color ("Color (RGB) Blending (A)", Color) = (1,0,0,0)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
Lighting Off
Cull back
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Alphatest Greater [_Cutoff]
SetTexture [_MainTex] {
ConstantColor [_Color]
combine constant lerp(constant) texture, texture
}
}
}
FallBack "Unlit/TransparentCutout"
}