Unity3D的着色器介绍(四)——Fixed Function shaders实例

之前介绍了很多理论性的东西,接下来几篇就直接贴一些常见的shader实例源码,都是比较简单的例子,有兴趣的朋友可以看看。
首先是介绍一下最简单的Fixed Function shaders:

1、显示纯颜色物体
Shader “Example/FixedSolidColor” {
Properties {
_Color (“MainColor (RGB)”, Color) = (1,1,1,1)
}
SubShader {
pass
{
Lighting on
Material
{
Diffuse[_Color]
}
}
}
FallBack “Diffuse”
}
2、各种颜色通道
Shader “Example/FixedFullColor” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,0.5)
_SpecColor (“Spec Color”, Color) = (1,1,1,1)
_Emission (“Emmisive Color”, Color) = (0,0,0,0)
_Shininess (“Shininess”, Range (0.01, 1)) = 0.7
}
SubShader {
Pass {
Lighting On
SeparateSpecular On
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
}
}
}
3、显示一张贴图
Shader “Example/FixedOnePic” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {
Pass
{
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
}
}
FallBack “Diffuse”
}
4、多张贴图叠加
Shader “Example/FixedMulPic” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
_MainTex2 (“Base2 (RGB)”, 2D) = “white” {}
_MainTex3 (“Base3 (RGB)”, 2D) = “white” {}
}
SubShader {
Pass
{
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
SetTexture [_MainTex2] {
Combine texture * previous DOUBLE
}
SetTexture [_MainTex3] {
Combine texture * previous DOUBLE
}
}
}
FallBack “Diffuse”
}
5、透明通道贴图+双面显示
Shader “Example/FixedAlphaCull” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
Cull off
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
}
}
FallBack “Diffuse”
}
6、假反射贴图特效
Shader “Example/FixedReflect” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {TexGen CubeReflect}
}
SubShader {
Pass
{
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
}
}
FallBack “Diffuse”
}
可以尝试把CubeReflect替换成ObjectLinear、EyeLinear、SphereMap、CubeNormal,各有不同的效果

猜你喜欢

转载自blog.csdn.net/liweizhao/article/details/81352274
今日推荐